1602 LCD and I2C backpack with pycom
-
@robert-hh How can i import a library? It's showing an import error
-
@Lucas_Vieira I do not know which environment you are using, but I just copy the files to the device, e.g. mylib.py and write:
import mylib
Preferring the basic style, I do not use any of the IDEs for Atom or VSC. -
-
@Lucas_Vieira You are trying the wrong module, since you have a display with i2c backpack. Please copy the files esp8266_i2c_lcd.py and lcd_api.py to you device. Then you can test it with the following code. which is more or less the content of the file esp8266_i2c_lcd_test.py. Do not get confused about the esp8266 prefix. For this application, both board behave similar. Connect the I2C with:
LoPy4 LCD ------------------------- GND GND Vin Vcc (assuming you need 5V for the display) P9 sda P10 scl"""Implements a HD44780 character LCD connected via PCF8574 on I2C. This was tested with: https://www.wemos.cc/product/d1-mini.html""" from time import sleep_ms, ticks_ms from machine import I2C, Pin from esp8266_i2c_lcd import I2cLcd # The PCF8574 has a jumper selectable address: 0x20 - 0x27 DEFAULT_I2C_ADDR = 0x27 def test_main(): """Test function for verifying basic functionality.""" print("Running test_main") i2c = I2C() lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) lcd.putstr("It Works!\nSecond Line") sleep_ms(3000) lcd.clear() count = 0 while True: lcd.move_to(0, 0) lcd.putstr("%7d" % (ticks_ms() // 1000)) sleep_ms(1000) count += 1 if count % 10 == 3: print("Turning backlight off") lcd.backlight_off() if count % 10 == 4: print("Turning backlight on") lcd.backlight_on() if count % 10 == 5: print("Turning display off") lcd.display_off() if count % 10 == 6: print("Turning display on") lcd.display_on() if count % 10 == 7: print("Turning display & backlight off") lcd.backlight_off() lcd.display_off() if count % 10 == 8: print("Turning display & backlight on") lcd.backlight_on() lcd.display_on() #if __name__ == "__main__": test_main() -
@robert-hh

Thank you for helping me to resolve this error import, but nothing is working in LCD.

LCD is just on. -
@Lucas_Vieira Reboot via the reset button to ensure, that main.py is executed. Did you also upload lcd_api.py?
-
@Lucas_Vieira with the LCD connected, try the following commands on the REPL command line:
from machine import I2C i2c=I2C() i2c.scan()It should return
[39]
if it returns a different number, you have to change the I2C address in the script. It it returns an empty list, try to swap sda and scl. -
-
@Lucas_Vieira Stay with the initial set of SCL and SDA, and set
DEFAULT_I2C_ADDR = 63
It is a PCF8574A, not PCF8574.
-
@robert-hh

No error, but nothing appears on the display. i'm making a mistake in hardware. even so, thank you man for helping me in this case, i'll try be better! -
@Lucas_Vieira Do you see the other print statements?
-
@Lucas_Vieira I'm missing the print statements form the script. So your test script is not executed at all.
-
This post is deleted!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
