Alphanumerical LCD is one of the most popular output devices in the Embedded and IoT. Using LCD with predefined line organisation (here, 2 lines, 16 characters each) is as simple as sending a character's ASCII code to the device. This is so much simpler than in the case of the use of dot-matrix displays, where it is necessary to use fonts. The fixed organisation LCD has limits; here, only 32 characters can be presented to the user simultaneously. ASCII presents a limited set of characters, but many LCDs can redefine character maps (how each letter, digit or symbol looks). This way, it is possible to introduce graphics elements (i.e. frames), special symbols and letters.
In this scenario, you will learn how to handle easily LCD to present information and retrieve it visually with a webcam.
Familiarise yourself with a hardware reference: this LCD is controlled with 6 GPIOs as presented in the “Table 1: ESP32-S3 SUT Node Hardware Details” on the hardware reference page.
You are going to use a library to handle the LCD. It means you need to add it to your platformio.ini
file. Use the template provided in the hardware reference section and extend it with the library definition:
lib_deps = adafruit/Adafruit LiquidCrystal@^2.0.2
Draw “Hello World” in the upper line of the LCD and “Hello IoT” in the lower one.
Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with void setup()…
and void loop()…
.
Include the library in your source code:
#include <Adafruit_LiquidCrystal.h>
Declare GPIOs controlling the LCD, according to the hardware reference:
#define LCD_RS 2 #define LCD_ENABLE 1 #define LCD_D4 39 #define LCD_D5 40 #define LCD_D6 41 #define LCD_D7 42
Declare a static instance of the LCD controller class and preconfigure it with appropriate control GPIOs:
static Adafruit_LiquidCrystal lcd(LCD_RS, LCD_ENABLE, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
Initialise class with display area configuration (number of columns, here 16 and rows, here 2):
lcd.begin(16,2);
Implement your algorithm. The most common class methods that will help you are listed below:
.clear()
- clears all content;.setCursor(x,y)
- set cursor, writing will start there;.print(contents)
- prints text in the cursor location; note there are many overloaded functions, accepting various arguments, including numerical.You should be able to see “Hello World” and “Hello IoT” on the LCD now.