Classify hand movements (up, down, left, right, ideal) from a BBC Micro:bit by analysing the x, y and z plane acceleration readings.
Software Requirements
- Python 3.6.7
- Keras 2.2.4
- Tensorflow 1.13.1
- Microfs 1.3.1
- Mu-Editor 1.0.2
- Pyserial 3.4
- Numpy 1.16.2
- Pandas 0.24.1
- Matplotlib 2.2.2
- Scikit-learn 0.20.
Hardware Requirements
- 2 BBC Micro:bits
- 2 USB Type A to Micro B 5-pin cables
Using Mu-Editor
Mu-Editor provides easy way code and compile python source codes for BBC Micro:bit.
To see the installation instruction of it, click here.
Make sure that BBC Micro:bit mode is selected in the Mu-Editor.
Mu-Editor prefers tabs for intendation
- Connect BBC Micro:bit to computer via USB
- Open code in Mu-Editor
- Flash it on the micro:bit
Using online editor
There are several online editors to code and compile source codes for BBC Micro:bit.
This official website provides online python editor to compile the code.
This site also let's you simulate your code depending on the code complexitiy.
The USB cable should support data transfer
- Write python code in a online editor
- Download the hex file
- Connect BBC Micro:bit to computer via USB
- Paste the hex file to the micro:bit hard drive
Data collection in BBC Micro:bit
- Plug in the Micro:bit via USB to the computer
- Flash the source code src/Collect Data.py on the Micro:bit
- Restart the Micro:bit
- Hold the Micro:bit such that the buttons are on top and button B points away from you
- Select number of data to collect by pressing button A and B (max 14 data)
- Press both button A and B to start collecting data
- Press button A to start the countdown
- After the countdown, perform the movement (data sampled for 1.5 seconds at sample rate of 10 Hz)
- Press button B to check remaining number of data to collect
- Repeat steps 5-9 to collect further data
- Once all data is collected, a smiley face will be displayed
Data transfer from BBC Micro:bit to computer
- Plug in the Micro:bit via USB to the computer
- On the terminal, run the command
python "src/Read Microbit.py"
- Enter the name of the movement data collected in the BBC Micro:bit
- Now all the data are moved to the RAW_Data directory in following subdirectory {movement_name} {date} {time}
Processing the raw data
- On the terminal, run the command
python "src/Process Data.py" --data "RAW_Data" --width 13 --normalize true
to look for data in RAW_Data directory, use moving average window of 13 and normalize the values between 0-1 - The processed data from all collected raw data will be in Processed Data {date} {time}.csv file.
Train and test model
- Open the Train Gesture Reader.ipynb in Jupyter Notebook
- Select a processed file for training and testing the model
- Give threshold accuracy to save the trained model
- Run all the cells
Test trained model
Recommended to power both micro:bit via USB
- Flash “src/Data Sender.py” in one BBC Micro:bit and “src/Data Receiver.py” in another one.
- Connect the receiver micro:bit via USB to the computer
- Open the Test Gesture Reader.ipynb in Jupyter Notebook
- Load the trained model from the Models directory
- Configure the serial port settings of the receiver micro:bit
- In one cell, the program waits for data from receiver mircro:bit via USB
- Press button A in the sender micro:bit to start countdown
- Perform the hand movement
- The transmitter sends an end token at the end of transmission and the receiver displays a tick sign when it receives it.
Press button B on transmitter if the end token was lost and not received by the receiver - Run remaining cells in Jupyter Notebook to process the data, plot its graph and display the predicted movement.