Table of contents
Often you will like to add a display to your RFzero, and many of the standard programs also enable the use of a display. Displays for Arduinos are typically Liquid Crystal Displays (LCD) or graphical displays. A display is a neat thing to put on your RFzero to let the user view the status of different things.
Please see the display description page for more information on how to connect a display.
Liquid crystal displays – LCD
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.
When you have installed the RFzero library you will also have installed support for an I2C LCD use.
Graphical displays – TFT
There are many different graphical displays available and probably many of them can be used with your RFzero. However, the RFzero programs only support the ILI9341 320 pixels x 240 pixels and the ILI9488 480 pixels x 320 pixels via SPI.
If you have a different graphical display or with a different kind of interface, you will have to integrate this yourself.
When you have installed the RFzero library you will also have installed support for the ILI9341 and the ILI9488 TFTs
LCD examples
Below are two examples that show how to make use of an 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 an LCD, with 20 characters by four lines, look like below.
In the programs parallel access to the LCD are being used. If you want to change to I2C/Wire access, using the RFzero LCD I2C included library, originally made by DFRobot and johnrickman, 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
1 2 3 |
// Include the parallel LCD library #include <LiquidCrystal.h> LiquidCrystal LCD(PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_DB4, PIN_LCD_DB5, PIN_LCD_DB6, PIN_LCD_DB7); |
and
1 2 |
// Initialize the LCD and switch backlight on LCD.begin(20, 4); |
to
1 2 3 |
// Include the I2C LCD library #include <RFzero_LCD_I2C.h> LCD_I2C lcdI2C; |
and
1 2 |
// Initialize the LCD and switch backlight on lcdI2C.begin(0x27, 20, 4); // LCD I2C addr. is 0x27, 20 chars and 4 lines and connected to D8 (SDA) and D9 (SCL) |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// RFzero include and object creation #include <RFzero.h> // MUST ALWAYS be included for RFzero // Include the parallel LCD library #include <LiquidCrystal.h> LiquidCrystal LCD(PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_DB4, PIN_LCD_DB5, PIN_LCD_DB6, PIN_LCD_DB7); void setup() { // Initialize the LCD and switch backlight on LCD.begin(20, 4); // Write to the LCD LCD.print("RFzero GPS RF ARM"); LCD.setCursor(3, 1); // Put the cursor at the fourth position on the second line LCD.print("www.rfzero.net"); LCD.setCursor(0, 3); // Put the cursor at the beginning of the fourth line LCD.print("5Q7J OZ2M OZ2XH OZ5N"); } void loop() {} |
I2C/Wire access
In the below example the RFzero LCD I2C library and an external board, with a PCF8574T, backlight and contrast control is used.
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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// RFzero include and object creation #include <RFzero.h> // MUST ALWAYS be included for RFzero // Include the I2C LCD library #include <RFzero_LCD_I2C.h> LCD_I2C lcdI2C; void setup() { // Initialize the LCD and switch backlight on lcdI2C.begin(0x27, 20, 4); // LCD I2C addr. is 0x27, 20 chars and 4 lines and connected to D8 (SDA) and D9 (SCL) // Write to the LCD lcdI2C.print("RFzero GPS RF ARM"); lcdI2C.setCursor(3, 1); // Put the cursor at the fourth position on the second line lcdI2C.print("www.rfzero.net"); lcdI2C.setCursor(0, 3); // Put the cursor at the beginning of the fourth line lcdI2C.print("5Q7J OZ2M OZ2XH OZ5N"); } void loop() {} |
TFT examples
The graphical displays use primarily two libraries by Adafruit (Adafruit_ILI9431 and Adafruit_GFX) for the ILI9341 and the ILI9488 library by Jarret Burkett. Below are two examples that show how to use the ILI9341 and the ILI9488 graphical displays.
Example of ILI9341 use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
// RFzero includes #include <RFzero.h> // Must always be included for RFzero // Display includes #define PIN_TFT_CS 10 #define PIN_TFT_RST 11 #define PIN_TFT_DC 12 #define backgroundColor 0x000F // Navy blue #define foregroundColor 0xFFE0 // Yellow #include <Adafruit_GFX.h> // by Adafruit: https://github.com/adafruit/Adafruit-GFX-Library #include <Adafruit_ILI9341.h> // by Adafruit: https://github.com/adafruit/Adafruit_ILI9341 Adafruit_ILI9341 tft = Adafruit_ILI9341(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST); void setup() { // InItialize the TFT tft.begin(); tft.fillScreen(backgroundColor); // Fill the background tft.setRotation(3); // Rotate the TFT to landscape // Write to the TFT tft.setTextColor(foregroundColor, backgroundColor); // Set the text colors tft.setTextSize(3); // Set the text size tft.setCursor(10, 20); // Put the cursor at the (x, y) = (10, 20) position tft.print("RFzero GPS RF ARM"); tft.setCursor(10, 70); tft.print("www.rfzero.net"); tft.setCursor(10, 120); tft.print("5Q7J OZ2M"); tft.setCursor(10, 150); tft.print("OZ2XH OZ5N"); } void loop() {} |
Example of ILI9488 use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// RFzero includes #include <RFzero.h> // Must always be included for RFzero // Display includes #define PIN_TFT_CS 10 #define PIN_TFT_RST 11 #define PIN_TFT_DC 12 #define backgroundColor 0x000F // Navy blue #define foregroundColor 0xFFE0 // Yellow #include <Adafruit_GFX.h> // by Adafruit: https://github.com/adafruit/Adafruit-GFX-Library #include <ILI9488.h> // by Jaret Burkett: https://github.com/jaretburkett/ILI9488 ILI9488 ifi = ILI9488(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST); void setup() { // InItialize the TFT tft.begin(); tft.fillScreen(backgroundColor); // Fill the background tft.setRotation(3); // Rotate the TFT to landscape // Write to the TFT tft.setTextColor(foregroundColor, backgroundColor); // Set the text colors tft.setTextSize(3); // Set the text size tft.setCursor(10, 20); // Put the cursor at the (x, y) = (10, 20) position tft.print("RFzero GPS RF ARM"); tft.setCursor(10, 70); tft.print("www.rfzero.net"); tft.setCursor(10, 120); tft.print("5Q7J OZ2M"); tft.setCursor(10, 150); tft.print("OZ2XH OZ5N"); } void loop() {} |
Display in other files than .ino
What if you want to access the display in one or more of your .cpp files? Well, you will have to create a display object in each .h file but this will take up precious and unnecessary memory. Instead you can use the extern keyword, and only have one instance of the display library declared in the .ino file. The use of the extern keyword tells the compiler to look elsewhere for the display object but it is accessible in the .cpp and .h files.
Below is how to do it, using an LCD, but the TFT works the same way, where one set of .cpp and .h files are in use, but this could be one or as many as needed.
File: MyProgram.ino.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <LiquidCrystal.h> // Must be included for LCD use LiquidCrystal LCD(PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_DB4, PIN_LCD_DB5, PIN_LCD_DB6, PIN_LCD_DB7); // Create LCD object, syntax: RS, Enable, DB4, DB5, DB6, DB7 // RFzero include and object creation #include <RFzero.h> // MUST ALWAYS be included // Own includes #include "foo.h" // foo.h (and foo.cpp) file located in same dir as MyProgram.ino ... void setup() { .... LCD.begin(20, 4); // Initialize the LCD, 20 chars and 4 lines ... } void loop() { ... } |
So in the .ino file just do as you normally would do.
File: foo.h.
1 2 3 4 5 6 7 |
... #include <LiquidCrystal.h> extern LiquidCrystal LCD; void Bar(int val); ... |
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.
1 2 3 4 5 6 7 8 9 10 |
... #include <foo.h> void Bar(int val) { ... LCD.print(result); ... } ... |
In the .cpp file you can now access the LCD library just as you would to in the .ino file.