diff --git a/internal_filesystem/lib/drivers/imu_sensor/bma423/bma423.py b/internal_filesystem/lib/drivers/imu_sensor/bma423/bma423.py index 6dae8f08..60571625 100644 --- a/internal_filesystem/lib/drivers/imu_sensor/bma423/bma423.py +++ b/internal_filesystem/lib/drivers/imu_sensor/bma423/bma423.py @@ -39,22 +39,25 @@ class BMA423: # 2G, 4G, 8G and 16G. If we want to be able to measure higher # max accelerations, the relative precision decreases as we have # a fixed 12 bit reading. - def __init__(self,i2c,*,acc_range=2): + def __init__(self,i2c,*,acc_range=2,address=None): default_addr = [0x18,0x19] # Changes depending on SDO pin # pulled to ground or V+ self.i2c = i2c self.myaddr = None self.features_in = bytearray(FEATURES_IN_SIZE) - found_devices = i2c.scan() - print("BMA423: scan i2c bus:", [hex(x) for x in found_devices]) - for addr in default_addr: - if addr in found_devices: - self.myaddr = addr - break - if self.myaddr == None: - raise Exception("BMA423 not found at i2c bus") - print("BMA423: device with matching address found at",hex(self.myaddr)) + if address is not None: + self.myaddr = address + else: + found_devices = i2c.scan() + print("BMA423: scan i2c bus:", [hex(x) for x in found_devices]) + for addr in default_addr: + if addr in found_devices: + self.myaddr = addr + break + if self.myaddr == None: + raise Exception("BMA423 not found at i2c bus") + print("BMA423: device with matching address found at",hex(self.myaddr)) # Device initialization. self.reset() diff --git a/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py b/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py index 7dfa6b94..1b7092fd 100644 --- a/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py +++ b/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py @@ -82,6 +82,12 @@ mic_input = AudioManager.add( # Vibrator test # One strong & fairly long buzz (repeat as needed) +from machine import I2C, Pin +i2c = I2C(1, sda=Pin(10), scl=Pin(11), freq=400000) + +def write_reg(reg, val): + i2c.writeto_mem(0x5A, reg, bytes([val])) + write_reg(0x01, 0x00) # internal trigger write_reg(0x03, 0) # Library A write_reg(0x04, 47) # Strong Buzz 100% @@ -92,9 +98,8 @@ write_reg(0x0C, 0) # stop (optional) # IMU: import drivers.imu_sensor.bma423.bma423 as bma423 -from machine import SoftI2C, Pin -i2c = SoftI2C(scl=11,sda=10) -sensor = bma423.BMA423(i2c) +sensor = bma423.BMA423(i2c, address=0x19) +time.sleep_ms(500) # some sleep is needed before reading values print("temperature: ", sensor.get_temperature()) print("steps: ", sensor.get_steps()) print("(x,y,z): ", sensor.get_xyz()) diff --git a/internal_filesystem/lib/mpos/main.py b/internal_filesystem/lib/mpos/main.py index ad37f1f6..000cca7e 100644 --- a/internal_filesystem/lib/mpos/main.py +++ b/internal_filesystem/lib/mpos/main.py @@ -107,7 +107,7 @@ def detect_board(): print("lilygo_t_watch_s3_plus ?") if i2c0 := fail_save_i2c(sda=10, scl=11): - if single_address_i2c_scan(i2c0, 0x19): # IMU on 0x19, scan shows: [25, 52, 81, 90] + if single_address_i2c_scan(i2c0, 0x19): # IMU on 0x19, vibrator on 0x5A and scan also shows: [52, 81] return "lilygo_t_watch_s3_plus" # example MAC address: D0:CF:13:33:36:306 # Then do I2C-based board detection