This tutorial will teach you how to retrieve and display sensor readings from the onboard inertial measurement unit (IMU) of the new Arduino Uno WiFi Rev2 development board. A basic understanding of electronics and programming is expected along with some familiarity with the Arduino platform. If you are new to the Arduino platform or would just like to refresh your knowledge, please see our Blink: Making An LED Blink On An Arduino Uno tutorial before proceeding with this one.
What Is Needed
- Linux, macOS, Or Windows Based Computer With A USB Port
- Arduino IDE
- Arduino Uno WiFi Rev2 (available on Arduino and SparkFun) With Compatible USB Cable
The recently released Arduino Uno WiFi Rev2 development board has an onboard IMU with a 3-axis accelerometer, a 3-axis gyroscope, and an embedded temperature sensor. This particular IMU is the LSM6DS3 device provided by ST Microelectronics (datasheet) accessed over the SPI serial bus interface.
My development system consists of the Arduino Uno WiFi Rev2 development board connected to a macOS based computer running the Mojave operating system with the desktop Arduino IDE. If you are using a different computer setup, the vast majority of this tutorial should still apply, however, some minor changes may be necessary.
Installing The IMU Library
The getting started guide for the Arduino Uno WiFi Rev2 states that the onboard IMU is “already supported by many libraries; you can choose between the available ones in our library manager using LSM6DS keyword”. I found this was not necessarily the case for me. I researched both the available libraries within the Library Manager along with general internet searches for an LSM6DS3 based library that supports the SPI interface and only found two. Both were available within the Library Manager.
The Accelerometer And Gyroscope LSM6DS3 by Seeed Studio library is a derivative of the SparkFun LSM6DS3 Breakout by SparkFun Electronics library with only the default I2C address being different. The two libraries also have different accompanying example sketches with the SparkFun library offering a few more. I decided to use the SparkFun library as it is the base library.
To install the SparkFun library, open the Library Manager (Tools > Manage Libraries…) and enter LSM6DS3 in the search field. Find and install the SparkFun LSM6DS3 Breakout by SparkFun Electronics library from the listing.
Writing The Software
Once the library is installed, open the MinimalistExample library example sketch (File > Examples > SparkFun LSM6DS3 Breakout > MinimalistExample). This sketch is currently configured to work with the IMU over an I2C serial bus interface so we need to change that to use the SPI interface instead. Change line 41 from
LSM6DS3 myIMU; //Default constructor is I2C, addr 0x6B
LSM6DS3 myIMU(SPI_MODE, SPIIMU_SS); // SPI Chip Select
That’s all it takes. Now let’s watch it in action. Open the Serial Monitor window (Tools > Serial Monitor) so that we can see the program’s output. Upload (Sketch > Upload) the sketch and watch the readings being presented in the Serial Monitor. My readings are shown below.
Processor came out of reset.
X = 0.0200
Y = 0.0156
Z = 1.0189
X = 0.0000
Y = -4.7600
Z = -3.8500
Degrees C = 23.8125
Degrees F = 74.8625
In this tutorial, we learned how to access the onboard IMU of the new Arduino Uno WiFi Rev2 development board. We installed the relevant library and were able to see acceleration, rotation, and temperature sensor readings being displayed upon loading and modifying an example sketch.
Thank you for joining me in this journey and I hope you enjoyed the experience. Please feel free to share your thoughts in the comments section below.