How to Use a HD44780 Based Display
Some projects and guides for HD44780 based LCD displays.
Components and supplies
1
DHT11 Temperature & Humidity Sensor (4 pins)
1
Arduino UNO
1
HD44780 16X2 LCD display
1
Jumper wires (generic)
1
USB-A to B Cable
Tools and machines
1
3D Printer (generic)
Project description
Code
Weather Station
c_cpp
1#include <hd44780.h> 2#include <hd44780ioClass/hd44780_pinIO.h> 3#include "DHT.h" 4 5#define DHTPIN 2 // what digital pin we're connected to 6 7// Uncomment whatever type you're using! 8#define DHTTYPE DHT11 // DHT 11 9//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 10//#define DHTTYPE DHT21 // DHT 21 (AM2301) 11 12// commentare il dispositivo non utilizzato (nel mio caso un l' ESP8266) 13#if defined (ARDUINO_ARCH_ESP8266) 14//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // per dispositivi esp8266 15#else 16const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // tutti gli altri dispositivi 17#endif 18hd44780_pinIO lcd(rs, en, db4, db5, db6, db7); 19 20// geometria dell LCD 21const int LCD_COLS = 16; // colonne dello schermo 22const int LCD_ROWS = 2; // righe dello schermo 23 24DHT dht(DHTPIN, DHTTYPE); 25 26void setup() { 27 Serial.begin(9600); 28 Serial.println("DHTxx test!"); 29 lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo 30 dht.begin(); 31} 32 33void loop() { 34 // Wait a few seconds between measurements. 35 delay(2000); 36 37 // Reading temperature or humidity takes about 250 milliseconds! 38 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 39 float h = dht.readHumidity(); 40 // Read temperature as Celsius (the default) 41 float t = dht.readTemperature(); 42 // Read temperature as Fahrenheit (isFahrenheit = true) 43 lcd.setCursor(0, 0); 44 lcd.print("Temperatura"); 45 lcd.setCursor(12, 0); 46 lcd.print(t); 47 lcd.setCursor(0, 1); 48 lcd.print("Umidita'"); 49 lcd.setCursor(12, 1); 50 lcd.print(h); 51} 52
Serial Communication
c_cpp
1// Francesco Mattiussi 2018 2// www.francescomattiussi.tk & www.francescomattiussi.blogspot.com 3// 4// 5 Comments in Italian 6// 7//Il pinout degli schermi con il HD44780 8// 9// 10 1 - LCD gnd 11// 2 - VCC (5v) 12// 3 - Vo Contrast Voltage 13// 4 - RS Register 14 Select (rs) 15// 5 - Read/Write 16// 6 - Enable (en) 17// 7 - Data 0 (db0) 18 ---- 19// 8 - Data 1 (db1) |-------- Non usati nella modalit in 4 bit 20// 21 9 - Data 2 (db2) | 22// 10 - Data 3 (db3) ---- 23// 11 - Data 4 (db4) 24// 25 12 - Data 5 (db5) 26// 13 - Data 6 (db6) 27// 14 - Data 7 (db7) 28// 15 - Backlight 29 Anode (+5v) 30// 16 - Backlight Cathode (Gnd) 31// 32 33#include <hd44780.h> 34#include 35 <hd44780ioClass/hd44780_pinIO.h> 36 37String inputString = ""; // stringa 38 per accumulare i dati 39boolean stringComplete = false; // flag per l' avvenuto 40 completamento 41 42// commentare il dispositivo non utilizzato (nel mio caso un 43 l' ESP8266) 44#if defined (ARDUINO_ARCH_ESP8266) 45//const int rs=D8, en=D9, db4=D4, 46 db5=D5, db6=D6, db7=D7; // per dispositivi esp8266 47#else 48const int rs=8, en=9, 49 db4=4, db5=5, db6=6, db7=7; // tutti gli altri dispositivi 50#endif 51hd44780_pinIO 52 lcd(rs, en, db4, db5, db6, db7); 53 54// geometria dell LCD 55const int LCD_COLS 56 = 16; // colonne dello schermo 57const int LCD_ROWS = 2; // righe dello schermo 58 59void 60 setup(){ 61 62 lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo 63 64 65 Serial.begin(9600); //inizializza la seriale a 9600 baud per il debug 66 67 68 inputString.reserve(200); //riserva 200 byte per la stringa 69} 70 71void loop() 72 { 73 74 if (stringComplete) { 75 lcd.clear(); //pulisce lo schermo 76 77 78 Serial.println(inputString); //stampa la stringa sul seriale 79 lcd.print(inputString); 80 //stampa la stringa sullo schermo 81 82 inputString = ""; //Pulisce la 83 stringa 84 stringComplete = false; //la stringa non pi completa 85 86 } 87 88 89 } 90 91 void serialEvent() { 92 93 while (Serial.available()) { 94 95 96 char inChar = (char)Serial.read(); //riceve il nuovo byte 97 98 inputString 99 += inChar; //lo agggiunge alla stringa 100 101 102 if (inChar == '\ 103') 104 { //se il nuovo carattere un newline 105 stringComplete = true; //la stringa 106 completa 107 } 108 } 109} 110 111 112
Serial Communication
c_cpp
1// Francesco Mattiussi 2018 2// www.francescomattiussi.tk & www.francescomattiussi.blogspot.com 3// 4// Comments in Italian 5// 6//Il pinout degli schermi con il HD44780 7// 8// 1 - LCD gnd 9// 2 - VCC (5v) 10// 3 - Vo Contrast Voltage 11// 4 - RS Register Select (rs) 12// 5 - Read/Write 13// 6 - Enable (en) 14// 7 - Data 0 (db0) ---- 15// 8 - Data 1 (db1) |-------- Non usati nella modalit in 4 bit 16// 9 - Data 2 (db2) | 17// 10 - Data 3 (db3) ---- 18// 11 - Data 4 (db4) 19// 12 - Data 5 (db5) 20// 13 - Data 6 (db6) 21// 14 - Data 7 (db7) 22// 15 - Backlight Anode (+5v) 23// 16 - Backlight Cathode (Gnd) 24// 25 26#include <hd44780.h> 27#include <hd44780ioClass/hd44780_pinIO.h> 28 29String inputString = ""; // stringa per accumulare i dati 30boolean stringComplete = false; // flag per l' avvenuto completamento 31 32// commentare il dispositivo non utilizzato (nel mio caso un l' ESP8266) 33#if defined (ARDUINO_ARCH_ESP8266) 34//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // per dispositivi esp8266 35#else 36const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // tutti gli altri dispositivi 37#endif 38hd44780_pinIO lcd(rs, en, db4, db5, db6, db7); 39 40// geometria dell LCD 41const int LCD_COLS = 16; // colonne dello schermo 42const int LCD_ROWS = 2; // righe dello schermo 43 44void setup(){ 45 46 lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo 47 48 Serial.begin(9600); //inizializza la seriale a 9600 baud per il debug 49 50 inputString.reserve(200); //riserva 200 byte per la stringa 51} 52 53void loop() { 54 55 if (stringComplete) { 56 lcd.clear(); //pulisce lo schermo 57 58 Serial.println(inputString); //stampa la stringa sul seriale 59 lcd.print(inputString); //stampa la stringa sullo schermo 60 61 inputString = ""; //Pulisce la stringa 62 stringComplete = false; //la stringa non pi completa 63 64 } 65 66 } 67 68 void serialEvent() { 69 70 while (Serial.available()) { 71 72 char inChar = (char)Serial.read(); //riceve il nuovo byte 73 74 inputString += inChar; //lo agggiunge alla stringa 75 76 77 if (inChar == '\n') { //se il nuovo carattere un newline 78 stringComplete = true; //la stringa completa 79 } 80 } 81} 82 83 84
Hello World
c_cpp
1// vi:ts=4 2// ---------------------------------------------------------------------------- 3// HelloWorld - simple demonstration of lcd 4// Created by Bill Perry 2016-07-02 5// bperrybap@opensource.billsworld.billandterrie.com 6// 7// This example code is unlicensed and is released into the public domain 8// ---------------------------------------------------------------------------- 9// 10// This sketch is for LCDs that are directly controlled with Arduino pins. 11// 12// Sketch prints "Hello, World!" on the lcd 13// 14// See below for configuring the Arduino pins used. 15// 16// While not all hd44780 use the same pinout, here is the one that most use: 17// pin 1 is the pin closest to the edge of the PCB 18// 1 - LCD gnd 19// 2 - VCC (5v) 20// 3 - Vo Contrast Voltage 21// 4 - RS Register Select (rs) 22// 5 - Read/Write 23// 6 - Enable (en) 24// 7 - Data 0 (db0) ---- 25// 8 - Data 1 (db1) |-------- Not used in 4 bit mode 26// 9 - Data 2 (db2) | 27// 10 - Data 3 (db3) ---- 28// 11 - Data 4 (db4) 29// 12 - Data 5 (db5) 30// 13 - Data 6 (db6) 31// 14 - Data 7 (db7) 32// 15 - Backlight Anode (+5v) 33// 16 - Backlight Cathode (Gnd) 34// 35// ---------------------------------------------------------------------------- 36// LiquidCrystal compability: 37// Since hd44780 is LiquidCrystal API compatible, most existing LiquidCrystal 38// sketches should work with hd44780 hd44780_pinIO i/o class once the 39// includes are changed to use hd44780 and the lcd object constructor is 40// changed to use the hd44780_pinIO class. 41 42#include <hd44780.h> 43#include <hd44780ioClass/hd44780_pinIO.h> // Arduino pin i/o class header 44 45// declare Arduino pins used for LCD functions 46// and the lcd object 47 48// Note: this can be with or without backlight control: 49 50// without backlight control: 51// The parameters used by hd44780_pinIO are the same as those used by 52// the IDE bundled LiquidCrystal library 53// note that ESP8266 based arduinos must use the Dn defines rather than 54// raw pin numbers. 55#if defined (ARDUINO_ARCH_ESP8266) 56const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // for esp8266 devices 57#else 58const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // for all other devices 59#endif 60hd44780_pinIO lcd(rs, en, db4, db5, db6, db7); 61 62//with backlight control: 63// backlight control requires two additional parameters 64// - an additional pin to control the backlight 65// - backlight active level which tells the library the level 66// needed to turn on the backlight. 67// note: If the backlight control pin supports PWM, dimming can be done 68// using setBacklight(dimvalue); 69// 70// WARNING: some lcd keypads have a broken backlight circuit 71// If you have a lcd keypad, it is recommended that you first run the 72// LCDKeypadCheck sketch to verify that the backlight circuitry 73// is ok before enabling backlight control. 74// However, the hd44780_PinIO class will autodetect the issue and 75// work around it in s/w. If the backlight circuitry is broken, 76// dimming will not be possible even if the backlight pin supports PWM. 77// 78#if defined (ARDUINO_ARCH_ESP8266) 79//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7, bl=D10, blLevel=HIGH; 80#else 81//const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7, bl=10, blLevel=HIGH; 82#endif 83//hd44780_pinIO lcd(rs, en, db4, db5, db6, db7, bl, blLEvel); 84 85// LCD geometry 86const int LCD_COLS = 16; 87const int LCD_ROWS = 2; 88 89void setup() 90{ 91 // initialize LCD with number of columns and rows: 92 // 93 // note: 94 // begin() will automatically turn on the backlight if backlight 95 // control is specified in the lcd object constructor 96 // 97 lcd.begin(LCD_COLS, LCD_ROWS); 98 99 // if backlight control was specified, the backlight should be on now 100 101 // Print a message to the LCD 102 lcd.print("Hello, World!"); 103} 104 105void loop() {} 106
Weather Station
c_cpp
1#include <hd44780.h> 2#include <hd44780ioClass/hd44780_pinIO.h> 3#include "DHT.h" 4 5#define DHTPIN 2 // what digital pin we're connected to 6 7// Uncomment whatever type you're using! 8#define DHTTYPE DHT11 // DHT 11 9//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 10//#define DHTTYPE DHT21 // DHT 21 (AM2301) 11 12// commentare il dispositivo non utilizzato (nel mio caso un l' ESP8266) 13#if defined (ARDUINO_ARCH_ESP8266) 14//const int rs=D8, en=D9, db4=D4, db5=D5, db6=D6, db7=D7; // per dispositivi esp8266 15#else 16const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7; // tutti gli altri dispositivi 17#endif 18hd44780_pinIO lcd(rs, en, db4, db5, db6, db7); 19 20// geometria dell LCD 21const int LCD_COLS = 16; // colonne dello schermo 22const int LCD_ROWS = 2; // righe dello schermo 23 24DHT dht(DHTPIN, DHTTYPE); 25 26void setup() { 27 Serial.begin(9600); 28 Serial.println("DHTxx test!"); 29 lcd.begin(LCD_COLS, LCD_ROWS); //inizializza lo schermo 30 dht.begin(); 31} 32 33void loop() { 34 // Wait a few seconds between measurements. 35 delay(2000); 36 37 // Reading temperature or humidity takes about 250 milliseconds! 38 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 39 float h = dht.readHumidity(); 40 // Read temperature as Celsius (the default) 41 float t = dht.readTemperature(); 42 // Read temperature as Fahrenheit (isFahrenheit = true) 43 lcd.setCursor(0, 0); 44 lcd.print("Temperatura"); 45 lcd.setCursor(12, 0); 46 lcd.print(t); 47 lcd.setCursor(0, 1); 48 lcd.print("Umidita'"); 49 lcd.setCursor(12, 1); 50 lcd.print(h); 51} 52
Downloadable files
Weather Station Connections
Weather Station Connections
Weather Station Connections
Weather Station Connections
Documentation
Display frame (STL)
Display frame (STL)
Display frame (for 123D Design)
Display frame (for 123D Design)
Display frame (STL)
Display frame (STL)
Display frame (for 123D Design)
Display frame (for 123D Design)
Comments
Only logged in users can leave comments