import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# MPU-6000 address, 0x68(104)
# Select gyroscope configuration register, 0x1B(27)
# 0x18(24) Full scale range = 2000 dps
bus.write_byte_data(0x68, 0x1B, 0x18)
# MPU-6000 address, 0x68(104)
# Select accelerometer configuration register, 0x1C(28)
# 0x18(24) Full scale range = +/-16g
bus.write_byte_data(0x68, 0x1C, 0x18)

# MPU-6000 address, 0x68(104)
# Select power management register1, 0x6B(107)
# 0x01(01) PLL with xGyro reference
bus.write_byte_data(0x68, 0x6B, 0x0

Its in +-16g but and according to the datasheet 1 page 15, its AFS_SEL. So i just simply replace the bus.write_byte_data(0x68, 0x1C, 0x18) the '0x18' into AFS_SEL = 0 and replace '0x18' into FS_SEL = 0 for both accelerometer and gyro?

 Acceleration in X-Axis : 932
Acceleration in Y-Axis : -108
Acceleration in Z-Axis : 15036
X-Axis of Rotation : -362
Y-Axis of Rotation : -40
Z-Axis of Rotation : -114

Data i get using bus.write_byte_data(0x68, 0x1C, 0x18)

Acceleration in X-Axis : 924
Acceleration in Y-Axis : -32
Acceleration in Z-Axis : 15072
X-Axis of Rotation : -335
Y-Axis of Rotation : -30
Z-Axis of Rotation : -95

And these are the data i get by using (0x68, 0x1C, 0x00) Aren't they almost the same?

  • 1
    \$\begingroup\$ Your link is broken, and the words in your text don't match anything in the code snippet, so it's impossible to understand what you're asking. \$\endgroup\$ – Dave Tweed Apr 28 '19 at 15:03
  • \$\begingroup\$ i've edited the post. \$\endgroup\$ – ckkkk Apr 28 '19 at 15:07

What you're suggesting is absolutely technically correct, but expressed in a slightly confusing way.

The things called AFS_SEL and FS_SEL are 2-bit fields within the registers. Writing 0x00 instead of 0x18 to the registers is correct, because you're switching the fields from FS_SEL = 'b11 to FS_SEL = 'b00.

Bottom line: the relevant code is bus.write_byte_data(0x68, 0x1B, 0x00).

  • \$\begingroup\$ So it should be "bus.write_byte_data(0x68, 0x1C, 0x18)" from +-16g into "bus.write_byte_data(0x68, 0x1C, 0x00)" +-2g? \$\endgroup\$ – ckkkk Apr 28 '19 at 15:28
  • \$\begingroup\$ But the data i get from both (0x68, 0x1C, 0x18) and (0x68, 0x1C, 0x00) are almost the same \$\endgroup\$ – ckkkk Apr 28 '19 at 15:34
  • \$\begingroup\$ If I missed that before you put in the expanded version, I'm sorry. From my (quite light) reading of the data sheet, you're doing the correct thing there. I would suggest an even closer reading, to see if the chip needs to be in a specific mode for the write to "take" (it may need to be in reset, or not in reset, or powered down, or not powered down, or it may not matter at all -- it depends on the manufacturer) \$\endgroup\$ – TimWescott Apr 28 '19 at 16:12
  • \$\begingroup\$ The acceleration in z-axis should be close to 1g right? But it doesn't look like that. \$\endgroup\$ – ckkkk Apr 29 '19 at 9:47
  • \$\begingroup\$ Yes, and you can do a quick & dirty test of the accelerometer by tipping it and checking the acceleration. \$\endgroup\$ – TimWescott Apr 29 '19 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.