ZachLabs Arduino

Lab 14: Character LCDs

There are many different types of liquid-crystal displays (or “LCDs”) that have been made over the years. The one in your kit is an old type that has been around for decades and is more like a digital watch than a modern phone screen (even though both are technically LCDs). They use a backlight to light up the entire screen, and then use an electrically controlled material to selectively block out the light and create darker colors.

Example Program

Connect the character LCD to your Arduino by making the following connections with the long M-to-F jumper wires included in your kit, and then upload the program to your Arduino:

Character LCD Arduino Pin
GND GND
VCC 5V
SDA A4
SCL A5
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp lcd;

void setup()
{
    // Initialize the LCD:
    lcd.begin(16, 2);

    // Print an unchanging message on the top row of the LCD:
    lcd.print("I have been on");
}

void loop() 
{
    // Re-print the changing message on the bottom row of the LCD:
    lcd.setCursor(0, 1);
    lcd.print("for ");
    lcd.print(millis() / 1000);
    lcd.print(" seconds.");
}

Before you can compile and upload this program to your Arduino you will need to open the library manager in the Arduino IDE (“Tools > Manage Libraries…”, or Ctrl+Shift+I), type “hd44780” in the search bar, and install the “hd44780” library by “Bill Perry”.

Once you have installed the library and compiled and uploaded the program you should see some text printed on the LCD screen. If you do not, quickly double-check your wiring. If everything is wired correctly and the backlight is on but you do not see any text, you probably need to adjust the contrast on the LCD screen.

Get a small Phillips head screwdriver and use it to adjust the blue potentiometer on the circuit board on the back of the LCD screen. If you turn it all the way clockwise you will see all of the pixels (even the ones that are off), and if you turn it all the way counterclockwise you will see nothing but the backlight. Find a happy medium where the text is clearly visible without the pixels that are off also being visible.

Learn More

Assignment

Use one of the sensors from a previous lab (X/Y joystick, ultrasonic rangefinder, photoresistor, potentiometer, etc.) and create a “dashboard” on the LCD that visually displays and updates the information from the sensor in real-time. You should do something more interesting than merely printing out a number, like this example below that shows the position of the X/Y joystick as two animated meters, one for each axis. Be creative!