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 two. This solution requires a I2C to parallel converter, shift register, thus is a bit more expensive and slower too.

LCD example

In the below example a LCD 20 characters wide and with four lines are used in parallel mode. But any Hitachi HD44780 compatible LCD should work just fine. The code makes the LCD look like below.

The code for the above LCD where the LCD RS is connected to D14, LCD Enable connected to D15, and the LCD data bits DB7 to DB4 connected to D13 to D10 respectively. Please see the LCD description on the hardware page for more information.

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.