The Zumo Shield includes an onboard LSM303DLHC compass module that combines a 3-axis accelerometer and 3-axis magnetometer into a single package with an I²C interface. This sensor can be used in advanced applications to help your Zumo detect collisions and determine its own orientation. We recommend carefully reading the LSM303DLHC datasheet (629k pdf) to understand how it works and how to use it.
Level shifters built into the shield allow the LSM303DLHC, which operates at 3.3 V, to be connected to the 5 V logic level pins of the Arduino. The LSM303, 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.
Please note that the magnetometer in the LSM303 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.
We have written a basic LSM303 Arduino library that makes it easier to interface the LSM303DLHC with an Arduino. The library provides functions to read the raw accelerometer and magnetometer data. We plan to provide some higher-level example code in the near future to demonstrate how a Zumo robot might be able to make use of this data.
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.