Matha Goram
Published © GPL3+

Do You Read Me?

After reading the data from a sensor, the succeeding step is to display the data on the screen for quick and simple feedback.

BeginnerProtip15 minutes632
Do You Read Me?

Things used in this project

Hardware components

ELEGOO Arduino UNO R3
×1
ELEGOO LCD1602 screen
×1
Elegoo DuPont connection wires
×1
ELEGOO Breadboard
×1
Sunfounder Baseplate
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

LCD1602 introductory test assembly

Assembly diagram

Schematics

LCD1602 introductory test schematic

The most basic schematic diagram to test the LCD1602 display.

Code

LCD1602 introductory test cases

C/C++
An introductory set of tests for the LCD1602 device using the standard Arduino Liquid Crystal library.
/*
 * ElegooLCD1602-01.ino
 * A basic set of tests to demonstrate the 16x2 LCD device using the
 * Arduino LiquidCrystal library for displays that rely on the
 * Hitachi HD44780 driver.
 * 2018-10-12
 * armw
 * v0.1
 * © 2018 <reza@parkcircus.org> All Rights Reserved
 *  
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.  
 * 
 * Reference:
 * https://www.arduino.cc/en/Reference/LiquidCrystalBegin
 * The basic circuit relies on the following connections:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte bitmap_smiley[8] =
{
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};
const int smiley = 1;                   // index to custom character bitmap
const int nCols = 16;                   // number of columns in LCD screen
const int nLines = 2;                   // number of lines in LCD screen

void setup()
{
  Serial.begin(115200);                 // needed only if serial line tests will be conducted
                                        // set up the LCD's number of columns and rows: 
  lcd.begin(nCols, nLines);             // initializes the interface to the LCD screen, and 
                                        // specifies the dimensions (width and height) of the display

  lcd.createChar(smiley, bitmap_smiley);// create a new character
  lcd.setCursor(0, 0);                  // print a message to the LCD
  lcd.write(smiley);                    // print custom character smiley
  delay(1000);                          // wait 1 sec

  lcd.print("LCD1602-01 test");
  lcd.write(smiley);                    // print custom character smiley
  delay(1000);
                                        // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);                  // (note: line 1 is the second row, since counting begins with 0):
  lcd.print("ELEGOO Starter K");        // print the message at line 2
  delay(1000);
  lcd.clear();
  lcd.print("Test starting...");
  delay(4000);
}

void loop()
{
  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // blink - blink block-style cursor
  lcd.print("block style");
  lcd.setCursor(0, 1);
  lcd.blink();                          // blink cursor with block style
  lcd.print("blink cursor");
  delay(4000);                          // wait 4 secs
  lcd.setCursor(0, 1);
  lcd.noBlink();                        // do not blink block style cursor
  lcd.print("blink off    ");
  lcd.write(smiley);                    // print custom character smiley
  delay(4000);

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // cursor - blink underscore style cursor
  lcd.print("underscore style");
  lcd.setCursor(0, 1);
  lcd.cursor();                         // display underscore at position for next character to be written
  lcd.print("show cursor");
  delay(4000);                          // wait 4 secs
  lcd.setCursor(0, 1);
  lcd.noCursor();                       // do not blink underscore style cursor
  lcd.print("hide cursor    ");
  lcd.write(smiley);                    // print custom character smiley
  delay(4000);

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // display - turn on/off the LCD display
  lcd.print("display control");
  lcd.setCursor(0, 1);
  lcd.display();                        // turn on display
  lcd.print("turned on");
  delay(4000);                          // wait 4 secs
  lcd.setCursor(0, 1);

  lcd.print("turn off LCD now");
  delay(2000);
  lcd.noDisplay();                      // do not display on LCD screen
  delay(4000);
  lcd.display();                        // turn on the display after display test is completed

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // scroll - set text flow direction
  lcd.print("text flow right");
  lcd.setCursor(0, 1);
  lcd.print("123456 scrolling");
  delay(2000);                          // wait 2 secs
  for (int i = 0; i < nCols; i++)
  {
    lcd.scrollDisplayRight();           // scroll one position right, both lines in tandem
    delay(700);                         // for visual recognition, unnecessary in practice
  }
  delay(2000);

  lcd.clear();
  lcd.print("text flow left");
  lcd.setCursor(0, 1);
  lcd.print("scrolling 123456");
  delay(2000);
  for (int i = 0; i < nCols; i++)
  {
    lcd.scrollDisplayLeft();            // scroll one position left, both lines in tandem
    delay(700);                         // for visual recognition, unnecessary in practice
  }
  delay(4000);  

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
  // serial
  lcd.print("Serial line test");
  delay(4000);
  lcd.clear();
  if (Serial.available())               // during test, ensure that serial line has been "stuffed" with test characters
  {
    delay(200);
    while (Serial.available() > 0)
    {
      lcd.write(Serial.read());         // write current character to LCD screen
    }
  }
  delay(6000);                         // allow extra time to view display screen (for test purposes only)

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // set cursor - position the cursor at {col, row} on screen for next character to be written
  lcd.print("Set cursor");
  lcd.setCursor(0, 1);
  lcd.print("at {column,line}");
  delay(4000);

                                        // loop through English language alphabet set
  for (int a = 'a'; a <= 'd'; a++)
  {
    lcd.clear();
    for (int  r = 0; r < nLines; r++)   // loop over the columns
    {
      for (int c = 0; c < nCols; c++)   // loop over the rows
      {
        lcd.setCursor(c, r);            // set the cursor position:
        lcd.write(a);                   // print the letter
        delay(100);
      }
    }
  }
  delay(1000);

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
                                        // text direction - set flow to right or left
  lcd.print("text direction");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print("left to right");
  delay(2000);                          // wait 2 secs
  lcd.leftToRight();
  lcd.home();
  for (int a = 'a'; a <= 'm'; a++)
  {
    lcd.write(a);
    delay(500);                         // for test use only to let human eye play catch-up
  }
  delay(4000);
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print("right to left");
  delay(2000);                          // wait 4 secs
  lcd.rightToLeft();
  lcd.setCursor(12, 0);
  for (int a = 'n'; a <= 'z'; a++)
  {
    lcd.write(a);
    delay(500);
  }
  delay(4000);

  lcd.clear();                          // clear LCD screen & position the cursor in the upper-left corner
  lcd.print("All tests done!");
  lcd.write(smiley);                    // print custom character smiley
  delay(4000);
}

Credits

Matha Goram
27 projects • 23 followers
Working with discrete electronic components for a very long time but still suffering from the occasional dry soldering results.
Thanks to Arduino.

Comments