Wiring for Flora
Flora uses conductive thread or aligator clips, connect up the 3V/SDA/SCL/GND pins to the matching pins in the north-west quarter of the Flora board. We suggest alligator clips to test, then sew in with thread once it works!Wiring for Arduino
You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C or SPI, then port the code - its pretty simple stuff!Let's start with just I2C interfacing since it requires the fewest # of wires:
-
Connect Vin to the power supply, 3-5V is fine. Use the same
voltage that the microcontroller logic is based off of. For most
Arduinos, that is 5V
- Connect GND to common power/data ground
- Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
- Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2
Download Arduino Libraries
To begin reading sensor data, you will need to download the Adafruit LSM9DS0 library and the Adafruit Unified Sensor library from the Arduino library manager.
Open up the Arduino library manager:
Search for the Adafruit LSM9DS0 library and install it
Search for the Adafruit Unified Sensor and install it (you may have to scroll down quite far to find it)
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Load Demo Sketch
Now you can open up File->Examples->Adafruit_LSM9DS0->lsm9doftest and upload to your Arduino wired up to the sensor
This time, you'll get the outputs in m/s*s, gauss an degrees-per-second
Library Reference
The library we have is simple and easy to useYou can create the Adafruit_LSM9DS0 object with:
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(); // i2c sensor
If you're using "hardware" SPI, you will have to wire up the pins as follows:
- SCL -> SPI CLK
- SDA -> SPI MOSI
- SDO_XM & SDO_G -> SPI MISO (both together)
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(LSM9DS0_XM_CS, LSM9DS0_GYRO_CS);
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(LSM9DS0_SCLK, LSM9DS0_MISO, LSM9DS0_MOSI, LSM9DS0_XM_CS, LSM9DS0_GYRO_CS);
Begin!
To initialize the sensor, call lsm.begin() which will check the sensor can be found. It returns true/false depending on these checks. We suggest you wrap begin() in a statement that will check if the sensor was located:if(!lsm.begin()) { /* There was a problem detecting the LSM9DS0 ... check your connections */ Serial.print(F("Ooops, no LSM9DS0 detected ... Check your wiring!")); while(1); }
Set Ranges
These chips have tons of registers, we basically provide interface code for the most useful stuff, such as setting the range. Each subsensor has it's own range. Higher ranges have less precision but can measure larger movements!Set up the ranges with the setup functions:
// 1.) Set the accelerometer range lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G); //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G); //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G); //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G); //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G); // 2.) Set the magnetometer sensitivity lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS); //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS); //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS); //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS); // 3.) Setup the gyroscope lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS); //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS); //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
Read data
Read data using the Adafruit_Sensor API by first creating four events, one for each sub-sensor:sensors_event_t accel, mag, gyro, temp;
lsm.getEvent(&accel, &mag, &gyro, &temp);
For the Accelerometer event you can read accel.acceleration.x, accel.acceleration.y or accel.acceleration.z which are in meters/second*second.
For the Magnetometer event you can read mag.magnetic.x, mag.magnetic.y or mag.magnetic.z which are in gauss.
For the Gyro event you can read gyro.gyro.x, gyro.gyro.y or gyro.gyro.z, which are in degrees-per-second (dps)
The temperature event data is in temp.temperature, in degrees C
Text editor powered by tinymce.