fmattiussi
Published © CERN-OHL

How to Use a HD44780 Based Display

Some projects and guides for HD44780 based LCD displays.

BeginnerShowcase (no instructions)2,397
How to Use a HD44780 Based Display

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
HD44780 16X2 LCD display
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
USB-A to B Cable
USB-A to B Cable
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Display frame (for 123D Design)

Display frame (STL)

Schematics

Weather Station Connections

Code

Serial Communication

C/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 World

C/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 Station

C/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);
}

Credits

fmattiussi

fmattiussi

5 projects • 2 followers

Comments