Project showcase

How to Use a HD44780 Based Display © CERN-OHL

Some projects and guides for HD44780 based LCD displays.

  • 431 views
  • 2 comments
  • 1 respect

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

About this project

Introduction

About two weeks ago, I bought a 16x2 LCD display in a local electronics fair for about 2€. In the price tag was written "Arduino display", in fact, on the circuit board there are a HD44780 IC, that works perfectly with Arduino. After soldering the connection pins to the LCD, I have found a library for this module on Github. The library was created by "duinoWitchery" and is on his Github page at this link.

Connections and other

The connections are easy, and easy to find; in fact the instructions for the connection are write in the example code of the library:

//  1 - LCD gnd
//  2 - VCC (5v)
//  3 - Vo Contrast Voltage 
//  4 - RS Register Select (rs)
//  5 - Read/Write
//  6 - Enable (en)
//  7 - Data 0 (db0) ----
//  8 - Data 1 (db1)     |-------- Not used in 4 bit mode
//  9 - Data 2 (db2)     |
// 10 - Data 3 (db3) ----
// 11 - Data 4 (db4)
// 12 - Data 5 (db5)
// 13 - Data 6 (db6)
// 14 - Data 7 (db7)
// 15 - Backlight Anode (+5v)
// 16 - Backlight Cathode (Gnd)

If you don't want to use a potentiometer to control the contrast, connect the pin 3 to the GND.

First tests

After installing it, I've looked to the examples to find one that works as a Hello World for my LCD. And I have found it in Examples> ioClass> HD44780_pinIO> Hello World. The library is like the LiquidCrystal.h library. This is the Hello World code:

// vi:ts=4
// ----------------------------------------------------------------------------
// HelloWorld - simple demonstration of lcd
// Created by Bill Perry 2016-07-02
// bperrybap@opensource.billsworld.billandterrie.com
//
// This example code is unlicensed and is released into the public domain
// ----------------------------------------------------------------------------
// 
// This sketch is for LCDs that are directly controlled with Arduino pins.
//
// Sketch prints "Hello, World!" on the lcd
//
// See below for configuring the Arduino pins used.
//
// While not all hd44780 use the same pinout, here is the one that most use:
// pin 1 is the pin closest to the edge of the PCB
//  1 - LCD gnd
//  2 - VCC (5v)
//  3 - Vo Contrast Voltage
//  4 - RS Register Select (rs)
//  5 - Read/Write
//  6 - Enable (en)
//  7 - Data 0 (db0) ----
//  8 - Data 1 (db1)     |-------- Not used in 4 bit mode
//  9 - Data 2 (db2)     |
// 10 - Data 3 (db3) ----
// 11 - Data 4 (db4)
// 12 - Data 5 (db5)
// 13 - Data 6 (db6)
// 14 - Data 7 (db7)
// 15 - Backlight Anode (+5v)
// 16 - Backlight Cathode (Gnd)
//
// ----------------------------------------------------------------------------
// LiquidCrystal compability:
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
// sketches should work with hd44780 hd44780_pinIO i/o class once the
// includes are changed to use hd44780 and the lcd object constructor is
// changed to use the hd44780_pinIO class.
#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header
// declare Arduino pins used for LCD functions
// and the lcd object
// Note: this can be with or without backlight control:
// without backlight control:
// The parameters used by hd44780_pinIO are the same as those used by
// the IDE bundled LiquidCrystal library
// note that ESP8266 based arduinos must use the Dn defines rather than
// raw pin numbers.
#if defined (ARDUINO_ARCH_ESP8266)
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
#else
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // for all other devices
#endif
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);
//with backlight control:
//	backlight control requires two additional parameters
//	- an additional pin to control the backlight
//	- backlight active level which tells the library the level
//		needed to turn on the backlight.
//		note: If the backlight control pin supports PWM, dimming can be done
//			using setBacklight(dimvalue);
//
//	WARNING: some lcd keypads have a broken backlight circuit
//		If you have a lcd keypad, it is recommended that you first run the
//		LCDKeypadCheck sketch to verify that the backlight circuitry
//		is ok before enabling backlight control.
//		However, the hd44780_PinIO class will autodetect the issue and
//		work around it in s/w. If the backlight circuitry is broken,
//		dimming will not be possible even if the backlight pin supports PWM.
//
#if defined (ARDUINO_ARCH_ESP8266)
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
#else
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
#endif
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLEvel);
// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
	// initialize LCD with number of columns and rows: 
	//
	// note:
	//	begin() will automatically turn on the backlight if backlight
	// 	control is specified in the lcd object constructor
	//
	lcd.begin(LCD_COLS, LCD_ROWS);
	// if backlight control was specified, the backlight should be on now
	// Print a message to the LCD
	lcd.print("Hello, World!");
}
void loop() {}

This code contains o lot of comments, that are very usefull. To declare pin connection you have to comment or uncomment the pins's settings. In my case I have commented the pin settings for the LCDs that have a backlight, beacuse my LCD haven't backlight. For all the other parameters, they're the same to use with the classic LCD library.

Project 1: write text on the LCD using the serial port

The project is super easy. With this code you can write text on the LCD using the serial port. You only have to connect the LCD to Arduino (see the first paragraph), and Arduino to a computer. Upload the code and this is the result:

I don't know that is the character at end of the text, I think that is a NL character (?).

Project 2: Little weather station

This time I have used a DHT11 temperature and humidity sensor to create a little weather station for my bedroom. Also this time the code is very easy and I have written it in about 10 mins. This is the connection scheme:

And this is the result:

The labels for temperature and humidity are in Italian, im sorry. But I live in Italy and mi piace l'italiano!

I love 3D printing!

Since I love my Anet A8, I have designed this simple support or frame, for the display. If you want to 3D print them, the files are at the bottom of the page :)

Conclusions

Good, we are at the end of the "tutorial". I hope you liked it :D. If there are some errors (or grammar errors, I don't have used Google Translate), or you have doubts, write all in the comments and i'll reply you.

Code

Serial CommunicationC/C++
// Francesco Mattiussi 2018
// www.francescomattiussi.tk & www.francescomattiussi.blogspot.com
//
// Comments in Italian
//
//Il pinout degli schermi con il HD44780
//
//  1 - LCD gnd
//  2 - VCC (5v)
//  3 - Vo Contrast Voltage
//  4 - RS Register Select (rs)
//  5 - Read/Write
//  6 - Enable (en)
//  7 - Data 0 (db0) ----
//  8 - Data 1 (db1)     |-------- Non usati nella modalit in 4 bit
//  9 - Data 2 (db2)     |
// 10 - Data 3 (db3) ----
// 11 - Data 4 (db4)
// 12 - Data 5 (db5)
// 13 - Data 6 (db6)
// 14 - Data 7 (db7)
// 15 - Backlight Anode (+5v)
// 16 - Backlight Cathode (Gnd)
//

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> 

String inputString = "";         // stringa per accumulare i dati
boolean stringComplete = false;  // flag per l' avvenuto completamento

// commentare il dispositivo non utilizzato (nel mio caso un l' ESP8266)
#if defined (ARDUINO_ARCH_ESP8266)
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // per dispositivi esp8266
#else
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // tutti gli altri dispositivi
#endif
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// geometria dell LCD
const int LCD_COLS = 16; // colonne dello schermo
const int LCD_ROWS = 2; // righe dello schermo

void setup(){

	lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo
 
  Serial.begin(9600); //inizializza la seriale a 9600 baud per il debug
  
  inputString.reserve(200); //riserva 200 byte per la stringa
}

void loop() {
  
  if (stringComplete) {
    lcd.clear(); //pulisce lo schermo
    
    Serial.println(inputString); //stampa la stringa sul seriale
    lcd.print(inputString); //stampa la stringa sullo schermo
    
    inputString = ""; //Pulisce la stringa
    stringComplete = false; //la stringa non  pi completa

  }

 }

 void serialEvent() {
  
  while (Serial.available()) {
    
    char inChar = (char)Serial.read(); //riceve il nuovo byte
    
    inputString += inChar; //lo agggiunge alla stringa
   
    
    if (inChar == '\n') { //se il nuovo carattere  un newline
      stringComplete = true; //la stringa  completa
    }
  }
}
Hello WorldC/C++
// vi:ts=4
// ----------------------------------------------------------------------------
// HelloWorld - simple demonstration of lcd
// Created by Bill Perry 2016-07-02
// bperrybap@opensource.billsworld.billandterrie.com
//
// This example code is unlicensed and is released into the public domain
// ----------------------------------------------------------------------------
// 
// This sketch is for LCDs that are directly controlled with Arduino pins.
//
// Sketch prints "Hello, World!" on the lcd
//
// See below for configuring the Arduino pins used.
//
// While not all hd44780 use the same pinout, here is the one that most use:
// pin 1 is the pin closest to the edge of the PCB
//  1 - LCD gnd
//  2 - VCC (5v)
//  3 - Vo Contrast Voltage
//  4 - RS Register Select (rs)
//  5 - Read/Write
//  6 - Enable (en)
//  7 - Data 0 (db0) ----
//  8 - Data 1 (db1)     |-------- Not used in 4 bit mode
//  9 - Data 2 (db2)     |
// 10 - Data 3 (db3) ----
// 11 - Data 4 (db4)
// 12 - Data 5 (db5)
// 13 - Data 6 (db6)
// 14 - Data 7 (db7)
// 15 - Backlight Anode (+5v)
// 16 - Backlight Cathode (Gnd)
//
// ----------------------------------------------------------------------------
// LiquidCrystal compability:
// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal
// sketches should work with hd44780 hd44780_pinIO i/o class once the
// includes are changed to use hd44780 and the lcd object constructor is
// changed to use the hd44780_pinIO class.

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header

// declare Arduino pins used for LCD functions
// and the lcd object

// Note: this can be with or without backlight control:

// without backlight control:
// The parameters used by hd44780_pinIO are the same as those used by
// the IDE bundled LiquidCrystal library
// note that ESP8266 based arduinos must use the Dn defines rather than
// raw pin numbers.
#if defined (ARDUINO_ARCH_ESP8266)
const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices
#else
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // for all other devices
#endif
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

//with backlight control:
//	backlight control requires two additional parameters
//	- an additional pin to control the backlight
//	- backlight active level which tells the library the level
//		needed to turn on the backlight.
//		note: If the backlight control pin supports PWM, dimming can be done
//			using setBacklight(dimvalue);
//
//	WARNING: some lcd keypads have a broken backlight circuit
//		If you have a lcd keypad, it is recommended that you first run the
//		LCDKeypadCheck sketch to verify that the backlight circuitry
//		is ok before enabling backlight control.
//		However, the hd44780_PinIO class will autodetect the issue and
//		work around it in s/w. If the backlight circuitry is broken,
//		dimming will not be possible even if the backlight pin supports PWM.
//
#if defined (ARDUINO_ARCH_ESP8266)
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH;
#else
//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH;
#endif
//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLEvel);

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
	// initialize LCD with number of columns and rows: 
	//
	// note:
	//	begin() will automatically turn on the backlight if backlight
	// 	control is specified in the lcd object constructor
	//
	lcd.begin(LCD_COLS, LCD_ROWS);

	// if backlight control was specified, the backlight should be on now

	// Print a message to the LCD
	lcd.print("Hello, World!");
}

void loop() {}
Weather StationC/C++
#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h> 
#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// commentare il dispositivo non utilizzato (nel mio caso un l' ESP8266)
#if defined (ARDUINO_ARCH_ESP8266)
//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // per dispositivi esp8266
#else
const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // tutti gli altri dispositivi
#endif
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// geometria dell LCD
const int LCD_COLS = 16; // colonne dello schermo
const int LCD_ROWS = 2; // righe dello schermo

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  lcd.setCursor(0, 0);
  lcd.print("Temperatura");
  lcd.setCursor(12, 0);
  lcd.print(t);
  lcd.setCursor(0, 1);
  lcd.print("Umidita'");
  lcd.setCursor(12, 1);
  lcd.print(h);
}

Custom parts and enclosures

Display frame (for 123D Design)
lcd_S7Ak4cbRil.123dx
Display frame (STL)

Schematics

Weather Station Connections
schema_3HOewUp7fB.fzz

Comments

Add projectSign up / Login