Help wanted with hitachi HD44780

Hi all,

I have connected my Raspberry Pi to my Arduino Uno by USB. I am trying to control a LCD display (LCM1602C V2.1) using a Python script from the Raspberry. I'm using a library called Nanpy to control the pins on the Arduino. Which I first tried with a simple led set up and worked just fine.

I am now trying to control the LCD with the same library but whatever I do, nothing seems to work. I've found the datasheet belonging to the hitachi HD44780 and I think I am doing the right things in the right order but the LCD keeps displaying white boxes. When I run the example code from the arduino IDE (LiquidCrystal - Blink) it works just fine. The following code is supposed to initialize the LCD and display a single 'h'.

from nanpy import ArduinoApi
from nanpy import SerialManager
import time

rs = 12
en = 11
d4 = 5
d5 = 4
d6 = 3
d7 = 2


def en_toggle():
    a.digitalWrite(en, a.HIGH)
    time.sleep(0.02)
    a.digitalWrite(en, a.LOW)
    time.sleep(0.02)


def lcd_init():
    time.sleep(0.02)
    a.digitalWrite(rs, a.LOW)

    # 0000
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0011
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.HIGH)
    en_toggle()
    time.sleep(0.02)

    # 0000
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0011
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.HIGH)
    en_toggle()
    time.sleep(0.02)

    # 0000
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0011
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.HIGH)
    en_toggle()
    time.sleep(0.02)

    # 0010
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0010
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 1000
    a.digitalWrite(d7, a.HIGH)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0000
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 1111
    a.digitalWrite(d7, a.HIGH)
    a.digitalWrite(d6, a.HIGH)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.HIGH)
    en_toggle()
    time.sleep(0.02)

    # 0000
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # 0110
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.HIGH)
    a.digitalWrite(d5, a.HIGH)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # RS 1 0100
    a.digitalWrite(rs, a.HIGH)
    a.digitalWrite(d7, a.LOW)
    a.digitalWrite(d6, a.HIGH)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)

    # RS 1 1000
    a.digitalWrite(rs, a.HIGH)
    a.digitalWrite(d7, a.HIGH)
    a.digitalWrite(d6, a.LOW)
    a.digitalWrite(d5, a.LOW)
    a.digitalWrite(d4, a.LOW)
    en_toggle()
    time.sleep(0.02)


connection = SerialManager(device='/dev/ttyACM0')
a = ArduinoApi(connection)

lcd_init()
time.sleep(2)

I would love some help!

Used the following tutorials/documentation tutorial

I would love some help!

Have you tried a Google search for "LCD Programming Examples" ? One of the early hits should take you here.

Similarly a search for "LCD Initialization" should take you here (at the same site).

An ancient version of the information in the tutorial you mentioned can be found here.

Don

Hey Don, thanks. I totally forgot to set all of the pins to OUTPUT mode before starting the lcd_init() method. The examples you mentioned reminded me of the fact that it's a mandatory thing to do. The code I wrote worked straight away. :sweat_smile: