Parcourir la source

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

adam_zhuo il y a 3 ans
Parent
commit
9e75d57c1a
2 fichiers modifiés avec 6 ajouts et 4 suppressions
  1. 3 1
      iic_6dof_imu/iic_6dof_imu.py
  2. 3 3
      iic_6dof_imu/iic_6dof_imu_data.py

+ 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: