L3G4200D Arduino Library

Views: 11643 Difficulty: 2 Status: Development

A library to interface Arduino code with the 3 Axis L3G4200D gyroscope.

Orientation is important! You can detect an objects orientation in space with gyroscopes. We like to use the Surface Mount L3G4200D gyro from ST Microelectronics. We have written a little Arduino library to simplify the process of getting readings from the gyro. We use this library in our HID 3D controller to make a gyroscope mouse.

Here is some code to get started with the gyro. Make sure to include the gyro library and the standard Arduino wire library (the communication protocol used by the gyro). Then in the setup function start up the Wire communication and initialiaze the gyro with a scale. You can use 2000, 500, or 250. This number determines the range of the values from the gyro.
In the main loop we get X, Y, and Z orientations with the get functions, for example:
  x = gyro.getX();
Then we spit these values out on the serial port wait 300 milliseconds and repeat. See the whole example sketch and grab the library from the download section below.
/* LucidTronix L3G4200D Gyroscope Library
 * For instructions, details and schematic, See:
#include <L3G4200D.h>
#include <Wire.h>

L3G4200D gyro;

int x, y, z;

void setup(){

void loop(){
  x = gyro.getX();

  y = gyro.getY();
  Serial.print(" Y:");

  z = gyro.getZ();
  Serial.print(" Z:");
  delay(300); //Just here to slow down the serial to make it more readable

L3G4200D Gyroscope Arduino Library


    This is set by control register 4. By default it is 2000 deg/s. The chip also supports 250 and 500 deg/s and you can change control register 4 in the .cpp file.
    Sat, Dec 26 2015 8:57PM
    Hi, im trying to look in which units does this library gives the output? To convert it to deg/s, thanks!
    Thu, Dec 03 2015 7:18PM
Here is another arduino library to handle Hue, Saturation, and Brightness as well as Red, Green, and ...
An arduino library for the MMA8453 Triple Axis Accelerometer...
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Rainbow flower necklace using the TLC5940....
Play pong on a little LCD screen with two big joysticks....
Control a 120v outlet with a 5V arduino....
An open source bitmap converter program built with Open Frameworks...
Two LED matrices give 70 LEDs to light up a necklace with messages....