Kaynağa Gözat

IIC总线和地址使用变量可配置

adam_zhuo 3 yıl önce
ebeveyn
işleme
9e75d57c1a

+ 3 - 1
iic_6dof_imu/iic_6dof_imu.py

@@ -20,7 +20,9 @@ yaw = 0.0
 seq = 0
 accel_factor = 9.806  #sensor accel g convert to m/s^2.
 
-myIMU = MyIMU(0x50)
+imu_iic_bus = 1
+imu_iic_addr = 0x50
+myIMU = MyIMU(imu_iic_bus, imu_iic_addr)
 
 print("Now 6DOF IMU Module is working ...")
 while True:

+ 3 - 3
iic_6dof_imu/iic_6dof_imu_data.py

@@ -10,9 +10,9 @@ import smbus
 import numpy as np
 
 class MyIMU(object):
-    def __init__(self, addr):
-        self.addr = addr
-        self.i2c = smbus.SMBus(1)
+    def __init__(self, iic_bus, iic_addr):
+        self.i2c  = smbus.SMBus(iic_bus)
+        self.addr = iic_addr
 
     def get_YPRAG(self):
         try: