This note illustrates the use of a low-cost alphanumeric screen that is prevalent where limited display is adequate for the intended purposes.
After reading the data from a sensor, the succeeding step is to transfer the available data for downstream use. The simplest method to accomplish this transfer is to display the data for human readability. If the data is simply a condition or state then colored lights are the simplest and perhaps the cheapest way to perform this operation for qualitative data.
If the data is quantitative then alphanumeric display in some format is desirable. This requirement is a common occurrence for appliances (e.g. domestic) or peripherals (e.g. printer/fax machines) panels. The immediate purpose of such feedback is to inform the user/operator on current status and to solicit, optionally, feedback to continue operations.
StoryThe simplest display device that offers alphanumeric rendering of the data is the Liquid Crystal Display(LCD) screen. The majority of these devices rely on the HitachiHD44780 controller. The Arduino library provides support for this controller with a set of higher level methods that minimize the need to understand the lower level operational details.
This exercise demonstrates the use of a device that supports 16 characters each on 2 lines (thereby commonly referred to as 1602). Additional some models of this device support Red/Green/Blue color indices for a broad spectrum of background colors. Owing to the limited purposes of this exercise, the the ability to adjust the background light did not merit as a test consideration.
The test exercises are limited to the following capabilities as provided in the standard Arduino Liquid Crystal library:
- autoscroll
- blink
- cursor
- display
- scroll
- serial line echo
- set cursor
- test direction
There are two methods for this function to permit characters to move in a set direction (i.e. left or right) upon output on the display:
- autoscroll – enable autoscroll function
- noAutoscroll – disable autoscroll
This method moves all existing text by one letter space when a new letter is placed for display on the screen.
noAutoscrollThis method disables the columnar shift of the existing text when a new letter is placed for display on the screen.
BlinkThere are two methods in this category to control the display of the cursor. The type cursor is either block or underscore:
- blink
- noBlink
This method enables the cursor to display in blink mode (i.e.turn on and then off in rapid succession). The blink interval cannot be set using the standard library.
noBlinkThis method disables the cursor from blinking.
Code snippetlcd.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 "); delay(4000);
CursorThere are two methods in this category to set the cursor when the underscore representation is used for the cursor:
- cursor
- noCursor
This method positions displays an underscore character at the current position. The next letter will be posted at this location.
noCursorThis method turns off the display of the cursor on the screen.
Code snippet 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 "); delay(4000);
DisplayThis category has two methods to control the visibility of the display on the screen:
- display
- noDisplay
This method turns on the display screen. If the screen was previously turned off then the previous settings of on-screen text and cursor will be restored.
noDisplayThis method turns off the display screen by suppressing visibility. There is no loss on screen content which can subsequently be restored by using the display method mentioned in the previous section.
Code snippet 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
ScrollThis category has two methods to set the scroll direction of all lines concurrently on the screen:
- scrollDisplayLeft
- scrollDisplayRight
This method moves all lines on the display screen to the left by one position.
scrollDisplayRightThis method moves all lines on the display screen to the right by one position.
Code snippet 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);
Serial Line EchoThis category has a single method, write, to display characters on the screen. In order to use it to echo the serial line data, the method must be used in conjunction with a method,available, in the Arduino Serial library.
Code snippet 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
SetCursorThere is only one method in this category – setCursor.
setCursorThis method sets the cursor to the specified location which is passed as a {column, row} tuple parameter. The ensuing output to the screen will be displayed starting at this position.
Code snippetText DirectionThis category has two methods to control the flow of new characters to the screen:
- rightToLeft
- leftToRight
This method enables new placement of text on the screen to flow from the right to the left direction. This method does not move any existing text on the screen.
leftToRightThis method enables new placement of text on the screen to flow from the left to the right direction.
Code snippet 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);
ReferencesArduino Liquid Crystal Library
Hitachi HD44780 Liquid Crystal Display module
Comments