分页: 1 / 1

树莓派Pico I2C问题求教!

发表于 : 2022年 3月 2日 19:53
Strathclyde_yang
用树莓派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)

Re: 树莓派Pico I2C问题求教!

发表于 : 2022年 3月 2日 21:10
shaoziyang
关于i2c的16位方式用法,可以参考社区的驱动

https://github.com/micropython-Chinese- ... /I2C_16bit

Re: 树莓派Pico I2C问题求教!

发表于 : 2022年 4月 8日 19:59
taobaowang
我来排版
from machine import Pin, I2C
import 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 module
data2 = 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 0x10
data3 = b'\x10\x00'i2c.writeto_mem(as_addr, as_reg_addr, data3)
sleep(0.5) 
#Send 0x00 and 0x00 to save the config
data4 = b'\x00\x00'i2c.writeto_mem(as_addr, as_reg_save, data4)sleep(0.5)