Basic LCD driver class (HD44780)

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
wjdp
Posts: 5
Joined: Thu Oct 09, 2014 2:46 pm

Basic LCD driver class (HD44780)

Post by wjdp » Wed Oct 22, 2014 6:39 pm

I've put together a very simple class to get a 4-bit LCD up and running quickly. Code based on this RPi version http://www.raspberrypi-spy.co.uk/2012/0 ... ng-python/.

Usage

Code: Select all

    lcd = HD44780()

    # Pins 0-5 as above
    lcd.PINS = ['Y1','Y2','Y3','Y4','Y5','Y6']

    # Initialise display
    lcd.init()

    # Use it
    lcd.set_line(0) # First line
    lcd.set_string("ABCDEFGHIJKLMNOP") # Send a string
    lcd.set_line(1) # Second line
    lcd.set_string("1234567890123456") # Again

    pyb.delay(3000) # 3 second delay

    # Done
    lcd.clear()
https://github.com/wjdp/micropython-lcd

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

Re: Basic LCD driver class (HD44780)

Post by dhylands » Wed Oct 22, 2014 9:11 pm

I also have some code over here: https://github.com/dhylands/python_lcd/tree/master/lcd

It supports 4-bit and 8-bit, as well as some of the I2C based LCD backpacks.

The lcd.py is the generic code.

The pyb_gpio_lcd.py and pyb_i2c_lcd.py create classes derived from LcdApi that takes care of actually talking to the LCD (over GPIO or I2C)

The i2c_lcd.py code also derives from LcdApi, but its designed for the BeagleBoneBlack, using the user-space i2c driver.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Basic LCD driver class (HD44780)

Post by nikhiledutech » Fri Dec 29, 2017 7:17 am

Hey,
I am using STM32F407disc board to interface with LCD. I have initalised the rs,en,rw d0-d7 pins correctly still nothing get written on LCD.

I have given code below.

CODE:
from pyb import Pin, delay, millis
from pyb_gpio_lcd import GpioLcd


#PIN configuration
rs = pyb.Pin('PB1',Pin.OUT_PP,Pin.PULL_UP)
rw = pyb.Pin('PB4', Pin.OUT_PP,Pin.PULL_UP)
en = pyb.Pin('PB5', Pin.OUT_PP,Pin.PULL_UP)
d0 = pyb.Pin('PE8', Pin.OUT_PP,Pin.PULL_DOWN)
d1 = pyb.Pin('PE9', Pin.OUT_PP,Pin.PULL_DOWN)
d2 = pyb.Pin('PE10', Pin.OUT_PP,Pin.PULL_DOWN)
d3 = pyb.Pin('PE11', Pin.OUT_PP,Pin.PULL_DOWN)
d4 = pyb.Pin('PE12', Pin.OUT_PP,Pin.PULL_DOWN)
d5 = pyb.Pin('PE13', Pin.OUT_PP,Pin.PULL_DOWN)
d6 = pyb.Pin('PE14', Pin.OUT_PP,Pin.PULL_DOWN)
d7 = pyb.Pin('PE15', Pin.OUT_PP,Pin.PULL_DOWN)

def test_main():
"""Test function for verifying basic functionality."""
print("Running test_main")
lcd = GpioLcd(rs,en,d0,d1,d2,d3,d4,d5,d6,d7,2,16)
lcd.putstr("It Works!\nSecond Line)
delay(3000)
lcd.clear()

This should print It works and Second Line but nothing gets printed on LCD display. So please help me in this. And guide me, if i have to make any changes in my code.

Thank you. :)

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

Re: Basic LCD driver class (HD44780)

Post by dhylands » Fri Dec 29, 2017 3:12 pm

How is your contrast pin (pin 3 on the LCD modules) connected?

Do you see a row of black squares when you power on the LCD? If you don't see the row of black squares, then you need to adjust the contrast voltage until you do. Otherwise, even if everything is working perfectly, you won't see anything on the screen.

nikhiledutech
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: Basic LCD driver class (HD44780)

Post by nikhiledutech » Mon Jan 01, 2018 4:36 am

When i powered on the LCD it shows black square are displayed on the LCD. After i initialize the LCD, the black boxes get disappeared.

Post Reply