Arduino: The Noiasca Liquid Crystal for your Character Display (LCD)

With so many Arduino LCD Libraries, why do we need just another one? The Noiasca Liquid Crystal supports I2C, SPI and parallel interfaces but more over, it handles special characters right. The days of octal codes for printing on a LCD are finally over!

Teaser: What does Noiasca Liquid Crystal different?

The "Noiasca Liquid Crystal" library does a character mapping from UTF-8 to the existing characters in the Hitachi HD44780U A00 ROM. As example some special characters in the second row of the display:

LCD special characters for Arduino

(Degree, Division, middle Point, n with tilde, Pound, Yen, Tilde, Sqareroot, Proportional to, Infinity, Left Arrow, Right Arrow, Backslash)

For the beginning you should know that you don't need to enter the octal ROM addresses of the special characters manually but these print can be done by a simple:

lcd.print("°÷·ñ£¥~√∝∞←→\\");

On this page I would like to dig deeper into what happens in the library.You can read more about this character mapping in some days or in the German section of this site.

Supported Hardware

The library offers several classes depending on the used hardware:

It's always necessary to include the library:

#include <NoiascaLiquidCrystal.h>

The second include depends on the used hardware:

#include <NoiascaHW/lcd_spi.h>  

After choosing the hardware, you need the constructor for your display, i. e.:

LiquidCrystal_SPI lcd(addr, cols, rows, csPin);

The needed parameters differ from hardware to hardware. I.e. the parallel LCD needs GPIO definitions, the I2C LCD needs to know the I2C address, the SPI display needs the chip select pin etc. See the Hello World sketch of the respective hardware to get the constructor right.

For I2C and SPI interfaces, don't forget to add a Wire.begin() or SPI.begin() to your setup. It will not be done by the library.

The Character Set of the HD44780U A00 ROM

If you check the HD44780U datasheet page 17ff you can see following:

  • In the lower range (to 127) there are 3 characters which differ from ASCII (red marked). The backslash is used for a Yen, the tilde was replaced by an arrow, and an additional arrow was added.
  • other "special characters" like (alpha, beta, micro,  ä, ö, ü, ...) are available, but have different addresses.
  • The Arduino will send these special characters in UTF-8.

HD44780 special characters

On page 18 you will find a second character set, but HD44780U displays always come with either the hardware support of A00 or A02. Other LCD controllers might have the possibility to change between character sets (e.g. the ST7070), but not the HD44780U. If you need the support for South European, East European or Cyrillic letters - you have to buy a LCD with A02 ROM. But be carefully, lot of advertised "Russian" displays seem to use the SPLC780D1 with Cyrillic letters starting at 0xA000 - not a HD44780U A02 ROM.

The first 128 characters (0-127) of UTF-8 are similar to ASCII. But characters can be encoded in up to 4 bytes. This is the reason, why you will get two "Japanese" characters, if you send for example the degree symbol. These characters are called "Katakana half-width" and are defined in UTF-8 from 0xFF65 to 0xFF9F.

The degree Symbol ° is encoded as 0xC2B0 and therefore you will get the Japanese character 0xC2 and 0xB0 if you try to print °.

The following table shows some of the characters and their representation in the character ROM A00.

char UTF-8 A00 Name
\ 5C 7C REVERSE SOLIDUS ("Backslash")
~ 7E 2D TILDE
£ C2 A3 ED POUND SIGN
¥ C2 A5 5C YEN SIGN
° C2 B0 DF DEGREE SIGN
µ C2 B5 E4 MICRO SIGN
· C2 B7 A5 MIDDLE DOT
ä C3 A4 E1 LATIN SMALL LETTER A WITH DIAERESIS
ö C3 B6 EF LATIN SMALL LETTER O WITH DIAERESIS
ü C3 BC F5 LATIN SMALL LETTER U WITH DIAERESIS
Ä C3 84 *) LATIN CAPITAL LETTER A WITH DIAERESIS
Ö C3 96 *) LATIN CAPITAL LETTER O WITH DIAERESIS
Ü C3 9C *) LATIN CAPITAL LETTER U WITH DIAERESIS
ß C3 9F E2 LATIN SMALL LETTER SHARP S
ñ C3 B1 EE LATIN SMALL LETTER N WITH TILDE
÷ C3 B7 FD DIVISION SIGN
ñ C6 9F F2 LATIN CAPITAL LETTER O WITH MIDDLE TILDE
Σ CE A3 F6 GREEK CAPITAL LETTER SIGMA
α CE B1 E0 GREEK SMALL LETTER ALPHA
β CE B2 E2 GREEK SMALL LETTER BETA
ε CE B5 E3 GREEK SMALL LETTER EPSILON
μ CE BC E4 GREEK SMALL LETTER MU
π CF 80 F7 GREEK SMALL LETTER PI
ρ CF 80 E6 GREEK SMALL LETTER RHO
E2 86 90 7F LEFTWARDS ARROW
E2 86 92 7E RIGHTWARDS ARROW
E2 88 E8 E8 SQUARE ROOT
E2 88 9D E0 PROPORTIONAL TO
E2 88 9E F3 INFINITY

At the bottom of the list - you even can find some 3 byte characters.

There are some additional things to know about UTF-8

  • If a character starts with 0b11xxxxxx (0xC0 and higher), more bytes will follow
  • 0b110xxxxx means exactly one start byte and a second byte will follow
  • 0b1110xxxx (0xE0 and higher) means the character consists of three bytes (e.g. the character for square root)
  • 0b11110xxx (0xF0 and higher) means, the character consists of four bytes

If you read that the first time, it sounds very complex, but Wikipedia summarizes UTF-8 very well. If you want to know more about UTF-8 - it's worth further reading.

Simply spoken, the library write method does three steps if you call write (either directly or implicit with print):

  • if it is the first character, decide if you should write the character or just store it as "first byte"
  • if we receive a following byte, decide if we got already enough characters and if yes, activate writing (and delete the special character storage)
  • if something has to be written to the LCD, check - if we need a further mapping.

To make this happen, the LCD class adds a 4byte storage for the special character and uses an internal function to do these decisions and character mapping.

Your own Character Converter

If you need for any reason a different converter for the characters you can hand over your own callback function as optional last parameter to your LCD object.

Example:

LiquidCrystal_SPI lcd(0x40, 16, 2, cbConverter);

Obviously - you also have to implement the callback function in your user sketch to do all the magic.

The minimum callback function looks like:

uint8_t cbConverter (uint32_t &special, uint8_t &value)
{
  return PRINT; // return PRINT or not NOPRINT
}

The callback function needs references to the the internal storage of previous special characters and the actual value to be printed.

If you want to print a character (the character in value), return the constant PRINT. If you don't want to print the value, you can store it into the special character buffer and return a NOPRINT.

Your callback function will be called internally every time you write a character, the .write method will always return 1, meaning "one value processed" even if it was not immediately displayed on the LCD but stored into special.

This enables the handling of UTF-8 characters which can consist of up to 4 bytes.

See the general example "50 Convert" how to write your own character converter.

German Umlauts

For my German readers: the default constructor enables the support for the small letters ä ö ü and ß. The large German umlauts Ä Ö Ü will be converted to their counterpart A O U, as there are no capital Umlauts in the Standard A00 Character set. If you want to try other variants, you can use following predefined callback functions

convert             // default, uses the standard converter (Ä gets A)
convert_ae          // Umlauts like Ä become Ae
convert_small       // Umlauts like Ä become ä
convert_special     // an Umlauts like Ä becomes Ä using custom character 

The callback "convert_special" will use the custom characters 5, 6 and 7 for the large Umlauts. To create the large umlauts you have to call the method to create the custom characters Ä Ö Ü in setup:

lcd.createUml();

Lowercase Letters with Descender (g j p q y)

There are alternative lowercase letters (minuscule) with descender (g j p q y) in the ROM A00. You can write them by adding 0x80 to the letter ("8 columns to the right"). But I don't like them very much. These letters are still one pixel higher even if they use the space below the baseline and are looking larger then the rest. See this example which prints the first line in the default font and the second line using the pixel below the baseline:

LCD with large descender for Arduino

If you would like to test on your own, use writeOld:

lcd.writeOld('g' + 0x80); // write g with the descender reaching below the baseline

Direct access to special characters .writeOld()

If you are already writing special characters with the .write() method, you should remember, that .write() will apply the character converter. If you want to write characters without the converter, you have to write them using the .writeOld() method.

Example: this will write ä on the display:

lcd.writeOld(0xE1); // ä

Why this? All characters in the ROM from 0xC0 onwards are effected by write. If you really need the direct access - you have to replace the method. But with the "Noiasca Liquid Crystal" you can print them anyway using .print().

Not effected are the custom characters 0 - 7 you might have created with the 5x7 bit pattern. These custom characters are well below 0xC0 and can be printed with .write() as with any other library.

Arduino IDE 1.8.9 or higher

To see UTF-8 characters properly you should use at least Arduino IDE 1.8.9 as this adds the "Fix UTF8 related bugs on Windows". If you can't see UTF-8 characters in the IDE or in the Serial Monitor, update your IDE.

Caveats

With so many LCD libraries out there, what are the caveats of Noiasca Liquid Crystal?

First, this library is not optimized for speed. I.e. this library does not read the Busy Flag of the display. It just waits the waiting time during the commands like defined in the datasheet. It's the same like in lot of other libraries. However: in general - if "the standard" library works for your LCD - Noiasca Liquid Crystal should work also.

Second, it will take (a little bit) more memory (SRAM and PROGMEM) for the character mapping. If you are low on memory, you can always use a minimum implementation adding a "_base" to the constructor. Nevertheless I put in some efforts and the library might take less memory than others.

And third, the constructors are not highly variable. There are some fixed values in the code you can't change from the user sketch. The library works fine as long as you can live with the internal default values.

Summary

If you need an easy support of the given character set of a HD44870 display or if you want to have one unique interface for several hardware variants of LCDs take the "Noiasca Liquid Crystal" library in consideration. If you are from a European country and you need better support of Latin1-4 letters you should really buy a SPLC780D1 LCD - which is also supported by this library.

Links

Protocol

First upload: 2020-09-02 | Version: 2020-12-03