I made an Arduino game around the MPU-6050 sensor (6DOF = gyro+accelerometer) and an OLED display:
- tilt the sensor to move the ball around
- do not touch the borders
- try to catch as many squares as possible within 1 minute
I’m using the GY-521 module with the MPU-6050 sensor, that talks I2C. Getting useful data out of this sensor is not straightforward, but i found a library that makes this very simple; actually it’s not implemented as a library but rather an example sketch that works without any setup. As far as i understand, the challenge is to keep track of pitch and roll based on the gyro, which only outputs relative changes, and needs to be corrected by the acceleromter that has gravity as reference.
My sketch below includes 2 functions: the game, if D7 is connected to GND; and a basic gyro test program that shows the pitch and roll values, shows them in an XY grid, and changes the buzzer pitch according to distance from origin.
For the OLED i use the excellent U8G library which allows many fonts and fast graphics.
I include a basic wiring diagram here.
And here is my sketch, you will need to include 2 files in your sketch folder I2C and Kalman.h, they come with the MPU-6050 example mentioned above:
Somehow WordPress goes ‘oops page not found’ when i try to save this post with my sketch, so i have put it on pastebin, or full zip file gyro-game-v3