Controlling a HD44780 LCD on a BeagleBone (Part 1)

Hitachi HD44780 compatible LCD screens are those common displays we see all over the place. Getting them to display some information is fairly easy, as all you have to do is send the appropriate bits to each of the LCD screen inputs.

Basic 16x2 Character LCD - HD44780 compatible

In this post I will describe the steps I took to integrate a Hitachi HD44780 LCD with the BeagleBone board. First of all you need a LCD display. From my Arduino days, I had a couple of them laying around my lab. In this tutorial, I used a fairly inexpensive Microtivity LCD Module 1602. Because this LCD module requires a 5V source, and the BeagleBone GPIO pins only provide 3.3V, you need to get power from other sources: either connect a 5V DC adaptor to the BeagleBone and use P9_5 which provides +5V, or use any adapter that you have in your house to deliver the appropriate voltage with a voltage regulator. If you opt for the voltage regulator route, I recommend you get a 9V adaptor and use this neat sparkfun kit, just make sure the ground of this external voltage supply is connected to the ground pin of the BeagleBone. Of course you can bypass all these problems, by getting a +3.3V LCD display, but they will be more expensive.

BeagleBone and a HD44780 compatible LCD

Once you have acquired the LCD and connected to an appropriate power source, use the following connections.

LCD Pin # LCD Pin Description LCD Pin Connects to
1 VSS Ground
2 VDD +5V
3 VO Attach a potentiometer here to adjust contrast
4 Register Select (RS) BeagleBone pin P8_4
5 Read/Write (R/W) Ground
6 Clock Enable (E) BeagleBone pin P8_3
7 Data Bit 0 Unconnected
8 Data Bit 1 Unconnected
9 Data Bit 2 Unconnected
10 Data Bit 3 Unconnected
11 Data Bit 4 BeagleBone pin P8_5
12 Data Bit 5 BeagleBone pin P8_11
13 Data Bit 6 BeagleBone pin P8_12
14 Data Bit 7 BeagleBone pin P8_14
15 Backlight Anode (+) +5V (or lower)
16 Backlight Cathode (-) Ground

Source-Code
The code below will prompt you to enter a bitstream into the LCD screen. Keep in mind that you need the library beagle_gpio.h, or else the program will not compile. You can find all the necessary files to run the program in the following github site (https://github.com/nunoalves/BeagleBone-HD44780). You can compile, and run, this code by typing the following commands in the BeagleBone terminal:

gcc -c beagle_gpio.c
gcc beagle_gpio.o example_01.c
./a.out
rm -f a.out

Once the code is compiled you will be asked to type the appropriate bitstream. If you type the following bits, you will type the word “hi” on the LCD.

Type the following bitstream to display "hi" in the LCD

If you would like to manually type different characters look at the following table:

HD44780 LCD character table

… And here is a screen shot of the program output.

Screenshot of the program manually sending a bitstream to the HD44780.

Finally, if you would like to know more about controlling these LCD devices I suggest this website, and the article “How to use intelligent L.C.D.s – Part One” by Julyan llett, which can be found here.

In a future post, I will release another library that will allow us to automatically display text without manually typing the entire bitstream.

Addressing multiple BeagleBone GPIO pins in C

Since I am in the process of writing a HD44780 compatible LCD display driver for the beagle bone, I need to have a very simple piece of C code that writes data to multiple GPIO pins at the same time. In particular I need to have a function that when given a binary value, will turn ON/OFF may GPIO pins. For example, lets say the end-user is using the following 5 GPIO pins, P8_3, P8_4, P8_5, P8_11 and P8_12. Now lets say he just wants to turn ON pins P8_4 and P8_11, while leaving the others OFF. I created a neat piece of code that takes the pin selection in a binary format, and performs the appropriate ON/OFF switching operations. The latest version of this code can be found at the following github repository, https://github.com/nunoalves/BeagleBone-GPIO-in-C.

While this code works quite well, it is not really complete. For starters, I haven’t included all BeagleBone GPIO pins. You can include them all yourself in the function initialize_each_enabled_gpio(). Please refer to this earlier blog post for hints about how to do it. I also haven’t split this code into a different header file, so it’s its own library. I will do so, after I release the drivers for the HD44780 LCD display. Finally, this code could need some cleaning and optimization…

Here is a screenshot of the program running in the BeagleBone.

To compile and run this code just type the following commands in the BeagleBone terminal.

gcc main.c
./a.out

Finally, for those of you that are Doxygen fans, here is a printout of the code documentation.