I2C LCD Library... Help!

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
ken333nek
Posts: 3
Joined: Sat May 08, 2021 6:47 am

Re: I2C LCD Library... Help!

Post by ken333nek » Sat May 08, 2021 6:53 am

Hello,
I have some problem
(board:esp8266 v2 editor:Thonny)

I use
lcd_api.py,
esp8266_i2c_lcd.py
these two file

and run the below code:

Code: Select all

ssid = ' ' 
pw   = ' '  
i2c_addr = 0x27  
tz_hour  = 8     
# --------------------------------------------------
import network, ntptime, utime, gc
from machine import Pin, SoftI2C, Timer
from esp8266_i2c_lcd import I2cLcd
gc.enable()
led = Pin(2, Pin.OUT, value=1)
lcd = I2cLcd(SoftI2C(scl=Pin(5), sda=Pin(4)), i2c_addr, 2, 16)
wday  = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
def lcd_show(text, clear=True):
    if clear:
        lcd.clear()
    lcd.move_to(0, 0)
    lcd.putstr(text)
lcd_show('Connecting to\n  WiFi...')
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(ssid, pw)
while not wifi.isconnected():
    pass
def time_update(timer):
    while True:
        try:
            ntptime.settime()
            break
        except:
            utime.sleep(10)
def time_display(timer):
    led.value(not wifi.isconnected())
    dt = list(utime.localtime(utime.time() + tz_hour * 3600))
    dt[6] = wday[dt[6]]
    output = ' {0:4d}-{1:02d}-{2:02d} {6}\n   {3:02d}:{4:02d}:{5:02d}'
    lcd_show(output.format(*dt), clear=False)
    
time_update(None)
timer_ntp, timer_display = Timer(-1), Timer(-1)
timer_ntp.init(mode=Timer.PERIODIC, period=900000, callback=time_update)
timer_display.init(mode=Timer.PERIODIC, period=100, callback=time_display)
but when I run, editor will say

Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "esp8266_i2c_lcd.py", line 25, in __init__
OSError: [Errno 110] ETIMEDOUT

I don't know why

User avatar
Roberthh
Posts: 2691
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C LCD Library... Help!

Post by Roberthh » Sat May 08, 2021 9:24 am

Which line exactly is line 25. If I count your code starting from the first non-blank, it's a "while True".

ken333nek
Posts: 3
Joined: Sat May 08, 2021 6:47 am

Re: I2C LCD Library... Help!

Post by ken333nek » Sun May 09, 2021 2:48 am

This is 25 line

self.i2c.writeto(self.i2c_addr, bytearray([0]))

ken333nek
Posts: 3
Joined: Sat May 08, 2021 6:47 am

Re: I2C LCD Library... Help!

Post by ken333nek » Sun May 09, 2021 2:55 am

Hello,

File "esp8266_i2c_lcd.py", line 25, in __init__

it's means line 25 in esp8266_i2c_lcd.py or in my post code

if in my post code is while True

User avatar
Roberthh
Posts: 2691
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I2C LCD Library... Help!

Post by Roberthh » Sun May 09, 2021 9:21 am

It should be this line
self.i2c.writeto(self.i2c_addr, bytearray([0]))
which means that communication to the I2C fails. The most simple way to check that is calling:

from machine import SoftI2C
i2c = SoftI2C(scl=Pin(5), sda=Pin(4))
i2c.scan()

That should return a list of decimal addresses containing the address of the display. If the list is empty of has MANY entries, then the electrical connection to the display is wrong. If the list contains a different address, use that one.

Post Reply