On the datasheet it says that the number 2 corresponds to +-8g and I've seen tutorials saying we need to write 0x10 to the 0x1C register but how does 0x10 = 2?????
If you look at the datasheet, Register 0x1C has these bits
bit 7 = XA_ST
bit 6 = YA_ST
bit 5 = ZA_ST
bits 4:3 = AFS_SEL[1:0]
and you want to set AFS_SEL to the value 2 which is binary 10 which means set bit 4 of the register.
If you write that out as binary, it is 0b0001 0000 which is 0x10 (hex)
So, "writing the number 2" refers to the AFS_SEL bits which you then have to translate into the location within the register. Many libraries exist which define lots of handy constants and do all this translation for you.
Hi, @cyberinio
Welcome to the forum.
If you have the Library for the MPU6050 loaded in your Arduino IDE, you will find some example codes that show you have to change sensitivity/range.
Tom....
![]()
Thank you for your reply but what do you mean by "binary 10 which means set bit 4 of the register"??
Also am I right to say that since value 3 = binary 11 then i would write in 0x11 ?
the AFS_SEL bits occupy bits 3 and 4 of the register at 0x1C. This means bit 0 of AFS_SEL is the same as bit 3 of the register and bit 1 of AFS_SEL is bit 4 in the register.
I think I understand now thank you so much for your help, btw am I right to say that since value 3 = binary 11 then i would write in 0x11??
"0x" means HEX (hexadecimal). decimal 3 is also hexadecimal 3 (because it's < 10 decimal). So 3 = 0x03. But it would be 0b11.
No, If you write 0x11, that is the same as 0b 0001 0001 so you would be setting bit 4 and bit 0.
bit: 7 6 5 4 3 2 1 = register at 0x1C
AFS_SEL = x x
so
AFS_SEL = 3 would be
bit: 7 6 5 4 3 2 1 = register at 0x1C
AFS_SEL = 1 1
which is 0b 0001 1000 = 0x18 (hex)
I see I see, so then AFS_SEL 1 = 0x08 and AFS_SEL 0 = 0x00?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.