树莓派Pico I2C问题求教!
发表于 : 2022年 3月 2日 19:53
用树莓派Pico与一个角度传感器通信,通过I2C,写入传感器的控制指令为2字节,16位,但不知道micropython如何写入16位,以下代码,写入后没有用,求大神帮忙!from machine import Pin, I2Cimport time, ustruct, binasciifrom time import sleep i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq = 400000) #Define the I2C pin and frequency # Print out any addresses founddevices = i2c.scan()if devices: for d in devices: print(hex(d)) # Attitude sensor address as_addr = 0x50 # Attitude sensor Regaddras_reg_addr = 0x1a # Set I2C addressas_reg_save = 0x00 # Save configurationas_reg_unlock = 0x69 # Unlock the module # Main# Send 0x88 and 0xb5 to unlock the moduledata2 = b'\x88\xB5'i2c.writeto_mem(as_addr, as_reg_unlock, data2)sleep(0.5) # Send 0x10 and 0x00 to change the address of the module to 0x10data3 = b'\x10\x00'i2c.writeto_mem(as_addr, as_reg_addr, data3)sleep(0.5) #Send 0x00 and 0x00 to save the configdata4 = b'\x00\x00'i2c.writeto_mem(as_addr, as_reg_save, data4)sleep(0.5)