Angular velocity with Arduino
In this tutorial we will use the L3G4200D sensor from STMicroelectronics. This gyroscope measures angular rates about three axes. They are referenced as x, y and z. The angular velocity about the x, y and z axis are also called respectevely roll pitch, and yaw rate.
What you will need
- L3G4200D 3 axes gyroscope
- Arduino Board. It is possible to interface the sensor to a Raspberry Pi as well.
- Male-male jumpers
- Software: Arduino IDE. Processing
- GND -> GND
- VCC -> 3.3V
- SDA -> A4
- SCL -> A5
- SD0 -> 3.3V
Getting angular velocities
In order to read data we need to request them from the sensor using the I2C library. As we can see from page 35 of the datasheet, the angular rate data are expressed as two’s complement and stored in registers. The following snippet retrieves these values from the registers and saves them in x,y and z variables.
So with the unique device address 105 (in hexadecimal) and the number of bytes of data to accept from the device we first begin the transmission and request data from the register. Then we read and save the bytes we are looking for. The read and write functions are reported below. Thanks to Bildr.org for these.
Finally, we will print the angular rates to the serial interface in the format “A,wx,wy,wz,Z”.
Initiate the Wire library for I2C communication, the Serial interface and the gyroscope with the resolution of 250°/s. Place what follows in your setup().
- Gaming and virtual reality input devices
- Angular Motion detection
- Attitude Estimation
- GPS navigation systems
- Appliances and robotics