Jupyter Notebooks are a powerful cross-platform method for analyzing data using Python

You can definitely use Jupyter to plot, analyze and calibrate your sensor data. This method is the most powerful because you can do plotting and calculations. However, we assume you already have Jupyter installed (either desktop or thru Anaconda) and have some familiarity with running 'notebook' style Python!

This example runs on chips with at least 64 KB of flash, and will not fit on an UNO (Atmega328) or Leonardo (Atmega32u4) - try the simple calibration instead!

Step 1 - Download Calibration Notebook

The gyro/magnetometer notebook lives in the SensorLab Arduino library, in the notebooks folder.

Look for this section in the website:

You must open this notebook within Jupyter - you cannot run it direct from github or from the command line as a text file!

Once open, your browser will look like this:

Step 2 - Upload the SensorLab imucal Example

Next we have to tell the microcontroller board to send the magnetometer (and, if there is one, accelerometer and gyroscope) data out over serial in the right format.

Open up the Adafruit_SensorLab->calibration->imucal

Select your desired board & port from the Tools menu then click Upload

Open up the serial console, you'll see SensorLab initialization and detection of whatever magnetometer is available. In this case is a LSM9DS1, but any gyroscope can be calibrated!

You'll then see a stream of data that looks like:
Raw:-58,-815,8362,76,-121,-95,-375,-159,-24
Uni:-0.07,-0.98,10.00,0.0832,-0.1327,-0.1046,-37.50,-15.93,-2.50

The first three numbers are accelerometer data - if you don't have an accelerometer, they will be 0

The middle three numbers are gyroscope data, they should definitely not be zeros!

The last three numbers are magnetometer - if you don't have an magnetometer, they will be 0

Configure the notebook

Close the serial port, and go back to Jupyter. In the first cell, find where we define the PORT and change the port to match your serial/COM port. For windows it'll be something like COM4 for Mac/Linux it'll be like /dev/cu.USBSERIAL or something

Run the first cell so the serial port is set

Then run the second cell, you should see output like this - the serial port is opened and IMU raw data is output as numbers

If you get errors or no numbers, hard-reset the board (click the reset button once) then try re-running the cell again.

Skip past the magnetometer calibration section, to the Gyro calibration cells

Skip the magnetometer cells, and find the Gyroscope offset calibration cell

Place the board down on a flat stable surface, we like to put a book on top of it to keep it flat and steady. You don't want any shifts or movement while you run the calibrator!

You'll see a 3 second countdown, then the serial port is opened and data collected

Once it's done you'll see a plotting of the data output. You should see something like this with red, green and blue lines. There may be some offset as expected, but the lines should wobble around a point without big spikes or increases/decreases.

Above the graph you'll see analysis of the average value (zero-g offset) like so:

In this case, the zero-g calibration is X = 0.044 Y = -0.0148, and Z = -0.0111

The units are in SI units radians / second not degree/s (dps)!

You'll also see the results of removing the offset, this should be 3 noisy but nearly-zero-centered lines. The higher the quality of the gyro, the lower the jitter in the measurements, and the lower the offset.

This guide was first published on Jan 26, 2020. It was last updated on Jan 26, 2020.

This page (Gyro Calibration with Jupyter) was last updated on Nov 06, 2020.