L3g20h gyroscope code getting stuck

Hi, I’m trying to run the Serial example in the library for the l3g20h gyroscope, but I’m having issues. I’ve imported the library, I’m using an Arduino Uno, and the program compiles without issues. But when I run it, it stops when it encounters a function from the library. So, for example, it’ll output basic Serial.println text outputs before any function from the library, and after a l3g function it doesn’t output anything. Neither while(gyro.init()) nor while(!gyro.init()) loop will work for checking the detection, there’s no text output inside the loop, it seems to just get stuck on the gyro.init. I was told this may be a wiring issue, but shouldn’t this output something regardless of the wiring? I also noticed that if I manually enter (L3G::device_D20, L3G::sa0_high) into the function parameters then it gets past that function call, but since there are functions without any parameters, that can’t always work. Does anyone know what the issue could be? I’ve tried using the adafruit l3g20h code, and it works fine to the extent of not getting stuck, I can check how it outputs the actual values if needed, though I’d rather use the native library for the pololu gyro.


I am sorry you are having trouble interfacing with your gyro. We have noticed that behavior like that can happen if SCL or SDA is being pulled low for some reason. Can you post pictures that clearly show how you have your gyroscope connected? Could you go ahead and check whether you are successfully getting data when using the Adafruit library?


I will do that tomorrow and will attach a picture, but I just follow the standard connections as said on the library for the uno: 5V- Vin, gnd-gnd, A4- sda, A5-scl. I’ve also tried 3.3V-Vdd. Also I’ll check the actual values from the adafruit code, but I don’t expect them to be right since they might have different registry values.

The photo is too big to attach so here is a link to it imgur.com/5VetEwW . I wasn’t able to get the adafruit code to properly identify the gyro, since it’s probably based on the adafruit version of the gyro, I would probably have to mess around with the library to get it to work. However, I noticed it was in SPI when it was giving me text outputs of not recognizing the gyro, and when I switched it to I2C it stopped outputting anything like the pololu code. So, I tried to connect the CS pin on the gyro to Vdd to try and force an I2C connection, but it didn’t help.

Your connections look okay; I also don’t see any indications that there could be a short. Can you measure the voltage on the SCL or SDA pins while the gyro is powered and tell me what you get?


I don’t currently have a voltmeter, I can check tomorrow if it would be better, but the arduino analogRead gives me 1023 or 5V on SCL, and 953 or 4.66 V on SDA.

I just checked with the multimeter, it’s 5V on scl and 4.9V on sda. I also just received a new arduino uno, and I tried using it, and the code actually outputs things now, which is odd because the previous arduino worked fine other than this. However, the code wasn’t able to autodetect the gyroscope.

Thanks for looking into those things and making an update about the new Arduino you are using. Have you been able to get your original Arduino Uno to communicate over I2C with any other I2C device? If not, it sounds like the I2C functionality has somehow been damaged. Also, when you say “the code wasn’t able to autodetect the gyroscope”, do you mean that the new Arduino will not autodetect the gyro, but if you specify it manually, it seems to work fine?


I’ve never tested the previous arduino with other I2C devices. The only obvious difference is that the new one doesn’t say it was made in Italy, I don’t know where the previous one was purchased. But currently for the new arduino, if I specify it manually it seems to get past the detection loop and gyro.enableDefault() and works until it encounters gyro.read, at which point it again stops and doesn’t output the actual values. If I set a void setTimeout then it continually outputs zeroes as the values, which I’m guessing means the gyro itself isn’t working.

That is some strange behavior; it sounds like your gyro might be damaged. If you email us with your salesorder information and refer to this thread, and we could look into helping you out with a replacement.


I didn’t end up asking for a replacement, thanks for the offer though, but it seems the issue was a problematic wire all along. Even though I checked its connectivity, and it could communicate with the arduino, and output things like mentioned before, somehow it only seems to have issues when encountering library commands, some I2C issue. So, that problem is finally done with.
This is a bit off-topic, but I’ve been testing it, and I was wondering if you think it’s possible to get accuracy within 3-5 degrees (after single turns, not long-term). I’m getting rather inaccurate values, within 10-20 degrees usually. I doubled the sample time for improved values, as they were half of the correct at first, and it sometimes will output within 5 degrees, but it doesn’t do it consistently either. Would a Kalman filter with an accelerometer or other gyros help significantly with this? Or maybe there’s a different gyro that would give more accurate results? I picked this one because of the low noise density.

I think you should probably be able to get better than 10 degrees, but the accuracy might depend on how you are reading the gyro, and how accurately you are keeping track of time between measurements.


A post was merged into an existing topic: Zumo Reflectance Sensor Array not working