Page 6 of 6

Re: I2C LCD Library... Help!

Posted: Sat May 08, 2021 6:53 am
by ken333nek
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

Re: I2C LCD Library... Help!

Posted: Sat May 08, 2021 9:24 am
by Roberthh
Which line exactly is line 25. If I count your code starting from the first non-blank, it's a "while True".

Re: I2C LCD Library... Help!

Posted: Sun May 09, 2021 2:48 am
by ken333nek
This is 25 line

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

Re: I2C LCD Library... Help!

Posted: Sun May 09, 2021 2:55 am
by ken333nek
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

Re: I2C LCD Library... Help!

Posted: Sun May 09, 2021 9:21 am
by Roberthh
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.

Re: I2C LCD Library... Help!

Posted: Sat Jul 16, 2022 5:17 am
by modulusmath
Such an interesting thread :). I am using a NodeMcu esp8266 with a LCD Display - no real marking on the backpack that I can see - I squinted...

I've tried all sort of different combos to see where I can be doing something wrong but the best I can do is make the LDC blink...

(FWIW I setup a blue/yellow 128x64 Pixel SSD1306 I2C lcd and it works great!).

I believe I have the jumpers set OK. I have power to the LCD, it is very bright and the white light on the side is on.

Code: Select all

from  machine import Pin,I2C
from esp8266_i2c_lcd import I2cLcd

i2c=I2C(sda=Pin(4), scl=Pin(5), freq=10000)   

devices=i2c.scan()
if len(devices) == 0:
 print("No i2c device !")
else:
 print('i2c devices found:',len(devices))
for device in devices:
    print("At address: ",hex(device))

lcd = I2cLcd(i2c, 0x3f, 2, 16)
lcd.putstr("Hello")

i2c devices found: 1
At address:  0x3f

##just blinks at the end ...

############################

I also tried using nodemcu_gpio_lcd.py a bit b/c the doc said it's for a nodemcu, but I'm not really sure I know how to use it properly.

Any thoughts here are helpful. Thanks

Re: I2C LCD Library... Help!

Posted: Sat Jul 16, 2022 6:01 am
by Roberthh
LCDs typically run at 5V. Do you run them at 5V, and do you have the contrast set?

Re: I2C LCD Library... Help!

Posted: Sat Jul 16, 2022 3:52 pm
by modulusmath
Roberthh wrote:
Sat Jul 16, 2022 6:01 am
LCDs typically run at 5V. Do you run them at 5V, and do you have the contrast set?
Right. Thanks Robert. I should have mentioned.

The Nodemcu is plugged into my USB, supplying 5V, and the Nodemcu is connected to LCD's VCC via it's VIN pin.

My understanding is the pin marked as VIN provides 5V as per my googling (I am very much still learning). So it's seems ok from that perspective.

Also, I did not explicitly turn on contrast. I googled for a bit but could not find out how to do that :)