Liquid crystal display

A Liquid Crystal Display (LDC) is a neat thing to put on your RFzero to let the user view the status of different things. In the world of Arduino the Hitachi HD44780 LCD library has become the de facto standard.  Fortunately, the LCD library is part of the Arduino IDE standard installation.

A HD44780 parallel LCD can operate in either four bits or eight bits mode. The first requires 12 connections and latter 16 connections. Due to the lower number of connections in the four bits mode this is the most used one also because there is hardly any speed advantage using the eight bits mode. On the RFzero the LCD connector, JP12, is designed specifically for four bits mode and connect the RFzero to the LCD using a pair of six wire cables.

You can also use the I2C (Wire) bus to write to a LCD. This way you will reduce the number of connections from 12/16 to just four. This solution requires a I2C to parallel converter, shift register, thus is a bit more expensive and slower too.


LCD examples

Below are two examples that show how to make use of a LCD with the RFzero. The first example uses parallel access, the standard Arduino library, and the RFzero on-board backlight and contrast circuit. The second example uses I2C/Wire and an external converter board for communication with the LCD. Both examples make a LCD, with 20 characters by four lines, look like below.

In the example programs parallel access to the LCD are being used. If you want to change to I2C/Wire access, using the LiquidCrystal I2C by Frank de Brabrander version 1.1.2 library – other libraries and versions may work differently, you will have to change the LCD inclusion at the top of the .ino files and the initialization in the setup() function, i.e. from

and

to

and

The changes are not specific to the RFzero, but applies to Arduino in general.

Parallel access

In the below example a LCD 20 characters wide and with four lines is used in parallel mode using the JP12 LCD tailored connector on the RFzero. Any Hitachi HD44780 compatible LCD should work just fine. The code makes the LCD look like below.

Please see the LCD description on the hardware page for more information.

I2C/Wire access

In the below example the LiquidCrystal I2C by Frank de Brabrander version 1.1.2 library, and an external board with a PCF8574T, backlight and contrast control is used. This library can be installed via the Arduino IDE in Menu | Tools | Manage libraries. Different libraries may have different syntax and/or H/W requirements, and have not been tested with the RFzero.

In the below example the I2C address of the LCD is 0x27, has 20 characters  and four lines. The LCD is connected to the default I2C bus on the RFzero on D8 (SDA) and D9 (SCL).


LCD in other files than .ino

What if you want to access the LCD in one or more of your .cpp files? Well, you will have to to create a LCD object in each .h file but this will take up precious and unnecessary memory. Instead you can use extern keyword and only have one instance of the LCD library declared in the .ino file. The use extern keyword tells the compiler to look elsewhere for the LCD object but it is accessible in the .cpp and .h files.

Below is how to do it where one set of .cpp and .h files are in use but this could be one or as many as needed.

File: MyProgram.ino.

So in the .ino file just do as you normally would do.

File: foo.h.

I.e. in the .h file add the #include to the library and the extern to the object for the LCD library.

File: foo.cpp.

In the .cpp file you can now access the LCD library just as you would to in the .ino file.