【发布时间】:2017-09-24 11:55:20
【问题描述】:
产品:https://www.adafruit.com/product/2020
数据表:https://cdn-shop.adafruit.com/datasheets/LSM9DS0.pdf
我是学生,这是我第一次使用 I2c 总线。我正在尝试读取基本陀螺仪值。我浪费了我生命中的一部分来了解 I2c 是如何工作的。但是在阅读了数据表并制作了我自己的脚本之后。 我的价值观被困在那里。什么都没有动,我不知道为什么。
Rotation in X-Axis : -1087
Rotation in Y-Axis : -28797
Rotation in Z-Axis : -15032
这是我的脚本。有人可以帮我解决吗?我正在使用小猎犬骨黑。
import smbus
import time
bus = smbus.SMBus(1)
# 0x6b adress (found with i2cdetect), 0x20 register (found with the data sheet), CTRL_REG1_G(20h)
bus.write_byte_data(0x6b, 0x20, 0x0F)
bus.write_byte_data(0x6b, 0x23, 0x30)
time.sleep(0.5)
data0 = bus.read_byte_data(0x6b, 0x08)
data1 = bus.read_byte_data(0x6b, 0x09)
xGyro = data1 * 256 + data0
if xGyro > 32767 :
xGyro -= 65536
data0 = bus.read_byte_data(0x6b, 0x0A)
data1 = bus.read_byte_data(0x6b, 0x0B)
yGyro = data1 * 256 + data0
if yGyro > 32767 :
yGyro -= 65536
data0 = bus.read_byte_data(0x6b, 0x0C)
data1 = bus.read_byte_data(0x6b, 0x0D)
zGyro = data1 * 256 + data0
if zGyro > 32767 :
zGyro -= 65536
print "Rotation in X-Axis : %d" %xGyro
print "Rotation in Y-Axis : %d" %yGyro
print "Rotation in Z-Axis : %d" %zGyro
【问题讨论】:
-
您能正确读取
WHO_AM_I_G (0Fh)寄存器吗?这将是我尝试的第一件事,因为它返回一个常量。 -
在我看来,您从错误的地址读取。陀螺仪输出寄存器位于 0x28...0x2D(数据表中的第 8.9 - 8.11 节)。访问陀螺仪子模块时保留地址 0x08..0x0D。
标签: python beagleboneblack i2c gyroscope