I'm trying to get the LSM9DS0 gyro/accelerometer/magnetometer to work with my Arduino. I'm using the example included in the library from the adafruit website on the gyro. About halfway through setup, the whole thing just freezes and nothing progresses.
This is the example sketch:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
void setupSensor()
{
// 1.) Set the accelerometer range
lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
// 2.) Set the magnetometer sensitivity
lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
// 3.) Setup the gyroscope
lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
void setup()
{
Serial.begin(9600);
Serial.println("LSM raw read demo");
// Try to initialise and warn if we couldn't detect the chip
if (!lsm.begin())
{
Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
while (1);
}
Serial.println("Found LSM9DS0 9DOF");
Serial.println("");
Serial.println("");
}
void loop()
{
lsm.read();
Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.accelData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.accelData.z); Serial.print(" ");
Serial.print("Mag X: "); Serial.print((int)lsm.magData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.magData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.magData.z); Serial.print(" ");
Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.gyroData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.gyroData.z); Serial.println(" ");
Serial.print("Temp: "); Serial.print((int)lsm.temperature); Serial.println(" ");
delay(200);
}
This is the simplified version:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h> // not used in this demo but required!
// i2c
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
void setupSensor()
{
// 1.) Set the accelerometer range
lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
// 2.) Set the magnetometer sensitivity
lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
// 3.) Setup the gyroscope
lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
}
void setup()
{
Serial.begin(9600);
Serial.println("LSM raw read demo");
if (!lsm.begin())
{
Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
while (1);
}
Serial.println("Found LSM9DS0 9DOF");
Serial.println("");
Serial.println("");
}
void loop()
{
lsm.read();
Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.accelData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.accelData.z); Serial.print(" ");
Serial.print("Mag X: "); Serial.print((int)lsm.magData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.magData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.magData.z); Serial.print(" ");
Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)lsm.gyroData.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)lsm.gyroData.z); Serial.println(" ");
Serial.print("Temp: "); Serial.print((int)lsm.temperature); Serial.println(" ");
delay(200);
}
In the Serial monitor, both of them just stop working after "LSM raw read demo".
No pull-up resistors, and as far as I'm aware, I have it wired up correctly.
When I ran the i2c detector sketch, the serial monitor gave me the line ÒZÒZÿ¤ÿ
Then I changed Serial.begin(115200); to Serial.begin(9600); and it gave me the output:
I2C scanner. Scanning ...
Done.
Found 0 device(s).
It may be an optical illusion, but it appears the blue wire is connected to the GND pin on the Arduino and the 3.3v pin on the LSM9. Can you verify that? On the LSM9, the GND pin is next to the yellow wire, not the red one.
You can't just push them together. You have to solder them, with the longer pins going downwards so they make contact with the metal inside the breadboard.
Demonstrating with a spare board I have lying around ...
Line up with the short pins ready to insert into the board:
Insert, and then solder along the top (each pin individually):
The finished result would look like my earlier photo, with a nice blob of solder on the top of each pin, flowing around it.
Ah ok, I think I got it this time. So, is there any explanation for what is happening? Am I experiencing some kind of software glitch with the arduino?
Edit: Ah, I didn't see that you posted again. I'll try my hand at soldering and get back to you. But, if the metal parts are all in contact with each other, why would it matter if they're soldered?
Am I experiencing some kind of software glitch with the arduino?
Hardly. You are experiencing bad contacts made by not soldering. Just pushing wires together (where they may have films of oxidation on them) is not going to give you a good joint.
You turned out to be completely correct and I wish I could shake your hand and thank you in person. Everything worked perfectly after some soldering.
Apologies for ignoring your question, I assure you it wasn't intentional. I didn't realize what you meant and didn't know what I was doing. It would indeed have saved us quite a lot of time.
I feel a little bad for asking you even more questions after this whole ordeal, but would you happen to know anything about getting meaningful values from the board?
That's what I'm getting from the board currently, and even when it's just sitting still, there's a huge amount of variance every 200 ms. The Gyro values seem to climb and fall by up to 40 (degrees?) every time, the Accelerometer returns a value around 2000 and varies by up to 150, and the Magnetometer seems to have a similar issue to the Accelerometer.
I realize this doesn't have much to do with my original post, and I understand if you're fed up with me at this point! But I'd still like to thank you for all your help.
Just confirm what code is producing those results. You posted a couple of versions before. I don't have that board, so I will be guessing a bit about what the problem is.