繁体   English   中英

我可以在 CircuitPython 中将 i2c LCD 的地址设置为 20 以外的地址吗?

[英]Can I set the address of an i2c LCD in CircuitPython for something other than 20?

这是非常特定于 Adafruit CircuitPython 的,因此是唯一的 CircuitPython 标签😊

我正在玩 Metro Express M0 板,并试图让它在带有 CircuitPython 的Jansane 16x2 1602 LCD上显示。 我正在尝试调整这些说明 我知道 Metro 正在查看该设备,至于

import board
import busio

i2c = busio.I2C(board.SCL, board.SDA)

while not i2c.try_lock():
    pass

while True:
    print("I2C addresses found:", [hex(device_address)
                                   for device_address in i2c.scan()])
    time.sleep(2)

我得到:

I2C addresses found: ['0x27']

这与 LCD 的默认地址一致。

但是,如果我尝试:

import adafruit_character_lcd.character_lcd_i2c as character_lcd

i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)

我得到:

...
File "adafruit_bus_device/i2c_device.py", line 171, in __probe_for_device
ValueError: No I2C device at address: 20

I2C 地址是否硬编码到 CircuitPython 中的库文件中? 有什么方法可以设置地址 20 的 if 吗?

提前致谢!

在这里寻找类的定义

根据第 71 行,您似乎可以设置地址。 如果要使用地址 0x27,请使用以下行:

lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2, address=0x27)

另请注意, https://github.com/adafruit/Adafruit_CircuitPython_CharLCD库支持 MCP23008 背包。 MCP23008 芯片用于 Adafruit 背包。 其他背包更有可能是该库不支持的 PCF8574 芯片。 这个库: https ://github.com/dhalbert/CircuitPython_LCD 支持 PCF8574,但是 API 不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM