Two
line LCD modules based on the Hitachi HD44780 LCD controller (commonly
referred to as 1602 LCD) are a very inexpensive way to add an output
device to an Arduino project, enabling all manner of user information to
be displayed in a flexible format.
I have found, though, that I am not able to read this display at a distance (maybe it is age related!). For my own projects I developed code that allows numbers to be displayed over both lines of the LCD display, making the ‘current’ value display for instruments, for example, more obvious and more visible.
On these types of LCD modules, each character from ASCII value 8 and above is defined in ROM, and the first 8 (numbered 0 through 7) are user-definable. In this application these 8 characters are used to define the top and bottom half of each double height number.
I found two ways to do this – one uses all 8 characters and the other just 7, shown below. Having the extra character available in the second font allows me to use the double height digits and a bar graph on the same display.
The first font creates more natural looking numbers but the horizontal stroke on the numbers are not aligned identically. This font can also have a ‘bold’ variant, where the horizontal strokes are double width. The second font creates a more stylized number, with all the central horizontal strokes aligned but also doubled up. All three types are shown below.
The class constructor is given a pointer to an initialized LiquidCrystal object so that it can print to that display and implements the following methods:
I have found, though, that I am not able to read this display at a distance (maybe it is age related!). For my own projects I developed code that allows numbers to be displayed over both lines of the LCD display, making the ‘current’ value display for instruments, for example, more obvious and more visible.
On these types of LCD modules, each character from ASCII value 8 and above is defined in ROM, and the first 8 (numbered 0 through 7) are user-definable. In this application these 8 characters are used to define the top and bottom half of each double height number.
Defining the Number Font
The trick is to come up with a set of top/bottom shapes that work within these limitations and provide legible numbers.I found two ways to do this – one uses all 8 characters and the other just 7, shown below. Having the extra character available in the second font allows me to use the double height digits and a bar graph on the same display.
The first font creates more natural looking numbers but the horizontal stroke on the numbers are not aligned identically. This font can also have a ‘bold’ variant, where the horizontal strokes are double width. The second font creates a more stylized number, with all the central horizontal strokes aligned but also doubled up. All three types are shown below.
I also found displays differ slightly in their inter-line spacing and
the size of the pixels. The color of the display also affects how the
characters are perceived.
Using the Source Code
The source code is implemented as a class and can be found at my library site.The class constructor is given a pointer to an initialized LiquidCrystal object so that it can print to that display and implements the following methods:
- begin() to initialize the default single-width font in the LCD display.
- setSingleFont() to load the single width font into the LCD.
- setDoubleFont() to load the double width (bold) font into the LCD.
- writeNumber() to write a multi-digit number starting at the specified top left (row, col) LCD coordinate with leading zeroes if requested.
- writeDigit() to write a single digit at the specified specified top left (row, col) LCD coordinate.