9-Axis IMU LESSON 12: Passing Data From Arduino to Python

In this lesson we show how to pass data from Arduino to Python using a Com Port. This is important for our 9-Axis IMU project as we want to take advantage of the processing power and 3D graphics capabilities of Python. Our goal is to get the date from Arduino to Python, and then create a dynamic 3D visualization of our system. The first step in this goal is to pass the data from arduino to Python.

In order to do this, a first step is to install the pyserial library. If you followed our python installation tutorial in lesson 11, then it is easy to install pyserial by just opening a windows command prompt, and then typing:

pip install pyserial

If this does not work, likely you did not install python according to the instruction in lesson 11.

In order to show a simple demonstration of passing data, we can use the following code on the arduino side, which just generates x, y, and z numbers and passes them to Python.

We can grab these numbers from the Com port on the Python side with the following code. Note that you should use the com port your arduino is on, which likely will not be the same as mine (which was ‘com5’).

The above example is just a simple method for passing different channels from Arduino to Python.

 

For our IMU project, we want to use the code we left off with Lesson 10. However, note we can scale back on the number of data channels, because we just want the calibration data and then the final roll, pitch and yaw numbers. This is the arduino code that will pass those parameters.

Then, on the Python side we can grab and parse the data with this code.

In the next lesson we will install Vpython and begin building our code to create dynamic 3D visualizations of our system.

Arduino Tutorial 34: Simplest Way to Use a Pushbutton Switch

In this lesson we show you a quick hack that will allow you to incorporate a pushbutton switch into an Arduino project without having to use an external pullup resistor, and still get very stable operation. The trick is to create a digital input pin, which in our example is pin 2. We then digitalWrite that INPUT pin HIGH. What that does is put an internal pullup resistor on pin 2, and then connects it to 5 volts. In effect, we are using a clever command to use the Arduino’s internal pullup resistors. The code below is what we used in the video. Enjoy!

 

9-Axis IMU LESSON 11: Install Python

This is a quick lesson where we show you how to install Python on a Windows 10 machine. We have gone about as far as we can go on our 9-axis IMU project using only the arduino. What we want to do now is to pass the data we are taking from arduino to Python, and then use python to do animations and 3D renderings. So, to move forward, we will need to install Python, which is explained in the video.

Arduino Tutorial 33: Understanding How to Control Servos with a Joystick

In this lesson we show you how to precisely control the position of two servos using a joystick. We derive the math equations which will allow you to get smooth and precise control of the servo. We also add a buzzer to the project to create an audible alarm when the button the joystick is pressed.

If you want to follow along at home, you can order the Arduino Kit we are using HERE.

Typically, the servos in electronics kits are not the best ones, but are suitable to learn with. If you want a more stable and better quality servo, this is the one I user in more of my projects: HiTEC

Below is the code we developed in this project.

 

9-Axis IMU LESSON 10: Making a Tilt Compensated Compass with Arduino

In this lesson we show you how to build a demo tilt compensated compass using the BNO055 9-axis sensor.  We go through some trigonometry to help you understand conceptually how the device works.

To play along at home, you will need an Arduino Nano, and an Adafruit BNO055 Inertial Measurement Sensor.

The code below is provided for your convenience. It is intended only for bench top demos, and should not be used in real applications. Just for fun, not for drones, or other actual control applications.