#MPU6050 python3 python RPi2
Explore tagged Tumblr posts
Text
MPU6050 + python3 on RPi2: playing with the system. Age ~10
We built an interactive game around the MPU6050 's features in a fun way for young kids. Check the references at the end for initial setup of the RPi2.
Preparations
To set it up, you will need to organize the 2 files mentioned below as per the folder structure suggested, and add the following empty file: ./lib/__init__.py , which is instrumental in the ‘import’ in Python. you may want to set this up in /home/pi/discovery. Please let me know with questions.
Files found in 2 following posts:
http://diyrobotics.tumblr.com/post/113318665181/file-mpu-game-part1-py http://diyrobotics.tumblr.com/post/113318048456/file-lib-mpu6050-py
Once organized, you should be able to get via the terminal something comparable to this directories’ content (directory “.” and directory "lib”) :
> ls lib mpu_game_part1.py > ls lib __init__.py mpu6050.py
Checking progress, finding issues
at any time thereafter you can try to run the main program mpu_game_part1.py by:
> sudo python3 mpu_gamge_part1.py
Note that Python won’t like some of the broken code I have in there: any type of text looking like “< ... >” is not meant to work. You will have to wait until that is filled to hope for no errors.
Filling the gaps with info on the page
The student opens mpu_game_part1.py and edits it, then can save and run it as mentioned above. To edit, you can use for instance:
> sudo nano mpu_game_part1.py
move around with the keys or the mouse’s roulette.
edit
to save when in the nano editor: CTRL + O , then Enter
to save and exit : CTRL + X , then Y, then Enter
The idea so far was to put most of the information on the edited code , so that the student does not need to change location. We read the top part together, trying to make sense of the order of the functions, trying to introduce what functions are.
Based on that, the changes are numbered from 1. to 6.
At step 5. , it is now possible to see something coming out of the sensor. This is really exciting. I noticed that even little kids can pick up which number coming out is the biggest, though negative values are a bit confusing. Still it is a good idea to let them play with the board to see the changes.
Note that at step 5. I also setup the MPU6050 so that it is not on the breadboard anymore, but rather connected on a 1 feet flexible cable, so that even a young one ca grab the sensor and turn it around to see changes. It is good fun for them.
step 6. makes it simpler to visualize, and fun to play with.
Results
Example of what to expect at step 5 if mapped measurement of accelerometer only (raw x, raw y, raw z):
gravity: 17160 12612 -2096 gravity: 13120 11656 -3028 gravity: 15012 13416 -2684 gravity: 12156 9108 -2064 gravity: 16936 6964 -316 gravity: 10424 2340 5928 gravity: 12812 2852 9344 gravity: 14776 3216 12016 gravity: 7756 -6528 12580 gravity: 920 -13044 11468 gravity: -5312 -12944 12948 gravity: -8232 -12352 13908 gravity: -2756 -12188 12008
Example of what to expect at step 6 (P for positive, N for negative):
gravity: _ _ P gravity: _ _ P gravity: _ _ P gravity: P _ _ gravity: P P _ gravity: P _ _ gravity: P _ _ gravity: _ _ P gravity: P _ P gravity: _ N P gravity: _ _ P gravity: _ N P gravity: N _ P gravity: P _ P gravity: P _ _ gravity: P _ P
Note that the sensor is measuring acceleration, which is gravity only when not accelerating (= not shaking).
I hope this is clear, feel free to ask.
What’s next
There is another part planned and ready to go for this week or next weekend, time allowing.
References:
fixing i2c + smbus for RPi2
http://diyrobotics.tumblr.com/post/113141816706/raspberry-pi-2-for-the-kids
connectinf to MPU6050 via i2c on RPi2
http://diyrobotics.tumblr.com/post/113315981381/rpi2-mpu6050-i2c-3d-accelerometer-gyroscope
0 notes