Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

LPY510AL gyro readings



Here is the avr-gcc code I use to periodically read the gyro’s indication around the X-axis.

(4X output is connected to ADC1 and Vref is connected to ADC0)

ISR( TIMER2_COMP_vect ) { // ADMUX ^= 1; ADCSRA |= (1 << ADSC); while (ADCSRA & (1 << ADSC)) { } valoare = ADCL + 256 * ADCH; UART_Transmit_Float( valoare ); }

I have 2 problems:

  1. If I uncomment the first line

which means that I would read ADC1 and ADC0 alternatively, then I read a constant value of 395 on ADC0 (aka Vref) and ~392 on ADC1 (aka 4X).
If I leave it commented, which means that I only read ADC1 (aka the 4X output), I get a value of 497 (which soon drops to 492). A huge difference! Why does this happen?

  1. Why does the reading on ADC1 (aka 4X) change when I rotate the sensor around the Z-axis and Z-axis alone?




Based on the information you have given us, I would guess that this is a problem with your AVR setup or code, not the gyro. Can you simplify your system as much as possible, then post your entire code and a detailed description of the circuit and a picture if possible?

In particular, I recommend removing the gyro from the circuit and replacing it with resistor voltage dividers giving you approximately the voltages you expect. On the other hand, if take work as expected and you suspect that the gyro is the problem, you could remove the AVR from the circuit and look at the gyro outputs with a multimeter.



This is weird:
I simplified the circuit, meaning that I removed a dummy motor driver and I changed the gyro’s position on the breadboard.
I now read Vref=395 and 4X = ~383 in both cases, which I think is correct.

The driver wasn’t running and the connections were the same…

The difference 395-383 => 40mV difference => 4deg/sec can be attributed to gyro’s drift, am I correct?


This is still baffling me.

Edit: maybe the floor I’m rotating it on around the Z-axis isn’t perfectly horizontal and there are “smallish” influences on the X axis.



From the datasheet:

This is not “drift” unless it changes over time. I recommend calibrating your sensor for this if it matters to you.

As for question 2, unless you describe your setup and show us your numbers, I cannot really comment. But sure, if you do not rotate it perfectly, you will see some variation in the reading on the other axis.



How do I calibrate it? :open_mouth:



I was not trying to imply that there is any calibration feature built in to the chip - just that instead of using Vref as your zero, you can measure what the sensor reads when it is not moving, and use that value as a zero.



Things are this: the static output of 4X, which is 383, agrees with the datasheet (1.23 V), while Vref does not (1.27).

Thank you for the help!


How are you sure that your ADC is so accurate? Can you also check Vref with a multimeter? It really does not matter in this situation, but in general, a good thing to do on the AVR (or most microcontrollers) if you need accurate measurements is to calibrate your analog reference against the internal reference diode. The datasheet for your AVR should have more information, but basically there is an internal analog channel you can read that should give you a precise voltage independent of VCC or AREF, which could easily be off by 5% or so.



Yes, I did check with two multimeters and one oscilloscope.