micro:bit and L3GD20 angular rate sensor

The L3GD20 is a low-power three-axis angular rate sensor. This is the module I bought for reference

More information can be found at http://www.st.com/content/st_com/en/products/mems-and-sensors/gyroscopes/l3gd20.html about the sensor

Features

  • Three selectable full scales (250/500/2000 dps)
  • I2 C/SPI digital output interface
  • 16 bit-rate value data output
  • 8-bit temperature data output
  • Two digital output lines (interrupt and data ready)
  • Integrated low- and high-pass filters with user-selectable bandwidth
  • Wide supply voltage: 2.4 V to 3.6 V
  • Low voltage-compatible IOs (1.8 V)
  • Embedded power-down and sleep mode
  • Embedded temperature sensor
  • Embedded FIFO
  • High shock survivability

Here is a schematic showing the module I had.

 

Connection

 

micro:bit Connection GY-50 L3GD20 connection
3v3 Vcc
Gnd Gnd
P20 SDA
P19 SCL

 

Code

I managed to find the following library that seemed to work well – https://github.com/pololu/l3g-arduino

This is the test example

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <L3G.h>

L3G gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();
}

void loop() {
  gyro.read();

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x);
  Serial.print(" Y: ");
  Serial.print((int)gyro.g.y);
  Serial.print(" Z: ");
  Serial.println((int)gyro.g.z);

  delay(100);
}

[/codesyntax]

 

Output

Open the serial monitor and you should see something like this

G X: 240 Y: -90 Z: -20
G X: 234 Y: -106 Z: -29
G X: 223 Y: -109 Z: -8
G X: 251 Y: -121 Z: -25
G X: 213 Y: -103 Z: 7
G X: 32752 Y: -5678 Z: 2387
G X: -5163 Y: -535 Z: -25250
G X: 3492 Y: 24889 Z: -3671
G X: 11287 Y: 8407 Z: -7101
G X: -9943 Y: 1122 Z: -19589

Links

You can pick up one these sensors for about $4

L3GD20 3-axis Gyroscope Sensor replace L3G4200D Angular velocity module

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :