/l3g-cm9

Arduino library for Pololu L3G4200D and L3GD20 boards

Primary LanguageC++OtherNOASSERTION

Robotis CM-900 (originally for Arduino) library for Pololu L3G4200D and L3GD20 boards

Version: 1.2.1
Release Date: 2012-10-31
www.pololu.com

Summary

This is a library for the Robotis CM-900 series that interfaces with L3G4200D and L3GD20 gyros on Pololu boards. It makes it simple to read the raw gyro data from these boards:

Getting Started

Software

I will probably not find all the places where the original code mentions the Arduino, but this fork is really adapted to the CM-900.

Download the archive from GitHub, decompress it, and move the “L3G” folder into the “libraries” subdirectory inside your Arduino sketchbook directory. You can view your sketchbook location by selecting File→Preferences in the Arduino environment; if there is not already a “libraries” folder in that location, you should create it yourself. After installing the library, restart the Arduino environment so it can find the L3G library and its example.

Hardware

Make the following connections with wires between the CM-900 and the L3G4200D/L3GD20 board:

CM-900                      L3G4200D/L3GD20 board
                  3.3V  ->  VIN
                   GND  ->  GND
        Digital Pin 15  ->  SCL
        Digital Pin 14  ->  SDA

Other pin assignments will probably work as well. You will just have to adapt the Wire.begin() statements accordingly.

Example Programs

Open an example code sketch by selecting File→Examples→L3G→example_name

Serial

This program continuously reads the gyro, communicating the readings over the serial interface. You can display the readings with the Arduino Serial Monitor.

Example output:

G X: 188 Y: -10 Z: -47
G X: 138 Y: -40 Z: -26
G X: 110 Y: -55 Z: 4

Library Reference

vector g
The last values read from the gyro.
bool init(byte device, byte sa0)
Initializes the library with the device being used (L3G4200D or L3GD20) and the state of the SA0 (slave address least significant bit) pin. Constants for these arguments are defined in L3G.h. Both of these arguments are optional; if they are not specified, the library will try to automatically detect the device and slave address, and it will return a boolean indicating whether the autodetection was succesful.
void enableDefault(void)
Turns on the gyro in the default configuration.
void writeReg(byte reg, byte value)
Writes a gyro register with the given value. Register address constants are defined in L3G.h.
byte readReg(byte reg)
Reads a gyro register and returns the value read.
void read(void)
Takes a reading from the gyro and stores the values in the vector g.

Differences from the L3G4200D library

This library is very similar to our earlier L3G4200D library, which is not compatible with the L3GD20. Besides the name change, the main difference in this library is that you need to call the init() function before using any of the other library functions, typically from within the Arduino setup() function. While the older library only works with the Pololu boards’ default gyro slave address of 1101001b, this library allows you to specify the slave address with the init() function.

Version History

  • 1.2.1 (2012-10-31): Cast sensor readings to 16-bit ints for better portability.
  • 1.2.0 (2012-07-06): Renamed library to L3G and added support for L3GD20.
  • 1.1.0 (2011-12-12): Arduino 1.0 compatibility.
  • 1.0.0 (2011-09-14): Original release of L3G4200D library.