Want to see exactly what your 3-axis accelerometer or 9-axis IMU sensor data means? This tutorial will show you how to display a rotatable 3D model on your computer using Python and either USB or Wi-Fi connection. Then all you need is an accelerometer or 9-axis sensor.
- Arduino IDE
- Arduino WiFi101 library
- Python 3.7.9
- pyserial Python library
- vtk Python library
- IMU Output Arduino Sketch & IMU Display Python Script
Plug your TinyZero with Accelerometer or RobotZero (that includes a 9-Axis Sensor) into a computer using a Micro USB cable. If you plan on using the WiFi TinyShield, you can stack that onto your processor board of choice using the tan 32-pin connector.
If this is your first time uploading code to your processor board, please see the tutorial for your respective board for learning how to download and configure the Arduino IDE: TinyZero tutorial or RobotZero tutorial
If you are using the Wi-Fi TinyShield to communicate to your computer, please see the software setup portion of the WiFi Tinyshield tutorial to install the WiFi101 library.
Download and install Python on your computer. The latest version of Python that includes the required libraries is 3.7.9. For 64-bit Windows, download and install Python from this link, but make sure to 'check' the box on the first installation page that says "Add Python 3.7 to PATH". See the troubleshooting section at the bottom of this tutorial if you have another version of Python already installed.
Next, two external Python libraries need to be installed. On Windows, navigate to the search bar in the Windows application bar, as seen below, and type 'cmd' then left-click the 'Command Prompt' application.
Once the black command window opens, type the command 'pip install pyserial' without quotes and hit Enter/Return. Also execute 'pip install vtk'.
Now that the Arduino IDE, Python 3.7.9, and the Python libraries are installed, download the visualizer Arduino Sketch and Python script from above in the Software section.
In the 'TinyCircuitsIMUOutput' directory, open the TinyCircuitsIMUOutput.ino file with the Arduino IDE. Edit lines 22 and 23 to match the computer connection and processor board you are using. Line 22 configures the connection you are using to your computer and the following options are available.
- line 22: int COMMUNICATION = USB;
- line 22: int COMMUNICATION = WIFI;
Edit line 23 to match the processor board you are using. The following options are available.
- line 23: int BOARD = TINYZERO;
- line 23: int BOARD = ROBOTZERO;
Below is an example for a USB connection to the RobotZero.
When using Wi-Fi, edit lines 26, 27, and 28 to match your network setup. Line 26 is the name of the Wi-Fi network your computer is connected to and can be found by clicking on the Wi-Fi symbol in your Windows application bar. Line 27 is the password you use to connect to the network you found for line 26. Line 28 is the local IP your computer has been assigned and can be found by left-clicking the Wi-Fi symbol, right-clicking your Wi-Fi network name, left-clicking properties, and looking for the IPv4 address. Below is an example of lines 26 ~ 38 after configuration for Wi-Fi.
Next, similar to what you did to setup the Arduino sketch, open the TinyCircuitsIMUDisplay.py file in WordPad or any text editor. Edit line 32 in the Python script to match line 29 in the Arduino sketch you set. The connection options are USB or WIFI, like in the Arduino sketch. You do not need to set the type of board you are using in the Python script.
Upload the Arduino sketch to your processor board. To start the python script, go to the 'src' directory containing the TinyCircuitsIMUDisplay.py file and enter 'cmd' into the top file path bar, as seen below, press Enter/Return.
Once the black command window pops up, enter 'python TinyCircuitsIMUDisplay.py' to start running the script. If the processor board is plugged in and configured for a USB connection, the 3D animation will pop up right away. If using Wi-Fi and the window does not pop up, turn your processor board off and on, or re-upload the sketch.
- I have a different version of Python already installed
- Follow the download instructions for Python 3.7.9 above. Now, when using pip to install the pyserial library do 'C:\Users\current_user\AppData\Local\Programs\Python\Python37\Scripts\pip.exe install pyserial' where 'current_user' should be replaced by your Windows username. Install the vtk library with 'C:\Users\current_user\AppData\Local\Programs\Python\Python37\Scripts\pip.exe install vtk'. To use the python command for version 3.7.9, use 'C:\Users\current_user\AppData\Local\Programs\Python\Python37\python.exe TinyCircuitsIMUDisplay.py'
- Wi-Fi connection between my computer and processor board is not connecting
- Ensure the Wi-Fi TinyShield is seated correctly in the 32-pin connector on your processor board
- Make sure the SSID Wi-Fi name in the Arduino sketch is typed correctly since the name is case-sensitive
- Make sure the correct Wi-Fi password is entered in the Arduino sketch
- Start the Python script first and then turn the processor board off and back on or start the script and re-upload the Arduino sketch
- Ensure the appropriate lines in the Arduino sketch and Python script are set to WIFI instead of USB
- The model is not rotating
- Ensure the board line in the Arduino sketch matches the board you are using
- Look at the TinyZero product page and check that you have the board with the 3-axis accelerometer
- Is there support for my 9-axis Wireling?
- Not yet, but support is coming soon!
As always, if you have any questions or feedback, feel free to email us at email@example.com.
Thanks for making with us!