Introduction: Mario Kart With HM-10
This project was for 'Creative Electronics', a Beng Electronics Engineering 4th year module at the University of Málaga, School of Telecommunications (www.etsit.uma.es).
In this project we are going to show how to BLE based-arduino system works along with raspberry. For this we use HM-10 BLE. These will be the slaves of our multi-thread system. The master will be a Raspberry pi that will have RetroPie installed. We will be able to send data to raspberry and generate keyboard events, taking advantage of Retropie going on Raspbian.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: What Do You Need?
2x Arduino nano
1x Raspberrypi 3B
1x SD Card 32 GB
2x HM-10 BT module
2x 9v batteries
2x Electrical Bakelite Circuit Board
Step 2: Building the Hardware
Connect both of the gy-521 module and the BT modules to the Arduino nano as the next picture shows.
It is important to put both gy-521 modules as the pictures shows. Pay attention to the RIGHT hand..
Step 3: The Code for Arduino
The code uses Kalman filter in order to minimize the noise and improve the accuracy of the gyroscope's sample.If you want to read more about Kalman filter: https://en.wikipedia.org/wiki/Kalman_filter
There are two different codes,one is for the hand control, the other one is for the foot control. The most part of the code (the Kalman filter and obtaining all of the GY-521 variables) has been taken from this github repository: "KalmanFilter" (thanks a lot for it!)The genuine part is in the void loop() Both codes is based on a state machine.This states machines controlls the actual state of the system.Every loop the system gets the sensor samples and checks the result, if there is a valuable change between the initial position(when the system switch on or reset) and the current one the "Hand" code determines if are you going to the left or to the right.However, the "Foot" code determine if your are accelerating or stopping. When the "Hand" code is on "Right state" or "Left state" checks if the sample shows that you're back to the initial position. Any change makes the program sends a character through Serial that is automatically resended by bluetooth to the raspberrypi.
To program the arduino that goes in the hand you need this code: Hand
To program the arduino that goes in the foot you need this code:Foot
State transition // Code sended
Initial to Right // "D"
Initial to Left // "I"
Left to Initial // "i"
Right to Initial // "d"
Accelerating // "A"
Stopping // "F"
Step 4: Setting Up RetroPie
We have left an image with the Retropie already configured, to do this download this link: RetroPie
Burn the image on the 32GB SD with a program like Win32DiskImager.
Start RetroPie press F4 to launch the terminal and type in:
In this folder we find a file in Python that models the communication between the different BLE.
The first one will be to modify this file to put the MACs of your BLE (HM-10) you can consult them type in:
Now, to modify the MACs we type: nano prueba.py
We modified the bt_addr array with our MACs (do not forget to put them in lowercase).
I have left a file called keyboard.c which explains how to generate keyboard events in linux. You can modify this file if you want, to add functionality. The important thing is that the executable you generate is called "teclado"
Step 5: Play and Enjoy
We run in the background this application for it type:
Python prueba.py &
Now we go out and start the simulation, type:
You can already use your own body as a keyboard and select the game.