I have purchased a rather cheap gyro L3G4200D sensor from eBay that can detect 3 axis rotation and deliver it through an I2C or SPI interface. I tried to use it to detect horizontal and vertical rotation in real-time. This turned out quite difficult as I could not visualize what the Gyro was outputting. I needed a visualization. I ended up using Blender to visualize the gyro that is connected to an Arduino Uno. With this combination, I got a real-time report that turned out pretty good and proved the sensor to be quite accurate at what it does.
Step 1: The Hardware
Step 2: The Software
For the visualization, I used blender and python.
This is where the problems start. We need to set up Blender and python in a right way. We need Blender to share the same python version as the system uses. The best way to do is to download the newest Blender, Install it. Open the Blenders internal python. On my computer it is located at: C:\Program Files\Blender Foundation\Blender\2.78\python\bin\python.exe It reveals the Python version Blender is using.
Head over to the Python page and download the EXACT same python bin. https://www.python.org/downloads/Install python but check in the [Add Python to PATH] in the beginning of the install wizard.
Rename the folder where python is located that blender uses so it will not be recognized anymore by blender.rename
C:\Program Files\Blender Foundation\Blender\2.78\python\
C:\Program Files\Blender Foundation\Blender\2.78\python_old\
If we start blender now it should be able to start without any problem. If the program crashes that means that the python version is not the exact same as blender used before or PATH have not been updated.
The only things missing now are the libraries we will be using with python. Fire up python and we will download the serial library this command that can be executed via the command line:
pip install serial
This library is needed because it enables python to receive serial connections from the Arduino.
Step 3: The Scripts
On the Arduino, we will have to upload this script:
This script I found and modified from this thread on the Arduino forum.
The job of this script is to get the data from the L3G4200D sensor and send it over a set COM port with 115200 baud rate.
<p>X: 38.72 Y: 8.61 Z: -17.66</p><p>X: 39.30 Y: 8.37 Z: -18.17</p><p>X: 40.07 Y: 8.24 Z: -18.81</p><p>X: 40.89 Y: 8.30 Z: -19.46</p><p>X: 41.69 Y: 8.41 Z: -20.05</p><p>X: 42.42 Y: 8.41 Z: -20.44</p>
In blender, we will need to change the layout to Scripting.
On the left side, we need to enter our python script that will be receiving the data and processing it from the sensor and change the COM port to the port where our Arduino is located.
Step 4: Run the Script
After hitting Run Script everything should be working and the cube should be turning just as the gyro sensor is turned.
Step 5: Troubleshooting
If you run into any problem with the execution of the script you will need to open the System console. Click Window -> Toggle System Console to reveal the console where the error is shown.
The most usual error is permission denied to open the port. To fix this quickly disconnect the Arduino and reconnect it.
If you need more help head over to my website for better support.