LCD 1602 - Library

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
mcauser
Posts: 404
Joined: Mon Jun 15, 2015 8:03 am

Re: LCD 1602 - Library

Post by mcauser » Sun Jun 09, 2019 8:08 pm

There are two versions of this device - the difference is the controller IC. If you have the PCF8574T. the default I2C bus address is 0x27. If you have the PCF8574AT the default I2C bus address is 0x3F. An i2c.scan() should reveal which address to use

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Mon Jun 10, 2019 5:44 am

Roberthh wrote:
Sun Jun 09, 2019 6:03 pm
What do you get with

Code: Select all

from machine import I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
print(i2c.scan())
Hi Robert, i got [39] as per below screenshot
Capture.PNG
Capture.PNG (243.67 KiB) Viewed 427 times

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

Re: LCD 1602 - Library

Post by Roberthh » Mon Jun 10, 2019 5:53 am

The instantiation of lcd should be:

lcd=I2cLcd(i2c, 0x27, 2, 16)

or

lcd=I2cLcd(i2c, 39, 2, 16)

You screen dump shows 0*27, which is 0

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Mon Jun 10, 2019 11:46 am

Roberthh wrote:
Mon Jun 10, 2019 5:53 am
The instantiation of lcd should be:

lcd=I2cLcd(i2c, 0x27, 2, 16)

or

lcd=I2cLcd(i2c, 39, 2, 16)

You screen dump shows 0*27, which is 0
Thank you Robert. i will check and get back to you.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Mon Jun 10, 2019 5:43 pm

RajaRamesh wrote:
Mon Jun 10, 2019 11:46 am
Roberthh wrote:
Mon Jun 10, 2019 5:53 am
The instantiation of lcd should be:

lcd=I2cLcd(i2c, 39, 2, 16)
Thank you Robert. i will check and get back to you.
hi robert... now i can see text on lcd after updating with 39. is it possible to scroll the text on lcd from right to left or left to right?

User avatar
dhylands
Posts: 3228
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LCD 1602 - Library

Post by dhylands » Mon Jun 10, 2019 5:58 pm

The LCD displays are quite primitive. Here's a couple of references to the commands that can be sent to the LCD:
http://web.alfredstate.edu/faculty/weimandn/index.html
https://dawes.wordpress.com/2010/01/05/ ... ction-set/

The typical way to achieve scrolling is to write new text which is scrolled. i. Send "This is a test t" the first time and then after a delay, send "his is a test to" to scroll 1 character left (positioning the cursor before sending each string).

The display is capable of doing some hardware scrolling, but as you can see on this page: http://web.alfredstate.edu/faculty/weim ... index.html the memory arrangement isn't all that straight forward.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Tue Jun 11, 2019 3:40 pm

dhylands wrote:
Mon Jun 10, 2019 5:58 pm
The LCD displays are quite primitive. Here's a couple of references to the commands that can be sent to the LCD:
http://web.alfredstate.edu/faculty/weimandn/index.html
https://dawes.wordpress.com/2010/01/05/ ... ction-set/

The typical way to achieve scrolling is to write new text which is scrolled. i. Send "This is a test t" the first time and then after a delay, send "his is a test to" to scroll 1 character left (positioning the cursor before sending each string).

The display is capable of doing some hardware scrolling, but as you can see on this page: http://web.alfredstate.edu/faculty/weim ... index.html the memory arrangement isn't all that straight forward.
Hi dhylands.....thank you for sharing the links. i gone through those links and i am not able to get the code to scroll the text. it will be more helpful if i get some code to scroll the text on LCD.

User avatar
dhylands
Posts: 3228
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LCD 1602 - Library

Post by dhylands » Tue Jun 11, 2019 5:23 pm

Here's an example which scrolls text (using the GPIO version).

Code: Select all

def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    lcd = GpioLcd(rs_pin=Pin.cpu.C6,
                  enable_pin=Pin.cpu.C8,
                  d4_pin=Pin.cpu.C2,
                  d5_pin=Pin.cpu.C3,
                  d6_pin=Pin.cpu.C4,
                  d7_pin=Pin.cpu.C5,
                  num_lines=2, num_columns=16)
    lcd.putstr("It Works!\nSecond Line\nThird Line\nFourth Line")
    delay(3000)
    lcd.clear()
    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)
    delay(1000)
    lcd.clear()
    count = 0
    while True:
        lcd.move_to(0, 0)
        lcd.putstr("%7d" % (millis() // 1000))
        delay(1000)
        count += 1
I recorded a video here: https://www.youtube.com/watch?v=KiR-r8mXBCo

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » 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.

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Sat Jun 15, 2019 6:38 am

dhylands wrote:
Tue Jun 11, 2019 5:23 pm
Here's an example which scrolls text (using the GPIO version).

Code: Select all

def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    lcd = GpioLcd(rs_pin=Pin.cpu.C6,
                  enable_pin=Pin.cpu.C8,
                  d4_pin=Pin.cpu.C2,
                  d5_pin=Pin.cpu.C3,
                  d6_pin=Pin.cpu.C4,
                  d7_pin=Pin.cpu.C5,
                  num_lines=2, num_columns=16)
    lcd.putstr("It Works!\nSecond Line\nThird Line\nFourth Line")
[/quote]
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")

Post Reply