Skip to content

IMU

RoboBoard IMU sensor

Control interface for integrated RoboBoard I2C accelerometer and gyroscope sensor.

#include <Wire.h>
void setup() {
  Wire.begin(); // Start I2C interface (for communication with sensor)
  auto result = IMU.read();
}

IMU sensor (based on MEMS technology) measures movement in 3 acceleration axis and 3 rotation axis. Allows to determine board movement, position, rotation angles.
Sensor is sharing I2C Wire (SDA, SCL pins) with Qwiic port, so it acts as additional module on the bus. Can be also used with third-party library.

Tip

In order to use sensor, you must enable I2C by calling Wire.begin() inside setup() function. Otherwise IMU functionality will not work.

Only raw sensor measurements available. Advanced orientation algorithms not yet implemented.

Code snippets

#include <Wire.h> // Required for "Wire.begin"
void setup() {
  // Start I2C at 400kHz
  // Calling "Wire.begin()" will start in 100kHz mode
  // SDA, SCL - pins connected to IMU and Qwiic port
  Wire.begin(SDA, SCL, 400000); // Required for "IMU"
}
void loop() {
  auto result = IMU.read(); // Store measurements in "result"
  Serial.println(result.getX_G()); // Read unit from "result"
  delay(100); // Wait 100ms for next read
}

Functions

Read sensor

Called IMU.read() function will sample measurements from IMU sensor and return in a single IMUData object. It contains functions to read data in different measurement units without require for additional conversions.

IMU.begin()

Initialize IMU sensor. Function IMU.read() calls this internally, so it's only useful if need to prepare sensor before first read operation.

IMUData IMU.read()

Read measurements from IMU sensor.
Returns structure with accelerometer, gyroscope and temperature data.
Note: Wire.begin() must be called in order for IMU to work!
Returns:
IMUData - object with sensor data. Read Access data for more info.

Access data

Available units:

  • Gravitational force (G)
  • Acceleration in meters per squared seconds (m/s2)
  • Rotation speed in degrees per second (dps)
  • Rotation speed in radians per second (rad/s)
  • Rotation speed in rounds per minute (RPM).
  • Orientation in angle degrees (°)

Accelerometer:

unit result.getX_G()

unit result.getY_G()

unit result.getZ_G()

Get gravitational force (G) measurement of X, Y, Z axis.
Returns:
unit - (float) gravitational force [-16.0, 16.0]G.

unit result.getX_mss()

unit result.getY_mss()

unit result.getZ_mss()

Get acceleration in meters per second squared of X, Y, Z axis.
Returns:
unit - (float) [-157.0, 157.0]m/s2.

Gyroscope:

unit result.getX_dps()

unit result.getY_dps()

unit result.getZ_dps()

Get rotation in degrees per second of X, Y, Z axis.
Returns:
unit - (float) [-2000.0, 2000.0]dps.

unit result.getX_rads()

unit result.getY_rads()

unit result.getZ_rads()

Get rotation in radians per second of X, Y, Z axis.
Returns:
unit - (float) [-35.0, 35.0]rad/s.

unit result.getX_rpm()

unit result.getY_rpm()

unit result.getZ_rpm()

Get rotation in rounds per minute of X, Y, Z axis.
Returns:
unit - (float) [-333.0, 333.0]RPM.

Temperature:

Internal sensor / board temperature (not a room temperature!).

unit result.getTempC()

Get IMU sensor temperature in Celsius.
Returns:
unit - (float) temperature 25.0 °C.

unit result.getTempF()

Get IMU sensor temperature in Fahrenheit.
Returns:
unit - (float) temperature 77.0 °F.

Orientation:

Accelerometer based orientation measurements (susceptible to shaking).

unit result.getOrientX()

unit result.getOrientY()

Board orientation in space of X and Y axis.
Returns:
unit - (float) orientation [-180.0:180.0] degrees.

unit result.getRoll()

Get roll estimation.
Returns:
unit - (float) roll [-180.0:180.0] degrees.

unit result.getPitch()

Get pitch estimation.
Returns:
unit - (float) pitch [-90.0:90.0] degrees.

Configure sensor

IMU.setAccelRange(range)

Configure accelerometer measurement range (in gravitational force).
Can be lowered if higher precision is required.
Parameter:
range - max (G) range [2, 4, 8, 16]. Default: 16.

IMU.setGyroRange(range)

Configure gyroscope measurement range (in degrees per second).
Can be lowered if higher precision is required.
Parameter:
range - max (dps) range [250, 500, 1000, 2000]. Default 2000.

range IMU.getAccelRange()

Get configured accelerometer measurement range (in gravitational force).
Will return exact value configured in sensor.
Returns:
range - max (G) range.

range IMU.getGyroRange()

Get configured gyroscope measurement range (in degrees per second).
Will return exact value configured in sensor.
Returns:
range - max (dps) range.

string IMU.getName()

Get name of installed IMU sensor. Different variants exist in RoboBoard.
Returns:
string - name of IMU sensor.

number IMU.getI2CAddr()

Get I2C address of installed IMU sensor. Different variants exist in RoboBoard.
Returns:
number - I2C address of IMU sensor.

state IMU.isI2CAddr(address)

Check if specified address equal to installed IMU sensor.
Parameter: address - I2C address.
Returns: state - true if address match.

Sensor variants

Each RoboBoard contains different IMU sensor. See table below for part number and I2C address. These parameters can be also acquired dynamically using IMU.getName() and IMU.getI2CAddr() functions.

RoboBoard X3 v3.x RoboBoard X4 v1.0 RoboBoard X4 v1.1
QMI8658 LSM6DS3 ICM-20689
0x6B 0x6A 0x68