Page 5 of 6

Re: LCD 1602 - Library

Posted: Sat Jun 15, 2019 12:30 pm
by RajaRamesh
RajaRamesh wrote:
Wed Jun 12, 2019 4:28 am
dhylands wrote:
Tue Jun 11, 2019 5:23 pm
I recorded a video here: https://www.youtube.com/watch?v=KiR-r8mXBCo
Thank you dhylands...i will try and get back to you if have any questions.
Hi dhylands, i am trying below code to display text with GpioLcd. but text was not displaying on lcd screen so i stopped going further. do i need to change the pins in below code or do i need to change slc and sda pins. currently i am running below code after connecting slc =Pin(5) sda=Pin(4) from i2c to esp8266.

i used lcd.clear() to clear the screen but it is not happening.

from machine import Pin
from nodemcu_gpio_lcd import GpioLcd
lcd = GpioLcd(rs_pin=Pin(16),enable_pin=Pin(5),d4_pin=Pin(4),d5_pin=Pin(0),d6_pin=Pin(2),d7_pin=Pin(14),num_lines=2, num_columns=16)
lcd.putstr("Hello")

Re: LCD 1602 - Library

Posted: Sat Jun 15, 2019 4:04 pm
by dhylands
You need to use the i2c version and just extract the code that does the scrolling. The GPIO version doesn't work with LCDs that have i2c backpacks.

Re: LCD 1602 - Library

Posted: Sat Jun 15, 2019 4:07 pm
by dhylands
In particular, this code:

Code: Select all

    msg = 'This is a scrolling test. '
    if (len(msg) < lcd.num_columns):
        msg += ' ' * (lcd.num_columns - len(msg))
    for i in range(len(msg)):
        len2 = min(lcd.num_columns, len(msg) - i)
        len1 = lcd.num_columns - len2
        msg2 = ''
        if len2 > 0:
            msg2 += msg[i:i+len2]
        if len1 > 0:
            msg2 += msg[0:len1]
        lcd.move_to(0, 0)
        lcd.putstr(msg2)
        delay(250)

Re: LCD 1602 - Library

Posted: Thu Jun 27, 2019 3:41 am
by vdb_peter
Hi Dave- 1st of all, thanks for your great work here- got it working on my 8266 & 1602 (with level shifter) without any problems at all.

Can you explain the syntax of putstr(), please? I'm tripping up on the syntax you use in your Test script: lcd.putstr("%7d" % (ticks_ms() // 1000)). Please explain the use of "%". If I substitute the "(ticks_ms() // 1000))" with a variable that holds a number, it prints, but I don't understand what the ""%7d" %" means. (And I couldn't sufficiently decipher lcd_api.py to work it out myself, sorry).

Thanks

Re: LCD 1602 - Library

Posted: Thu Jun 27, 2019 3:48 am
by mcauser
This one explains the string formatting: https://pyformat.info/

Code: Select all

lcd.putstr("%7d" % (ticks_ms() // 1000))
can also be written as:

Code: Select all

lcd.putstr("{:7d}".format(ticks_ms() // 1000))
%7d means convert the int to a left space padded string 7 characters wide.
ie.

Code: Select all

123 -> "    123"
12345 -> "  12345"

Re: LCD 1602 - Library

Posted: Thu Jun 27, 2019 5:06 am
by dhylands
Just a couple minor corrections:

That would be '{:7d}'.format(args) - Use a colon and not a percent with the 7d.

Code: Select all

>>> '{:7d}'.format(123)
'    123'
And '%7d' % 123 produces space padding on the left.

Code: Select all

>>> '%7d' % 123
'    123'

Re: LCD 1602 - Library

Posted: Thu Jun 27, 2019 5:43 am
by mcauser
Ooops, thanks Dave!

Re: LCD 1602 - Library

Posted: Mon Jul 01, 2019 7:57 am
by RajaRamesh
dhylands wrote:
Sat Jun 15, 2019 4:07 pm
In particular, this code:

Code: Select all

    msg = 'This is a scrolling test. '
    if (len(msg) < lcd.num_columns):
        msg += ' ' * (lcd.num_columns - len(msg))
    for i in range(len(msg)):
        len2 = min(lcd.num_columns, len(msg) - i)
        len1 = lcd.num_columns - len2
        msg2 = ''
        if len2 > 0:
            msg2 += msg[i:i+len2]
        if len1 > 0:
            msg2 += msg[0:len1]
        lcd.move_to(0, 0)
        lcd.putstr(msg2)
        delay(250)
Hi Dave, i have updated i2c version with above code with small correction in for loop. i am getting error when for loop is outside of if statement.so i have mentioned the for loop inside if statement and the text is scrolling on LCD screen in 1st row. i have updated lcd.putstr as lcd.putstr(msg2\nmsg2) to scroll the text on 1st and 2nd row. but it was not working. do we need to have an if statement on lcd.row_num to scroll on 2nd row?

Re: LCD 1602 - Library

Posted: Sat Nov 30, 2019 7:37 pm
by vitalis
I just got my I2C 20x4 LCD working with esp32. I've used level shifter to adjust 3.3v and 5 v between devices.
A question: is it doable to redirect Micropython REPL to 20x4 LCD?

Re: LCD 1602 - Library

Posted: Sat Nov 30, 2019 9:17 pm
by Christian Walther
Apparently yes, see viewtopic.php?t=7083&p=40307