树莓派Pico I2C问题求教!
-
- 帖子: 1
- 注册时间: 2022年 3月 2日 19:50
树莓派Pico I2C问题求教!
用树莓派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)
- shaoziyang
- 帖子: 3954
- 注册时间: 2019年 10月 21日 13:48
-
- 帖子: 35
- 注册时间: 2022年 2月 20日 04:42
Re: 树莓派Pico I2C问题求教!
我来排版
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)
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)
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 1回复总数
- 1294 阅读次数
- 最新文章 由 shaoziyang
2021年 12月 2日 08:21
-
- 1回复总数
- 822 阅读次数
- 最新文章 由 shaoziyang
2021年 12月 2日 08:36
-
- 1回复总数
- 747 阅读次数
- 最新文章 由 shaoziyang
2021年 12月 2日 10:38