Using accelerometer sensor and Arduino to control a game.
Have a look at our video explaining what we did and filtering results: https://youtu.be/T_xc3NxIb94
- Python
Check the following webpage for instructions on how to install latest version of python: https://www.python.org/downloads/
- pyFirmata2
Check the following webpage for instructions on how to install pyFirmata2: https://pypi.org/project/pyFirmata2/
- pynput (Keyboard Controller Library)
On a terminal, install pynput with pip or pip3.
pip install pynput
or
pip3 install pynput
Reference resource: https://pypi.org/project/pynput/
- Arduino board and accelerometer wired as in the circuit_diagram image above
You might need to change PORT number in the realtime_iir_main.py script to the corresponding Arduino port on your PC.
- Change Directory to a clone of this project in your local file system.
cd IIR_application
- Run the realtime_iir_main.py on the terminal.
python realtime_iir_main.py
or
python3 realtime_iir_main.py
There should be 2 plots showing up. One is the unfiltered data. The other one is the filtered data. Keep this terminal running when you play.
- Use terminal to access the game directory(webGL format file).
cd IIR_application/Dinosaur_trial1
- Use terminal to run http server at port 8000. Keep the terminal open (Exit shortcut: ctrl+c).
python -m http.server --cgi 8000
or
python3 -m http.server --cgi 8000
- On a web browser, run localhost port 8000.
http://localhost:8000/
or
http://0.0.0.0:8000/
For this demo game, shake accelerometer in z-axis to jump. Try to avoid the spikes.
You can use this controller on any other custom/pre-existing games. However, please make sure the key pressed in the controller(realtime_iir_main.py) is correspond to the game you want to play.