简体   繁体   中英

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

This is pretty Adafruit CircuitPython specific, hence the one and only CircuitPython tag 😊

I'm playing around with a Metro Express M0 board and trying to get it to display on a Jansane 16x2 1602 LCD with CircuitPython. I'm trying to adapt these instructions . I know that the Metro is seeing the device, as for

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)

I get:

I2C addresses found: ['0x27']

which agrees with the default address for the LCD.

However, if I try:

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)

I get:

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

Is the I2C address hard coded into the library files in CircuitPython? Is there any way to set if for address 20?

Thanks in advance!

I looked here to find the definition of the class .

Based on line 71, it appears that you can set the address. If you want to use the address 0x27, use this line:

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

Also note that the https://github.com/adafruit/Adafruit_CircuitPython_CharLCD library supports MCP23008 backpacks. MCP23008 chips are used on Adafruit backpacks. Other backpacks are much more likely to be PCF8574 chips, which are not supported by that library. This library: https://github.com/dhalbert/CircuitPython_LCD supports PCF8574, but the API is different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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