Skip to content

Measuring motion using the IMU


Okay, but first:


An IMU stands for “Inertial Measurement Unit”, but basically, it’s a motion tracker!

The tinyCore’s IMU has six “Degrees of Freedom (6DOF), meaning we are measuring six things:

  • Acceleration in the X, Y, and Z axes

  • and Rotation (Gyroscopic Motion) in the X, Y, and Z axes

    This is also known as Pitch, Yaw, and Roll for all you aerospace nerds.

6DOF.png

The IMU on the tinyCore is specifically the LSM6DSOX, manufactured by STMicroelectronics. Within the datasheet, it describes it’s orientation:

image.png

And here is how that chip is oriented on the board.

image.png

Now that you know where it is, let’s walk through how to use it with the Arduino IDE.

At this point, you should have already installed the custom board library and tested flashing code with an example program (e.g. Blink).


The LSM6DSOX has a wonderful Arduino library made by Adafruit: Adafruit_LSM6DS

  1. You can either install it manually, or click on the Library Manager icon in Arduino IDE:

    image.png

  2. Then search “Adafruit_LSM6DS” and click INSTALL

    image.png


Our IMU example demonstrates how to initialize the IMU and view it’s data graphed out via the Serial Plotter in Arduino. To try it out, copy or flash the example program below:

Once you have the code copied into the Arduino IDE, and have connected your tinyCore via USB, it’s time to flash.

First, click the Board dropdown and “Select other board and port…”

image.png

Select the correct board and COM Port of the device. Click OK

image.png

Now click the Upload icon, and wait for the board to reboot.

image.png

image.png


The board should now be running the plotting program. Click the Serial Plotter icon in the top right corner of the IDE.

image.png

Ensure that you are set to the 115200 baud bitrate (located in the bottom right corner of the IDE)

You should now see several lines on the screen, color-coded and labeled with their variable type:

image.png

If your tinyCore is sitting up-right on a flat surface, you should see the third line (AccelZ) hovering around 9.81m/s. This is the acceleration due to gravity!

Now, if you start shaking the device, you will also see it’s movements, both accelerations and rotational movement in all six axes!

image.png

Try drawing circles in the air in different orientations, and see what shapes you can measure! Here’s my result:

image.png

Brain Teaser: Can you guess what frequency I was spinning the device at in the image above? _Click for the Answer!

If we are sampling every 25ms, and there are ~13 points per rotation (one sine wave), then we know that it is 25 × 13 = 325ms per cycle. Converting this to a frequency by inverting it, we get 1/0.325, or ~3Hz!


Make sure your tinyCore has the firmware flashed from above. Then click Connect.

Web Serial Not Supported. Please use Chrome, Edge, or Opera.

If you want to go further, you can learn how to improve our measurements via thresholding and Kalman filters in our IMU Deep Dive.

Nice job, now let’s move on to your first project!