Updated MPUxxx driver

This commit is contained in:
Stephan Hadinger 2021-06-18 18:36:32 +02:00
parent cf81127193
commit 236c17d896
1 changed files with 20 additions and 5 deletions

View File

@ -5,14 +5,13 @@
- Alternative to xsns_85_mpu6886.ino - Alternative to xsns_85_mpu6886.ino
-# -#
class MPU6886 : Driver class MPU6886 : I2C_Driver
var wire #- if wire == nil then the module is not initialized -#
var device var device
var gres, ares var gres, ares
var accel, gyro var accel, gyro
def init() def init()
self.wire = tasmota.wire_scan(0x68, 58) super(self, I2C_Driver).init(self.detect_mpu, 0x68, 58)
if self.wire if self.wire
var v = self.wire.read(0x68,0x75,1) var v = self.wire.read(0x68,0x75,1)
@ -50,7 +49,22 @@ class MPU6886 : Driver
self.gres = 2000.0/32768.0 self.gres = 2000.0/32768.0
self.ares = 8.0/32678.0 self.ares = 8.0/32678.0
print("I2C:","MPU"+str(self.device),"detected on bus",self.wire.bus) end
end
#- detect the MPU model type -#
#- currently MPU6886 and MPU9250 -#
def detect_mpu()
if self.wire
var v = self.wire.read(0x68,0x75,1)
if v == 0x19 self.device = 6886
elif v == 0x71 self.device = 9250
end
if self.device
return "MPU" + str(self.device)
end
#- don't return anything if invalid or unidentified -#
end end
end end
@ -118,5 +132,6 @@ class MPU6886 : Driver
end end
end end
mpu_accel = MPU6886() mpu_accel = MPU6886()
tasmota.add_driver(mpu_accel) tasmota.add_driver(mpu_accel)