Raspberry Pi LCD (HD44780) control

For a future more ambitious project, I tried to connect an LCD screen to a Raspberry Pi. My first guess was to connect the LCD directly to the Raspberry Pi GPIOs.


To control the LCD screen, I used the wiringPi library which has a HD44780 LCD driver. The use of this library is really simple as you can see in the code below. I used 4 bit communication so only 6 GPIOs are necessary: 4 data bits + E + RS.

#include <lcd.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv) {
	if (argc < 2) {
		printf("usage: %s <message>", argv[0]);
		return 1;
	// Init
	int dev = lcdInit(2, 16, 4, 
	                  11 /*RS*/, 12 /* E */,
	                  15, 16, 18, 22, 0, 0, 0, 0);


	int i;
	for (i = 1; i < argc; i++) {
		lcdPuts(dev, argv[i]);
		lcdPutchar(dev, ' ');

	return 0;

And the Makefile :

all: lcd

lcd: main.c
	gcc -o lcd main.c -lwiringPi -lwiringPiDev

Once compiled (directly on the RPi) you can use the command “./lcd …” to display some text.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.