Some form of display is often vital on your arduino projects.Let me introduce you to the HD44780 character LCD.
It’s quite a common and cheap display solution that is relatively easy to use. It often finds its way into many arduino starter kits for these reasons. Ive used it a few times in my projects but have always been annoyed by one aspect…. the high amount of pins and the requirement of a resistor for the backlight and a potentiometer for the contrast.
As you can see the board uses up 6 data pins on your board which can be a pain on the smaller boards I’ve been using lately. Then I discovered I2C (I squared C).
With this we can run these LCD displays with a total of 4 wires. This is handy on boards like the ESP8266 or ESP32 with few pins. I plan on using a I2C compatible display on a project in the near future. I ordered the larger 4 line version in fact.
The code for the I2C display is quite similar to the regular versions.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 columns and 2 row display
void setup() {
lcd.init(); //initialize lcd screen
lcd.backlight(); // turn on the backlight
}
void loop() {
delay(1000); //wait for a second
lcd.setCursor(0,0); // tell the screen to write on the top row
lcd.print("LCD TEST"); // tell the screen to write “hello, from” on the top row
lcd.setCursor(0,1); // tell the screen to write on the bottom row
lcd.print("Hello World!"); // tell the screen to write "Hello World!" on the bottom row
}