pi2hd44780

 USING INEXPENSIVE HD44780 BASED LCD DISPLAYS WITH THE PI

I've accumulated quite a pile of displays from discarded laser printers. (If you don't have one of these displays you can easily find them for around two dollars new including shipping to the US). So, it's time for a project!

Since I hate wiring things up I designed and had made a small circuit board to allow the display to be plugged directly into the Pi. (The design files are in this project's files section, or you can order directly from OSH Park.) All you need besides the board is a 10-pin header socket, and perhaps a small surface mount 10K trimmer to adjust contrast. My displays didn't need it. Solder it up like the following pictures:

(TBD)

THE SOFTWARE

There's plenty of code for driving the display from Python. However, the latest Raspbian includes the HD44780 kernel module, so I decided to use it. Here's how:

Add the following two lines to /boot/config.txt. They need to be one right after the other in the shown order:

    dtoverlay=hd44780-lcd,pin_d4=18,pin_d5=23,pin_d6=24,pin_d7=25

    dtparam=pin_rs=14,pin_en=15,display_width=8,display_height=2

Reboot, and the driver creates the /dev/lcd character device. You use control characters to control the display, kind of like the Linux terminal.

These displays are a little bit weird - even though they're 16x1 they are set up and controlled as if they were 8x2 displays. This lets a single HD44780 chip control them without using an expansion chip. The rightmost 8 characters of the display are written to as if they were the first 8 characters on line 2. Said another way, characters 1-8 are on line 1, characters 9-16 are on line 2.

Here are some command examples:

Clear the display and set the cursor to the first character in the first line:

    echo -n -e "\e[2J" > /dev/lcd

Set the cursor to the first character in the first line, but don't clear the display:

    echo -n -e "\e[H" > /dev/lcd

Here's what I did to put PC LOAD LETTER on my display (extra credit if you get the movie reference!) Notice the \n in the middle to jump to the second line in the display memory:

    echo -n -e "\e[2JPC LOAD\nLETTER" > /dev/lcd

If you include a "\n" in your echo command the rest of that line is cleared and the cursor is set to the next line on the display. So echo -n -e "\e[H\n\n" and echo -n -e "\e[2J" do the same thing. Also note that writing a "\n" after the last line sets the cursor to the first character in the first line.

How about something more useful? Put the following in /etc/rc.local directly after the line that says if [ "$_IP" ]; then:

    

    sudo chmod 766 /dev/lcd

    echo -n -e “\e[2J” > /dev/lcd

    echo $(echo $_IP | cut -c 1-8) > /dev/lcd

    echo $(echo $_IP | cut -c 9-15) > /dev/lcd

REFERENCES

HD44780 wikipedia entry

HD44780 Datasheet