Tag Archives: Digital Compass

Arduino IMU Project with Complete Avionics Display for Roll, Pitch and Yaw on a SSD1306 OLED

In this video lesson we wrap up our project to create an Arduino IMU using the GY-87 IMU module, with an MPU6050 chip and a QMC5883L Magnetometer. In this lesson we complete the avionics display, creating an accurate graphical output for Roll, Pitch, and Yaw. This is the schematic we are using for this project:

OLED IMU
This schematic shows how to connect the SSD1306 OLED to our IMU Project.

This is the code we develop in the video. Remember, you have to calibrate your sensors, and put your calibration numbers into the code below. I showed you how to do the calibration in THIS LESSON.

 

Removing Digital Compass Glitches and Wrap Around Issues

In this video lesson we continue to improve our Arduino IMU project incorporating the GY-87 9-axis sensor module. In last weeks lesson, we had added tilt compensation to the project, so the IMU reports accurate Heading values, even if the sensor is tilted. This creates a tilt compensated digital compass. We are now getting ready to begin building graphical displays on the SSD1306 OLED display. In order to do that, we must clean up a few things on the project. First, our compass presently reports headings between +/- 180 degrees. For standard compasses, North is a heading of 0 degrees, and rotating clockwise reports increasing number, up to 359. Then the compass returns to North, as it has been rotated all the way around. The other issue we clean up in todays lesson is associated with the so called wrap around glitch. That is, if we move only two degrees, from 1 degree to 359 degrees, it is a very small physical change, but the complimentary filter sees it as a large change, and it filters that change. The practical implication of this is that the needle on the compass will take the long way around the dial when making this transition, and it creates a very awkward glitch in the display. We will show you how to solve the wrap around glitch.

This is the schematic we have been using for  this project:

MPU6050
Schematic for connecting the GY-87 module to the Arduino

This is the code we developed in today’s lesson. Understand, you must calibrate your sensor module, as we taught in THIS LESSON. Then you need to put those calibration values into the code below for it  to work accurately for your sensor module.

 

Improving Digital Compass Accuracy With a Low Pass Filter

In this video lesson we add a low pass filter to our calibration and digital compass program. This allows more precise calibration, and removes the jitter from the digital compass display. We continue to use the QMC5883L 3-Axis Magnetometer, which is on our GY-87 IMU module. We are using the following schematic for our project:

MPU6050
Schematic for connecting the GY-87 module to the Arduino

We collect the data using the GY-87 connected to an Arduino. Below is the simple program which takes the magnetometer data and sends it to the serial port.

The code for the Python side to do the calibration and display a Digital Compass is:

 

Calibrating a 3-Axis Magnetometer

In this video lesson we show you how to calibrate the QMC5883L 3-axis magnetometer. The lesson is geared toward this specific magnetometer, but the procedure will be the same for any 3-axis magnetometer. We then use the calibrated reading to measure and calculate the magnetic heading of the device. With this, we have created a calibrated digital compass. In this lesson we are using the GY-87 module, which contains the QMC5883L magnetometer. We are connecting the module to the arduino using the following schematic:

MPU6050
Schematic for connecting the GY-87 module to the Arduino

In the video we develop two programs. The first program determines your sensor’s calibration constants. Then the second program uses those calibration constants to calculate heading, or yaw. The second program uses the offsets and scale parameters for MY PARTICULAR SENSOR. These values were determined using the first program. You must determine these values for your sensor, and then edit the second program to use your particular calibration parameters.

Program to determine your calibration parameters:

Once you get your calibration parameters, then put them into this program. This program will then calculate your compass heading: