# Main Idea of Gyro  I have a L3G4200D (GY-50 model) gyroscope. I have been trying to learn how a gyro sensor works. The circuit diagram is attached. I want to ask some questions;

a) According to the datasheet of L3G4200D, x_lsb and x_msb (28h and 29h), y_lsb ,y_msb (2Ah and 2Bh), z_lsb , z_msb (2Ch and 2Dh) as shown in the picture 3. But according to code that in the picture first, Arduino requests bytes from 168 address of gyro (in the picture, the mark number is 1). But, 0x28 (hex) stands for b00101000 . What's wrong with it ?

b) Output of gyro is outputs degrees/second, is it correct?

c) In the picture 2, I did not move it, as it shown its results change, how can the angle change? It must be zero when it does not move.

d) In the picture 1, what I should calculate: highbyte*256+lowbyte ?

e) What does Fs=250,500,2000 dps mean? I know that Dps stands for Degree Per Second. But what would change by FS range, I mean if I pick either 500 or 2000 ?

• Have you taken a look at the datasheet for your gyro? – nanofarad Jul 5 '16 at 20:04
• Yes,I have.I have learned how to control registers 1 and 4. That's all. by the way,I have downloaded the code that is written above, I did not write it. – Unforgiven Jul 5 '16 at 20:09
• When I used LIS2DH last year, I found address byte has some extra complexity - read the entire datasheet for "gotchas". I think it was a bit to enable consecutive register reads. FS means Full Scale. – MarkU Jul 5 '16 at 20:16

## 2 Answers

According to the datasheet of L3G4200D, x_lsb and x_msb (28h and 29h), y_lsb ,y_msb (2Ah and 2Bh), z_lsb , z_msb (2Ch and 2Dh) as shown in the picture 3. But according to code that in the picture first, arduino requests biytes from 168 adress of gyro(in the pciture ,mark number is 1). But , 0x28 (hex) stands for b00101000 . what's wrong with it ?

168 is, in hex, 0xA8. That's 0x28 with the MSB set. Why? Well, the datasheet says:

In order to read multiple bytes, it is necessary to assert the most significant bit of the subaddress field. In other words, SUB(7) must be equal to 1, while SUB(6-0) represents the address of the first register to be read.

So address 0xA8 is the same as address 0x28 plus the instruction "I want to read multiple bytes".

Output of gyro is outputs degrees/second ,is it correct ?

Kind of. The number is actually a representation of the fraction of FS. See below.

in the picture 1,what I should calculate hightbyte*256+lowbyte ?

That is turning two 8-bit values into a single 16-bit value. It's easier to represent it using bit shifts:

``````(bighbyte << 8) | lowbyte
``````

That is, the high byte is shifted left 8 bits and the low byte is then ORed over the lower (zero) 8 bits.

What does Fs=250,500,2000 dps mean ? I know that Dps stands for Degree Per Second .But what would change by FS range ,I mean if I pick either 500 or 2000 ?

That is the "Full Scale" value. It defines what the raw numbers from the gyro actually mean. The gyro returns -32768 to +32767. -32768 is -FS, +32767 is +FS. So if the FS is set to 500 degrees per second then:

• -32768 is -500 degrees per second
• +32767 is +500 degrees per second

The simple formula is (using floating point maths):

DPS = Reading / 32768.0 * FS

The format is more commonly known as Q15 where a 16-bit value is split into 3 parts - a sign bit (bit 15), an integer part (there isn't one in this case), and 15 bits (14-0) of fraction. So the number actually represents, in Q15 format, between -1 and +1 in 65536 steps of 1/65536. That number is then multiplied by the full scale value, just like you would a percentage, to get the real DPS value.

• Thank you, These are very precious informations. I think it will take me long time understand whole part of it. – Unforgiven Jul 5 '16 at 21:06

According to the datasheet, FS seems to be Measurement Range. Also, I think you will find useful information in the following discussions: Understanding the sensitivity of an L3G4200D gyroscope and in How do I get gyro sensor data (L3G4200D) into degrees/sec? Due to the fact that the gyro is 16 bit, the range of values would be 2^16, what makes 65536. So, the values on your screen are between -65536/2 and +65536/2, that's why max. values that you see are around 32000.

There is always very tiny motion that the sensor can detect due to vibrations and etc. So, you should not expect the output of gyro to be a set of constants. Ideally, you should combine the data, lets say for 1 second, and find RMS value(average it) to get the result, don't look just for few instances/samples.

Also I should note that if there is ultrasound in the gyro environment, it might also cause wrong results. When outer frequencies coincide with the natural frequency of the gyro system, it leads to resonance and distorted data. This paper has explanation of this phenomenon among with other impacts to the gyroscope.

• Thanks for replying. I have already read that topics you recommend. Do you suggest calibrating the gryo ? I mean,first I will get 1500-2000 measures and define 0 point, and every time you read values from gyro ,compare it to calibration values , if it does not move value will be 0 . – Unforgiven Jul 5 '16 at 21:10
• Yes, something like that. Let's say you average 2000 values, (use RMS instead of mean, because you have negative values), and get 300(x) 400(y) 100(z) values. This would be your 0 point. When you will get a new point, you could compare it to the 0 point to see how much the values has changed and make calculations. I guess there should be ready libraries to make the calculations easy. Just continue to research, there are many projects with reports and ready software done on this topic, I am sure you can find much more. – UserRR Jul 5 '16 at 23:05
• Yes,I have already found ready-code and its simulation,it works perfectly..But I have to learn how it is written,how it works.The first thing that I should do is to run that code step by step . Thank you for your help. – Unforgiven Jul 6 '16 at 11:54