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)
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