簡體   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