3.d. Inertial sensors (accelerometer, magnetometer, and gyro)
The Zumo Shield includes on-board sensors that can be used as an inertial measurement unit (IMU) for applications like helping your Zumo detect collisions and determine its own orientation.
All versions of the Zumo Shield have a 3-axis accelerometer and 3-axis magnetometer accessible via I²C. Newer v1.2 and v1.3 boards also have a 3-axis gyroscope on the same I²C bus. The specific inertial sensor chips used on a shield depend on its version:
- The v1.3 version uses an LSM6DS33 accelerometer and gyro and an LIS3MDL magnetometer.
- The v1.2 version uses an LSM303D accelerometer and magnetometer and an L3GD20H gyro.
- The original version uses an LSM303DLHC accelerometer and magnetometer (it does not have a gyro).
- LSM303DLHC datasheet (1MB pdf)
We recommend carefully reading the datasheets listed above to understand how these sensors work and how to use them.
Using the sensors
Level shifters built into the shield allow the inertial sensors, which operate at 3.3 V, to be connected to the 5 V logic level pins of the Arduino. The sensors, level shifters, and I²C pull-up resistors are connected to the SCL and SDA pins on the Zumo Shield by default, but they can be disconnected by cutting traces to allow those pins to be used for other purposes. It is necessary to make some additional connections on the shield if you want to use the compass with an older Arduino without separate SCL and SDA pins; please see Section 3.c for more details about the compass connections.
ZumoIMU object in the Zumo Shield Arduino library provides functions that help configure and read the inertial sensors, and it abstracts details of the specific sensor ICs to make it easier to write programs that will work on all versions of the Zumo Shield. The library includes an example project that demonstrates how to use the magnetometer to help the Zumo coordinate its turns.
For advanced applications, you can instead use some of the dedicated libraries that we have written for these sensor chips; these include our LSM6 Arduino library, LIS3MDL Arduino library, LSM303 Arduino library, and L3G Arduino library. The v1.3 and v1.2 Zumo Shields use the same inertial sensor ICs as some of our IMU boards, like the MinIMU-9 v5, so Arduino software written for the MinIMU-9 (such as our AHRS example) can also be adapted to work on an Arduino-controlled Zumo robot with one of these shields.
Notes on the magnetometer
Please note that the magnetometer on the Zumo Shield is affected by currents in the motors and buzzer when they are operating, as well as metal in the batteries, and the readings are easily influenced by magnetic distortions in the environment around the Zumo (such as rebar in a concrete floor). As a result, it is very hard to accurately determine the Zumo’s absolute heading based on the magnetometer data. However, in our tests, we found that the magnetometer was still useful for detecting relative orientation changes; for example, once the magnetic readings are compensated for a particular environment, they can be used to help the Zumo turn left or right by a specific angle instead of just timing how long to run the motors to make such a turn.
In our tests, we found that the batteries, motors, and motor current affect the z axis of the magnetometer much more strongly than the x and y axes, so you probably will want to ignore the z readings. We were generally able to get decent results using only the x and y magnetometer readings to determine heading. Additionally, you might need to decrease the magnetometer sensitivity; if the magnetometer returns a value of -4096, that is a sign that the sensitivity range is set too narrow for your particular environment.