ESP32 Nokia 5110 LCD Display Tutorial | Display Text, Adjust Contrast
In this project, we’ll discover how to connect an ESP32 DevKit Development Board to a Nokia 5110 LCD. The Nokia 5110 LCD, the Phillips PCD8544 Driver IC, the operation of the ESP32 Nokia 5110 Interface, and the display of some text and graphics on the Nokia 5110 LCD using ESP32 will all be briefly discussed.
Introduction
If you wish to display animations, bespoke symbols, various types and sizes of typefaces, and many other graphic-related items, graphical displays are quite helpful (shapes, symbols).
Today, we have larger, more vibrant, and sometimes even touch-enabled graphic screens. But what if you prefer a more affordable, straightforward monitor with a good resolution?
For this, the Nokia 5110 LCD Module is an excellent option. The Nokia 5110 LCD, which was first used in the Nokia 3110 and Nokia 5110 Mobile Phones, has grown in popularity among do-it-yourselfers because of its inexpensive price, small size, and straightforward interface.
The Nokia 5110 LCD is a must-use display device in our projects because of this and the support from the Arduino Community (and other open-source communities) for drivers.
Nokia 5110 LCD
The Philips PCD8544 LCD Controller IC serves as the foundation for the Nokia 5110 LCD Module. It can drive 84 columns and 48 rows, which ironically corresponds to the Nokia 5110 LCD’s resolution of 8448 pixels.
Each of the six banks in the internal 504 bytes of SRAM on the PCD8544 can hold 84 bytes of data.
So, 6 Banks * 84 Bytes = 504 Bytes.
It’s crucial to keep in mind that the Nokia 5110 LCD and PCD8544 Controller both require a 3.3V supply. Since we are using ESP32, a 3.3V device, this won’t be a problem. But if you want to utilise an Arduino (or another 5V microcontroller) with a Nokia 5110 LCD, you must do the appropriate logic level conversions.
I created a guide specifically for connecting an Arduino to a 5110 LCD. If you intend to utilise Nokia 5110 LCD with Arduino, take a look at it.
Additionally, the Nokia 5110 LCD Module offers a variety of backlight colour choices, including red, blue, white, yellow, and green. I received the blue backlight model in my case.
ESP32 Nokia 5110 LCD Interface
enough theory Let’s move further with connecting the Nokia 5110 to the ESP32. But first, let’s quickly review the Nokia 5110 Module’s pinout. The pinout of the Nokia 5110 LCD is displayed in the following table and graphic.
| Pin Number | Pin Name | Pin Description |
| 1 | RST | External Reset Input |
| 2 | CE | Chip Enable |
| 3 | DC | Data / Command |
| 4 | DIN | Serial Data Input |
| 5 | CLK | Serial Clock Input |
| 6 | VCC | Supply Voltage |
| 7 | BL | Backlight Supply |
| 8 | GND | Ground |
Nokia 5110 LCD with Pinout
As you can see from the image, the Nokia 5110 LCD (or more precisely, the PCD8544 Controller) communicates with a microcontroller using a serial interface that resembles SPI. Therefore, we must use the ESP32 Microcontroller’s SPI pins.
Two of the four SPI connections on the ESP32 SoC are connected to the flash IC. Thus, there are just two hardware SPI interfaces left. HSPI and VSPI are what they are. You can use the ESP32 Pinout image below as a guide.
In this project, I’ll be utilising the VSPI interface. The hardware VSPI interface’s MOSI, CLK (SCK), and CS pins are required. Any ESP32 GPIO pin can be linked to the Reset (RST) and Data / Command (DC) pins of the Nokia 5110 LCD.
Thus, the final connections between the ESP32 and the Nokia 5110 LCD appear as follows:
| Nokia 5110 LCD | ESP32 DevKit Board |
| RST | GPIO 2 (D2) |
| CE | GPIO 15 (D15) |
| DC | GPIO 4 (D4) |
| DIN | GPIO 23 (D23) |
| CLK | GPIO 18 (D18) |
| VCC | 3.3V |
| BL | 3.3V (through 220Ω Resistor) |
| GND | GND |
NOTE: Instead of using VSPI_CS, I used HSPI_CS. But no worries.
You can use another GPIO pin to control the LCD’s backlight, but I chose to have it always on, so I linked the Nokia 5110 LCD’s “BL” pin to a 3.3V supply with a 220 current-limiting resistor.
Components Required
- ESP32 DevKit Development Board
- Nokia 5110 LCD Module
- Breadboard
- Connecting Wires
- Micro-USB Cable
Circuit Diagram
The connection of the ESP32 Nokia 5110 LCD interface is shown in the next image.
Preparing Arduino IDE
Adafruit PCD8544 Nokia 5110 LCD Library and Adafruit GFX Library are two libraries that you must download in order to use the Nokia 5110 LCD with the Arduino IDE. You can skip this step if you’ve already loaded these libraries and worked with the Nokia 5110 LCD.
In the Arduino IDE, select Tools -> Manage Libraries. . . to open the library manager.
Utilize the search bar to look for “pcd8544” and download the “Adafruit PCD8544 Nokia 5110 LCD Library”.
You must utilise the Adafruit GFX library to show little images, such as various shapes and symbols. Install the “Adafruit GFX” library and perform a “gfx” search. You can close the library manager after installing both libraries.
Testing Nokia 5110 LCD with ESP32
Connect the ESP32 to the computer by making all the connections as previously mentioned. Make sure ‘ESP32 Dev Module’ is chosen under Tools -> Board. Additionally, utilise the right COM port.
In the first programme, I’m just showing two different-sized texts on the Nokia 5110 LCD.
Code
| Â | #include <SPI.h> |
| Â | #include <Adafruit_GFX.h> |
| Â | #include <Adafruit_PCD8544.h> |
| Â | Â |
| Â | /* Declare LCD object for SPI |
| Â | Adafruit_PCD8544(CLK,DIN,D/C,CE,RST); */ |
| Â | Adafruit_PCD8544 display = Adafruit_PCD8544(18, 23, 4, 15, 2); |
| Â | int contrastValue = 60; // Default Contrast Value |
| Â | const int adcPin = 34; |
| Â | int adcValue = 0; |
| Â | Â |
| Â | void setup() |
| Â | { |
| Â | /* Initialize the Display*/ |
| Â | display.begin(); |
| Â | Â |
| Â | /* Change the contrast using the following API*/ |
| Â | display.setContrast(contrastValue); |
| Â | Â |
| Â | /* Clear the buffer */ |
| Â | display.clearDisplay(); |
| Â | display.display(); |
| Â | delay(1000); |
| Â | Â |
| Â | /* Now let us display some text */ |
| Â | display.setTextColor(WHITE, BLACK); |
| Â | display.setCursor(0,1); |
| Â | display.setTextSize(2); |
| Â | display.println(“|ESP32|”); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(BLACK); |
| Â | display.setCursor(22,20); |
| Â | display.println(“|Nokia|”); |
| Â | display.setCursor(22,32); |
| Â | display.println(“|5110|”); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | } |
| Â | Â |
| Â | void loop() |
| Â | { |
| Â | /* You can implement your own display logic here*/Â |
| Â | } |
This basic code demonstrates how simple it is to use the ESP32 to show text on the Nokia 5110 LCD. You can also experiment with other options, such as showing text in both normal and reversed forms and changing the font and size.
Adjust Contrast of the Display
You can digitally modify the display’s contrast using the function “setContrast” on the Nokia 5110 LCD, which is one of its handy features. If you prefer a software control of the contrast than a manual adjustment (as in a 162 Character LCD), this is quite useful.
So I created a tiny circuit and attached a 5 K POT to ESP32’s ADC1 channel 6. I’m also adjusting the contrast of the Nokia 5110 LCD Display based on the ADC’s output.
One thing to keep in mind is that the ESP32’s ADC has a 12-bit resolution. In other words, the ADC conversion’s output digital values will range from 0 to 4095. However, the Nokia 5110 LCD can only accept contrast levels between 0 and 100.
If you’ve previously used ADC and PWM in Arduino, there is a function called “map” that converts one set of integers into another set (in this case from 0 – 4095 to 0 – 100). This function must be used in our code.
Circuit Diagram
The circuit for altering the contrast of the Nokia 5110 LCD using a potentiometer is shown in the accompanying figure.
Code
| Â | #include <SPI.h> |
| Â | #include <Adafruit_GFX.h> |
| Â | #include <Adafruit_PCD8544.h> |
| Â | Â |
| Â | /* Declare LCD object for SPI |
| Â | Adafruit_PCD8544(CLK, DIN, D/C, CE, RST); */ |
| Â | Adafruit_PCD8544 display = Adafruit_PCD8544(18, 23, 4, 15, 2); |
| Â | Â |
| Â | int contrastValue = 57; // Default Contrast Value |
| Â | const int adcPin = 34; |
| Â | int adcValue = 0; |
| Â | Â |
| Â | void setup() |
| Â | { |
| Â | /* Initialize the Display*/ |
| Â | display.begin(); |
| Â | Â |
| Â | /* Change the contrast using the following API*/ |
| Â | display.setContrast(contrastValue); |
| Â | Â |
| Â | displayText(); |
| Â | delay(1000);Â Â Â |
| Â | } |
| Â | Â |
| Â | void loop() |
| Â | { |
| Â | adcValue = analogRead(adcPin); |
| Â | contrastValue = map(adcValue, 0, 4095, 0, 100); |
| Â | setContrast(); |
| Â | displayText(); |
| Â | Â |
| Â | } |
| Â | Â |
| Â | void setContrast() |
| Â | { |
| Â | display.setContrast(contrastValue); |
| Â | //display.display(); |
| Â | } |
| Â | Â |
| Â | void displayText() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextColor(WHITE, BLACK); |
| Â | display.setCursor(0,1); |
| Â | display.setTextSize(2); |
| Â | display.print(“|ESP32|”); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(BLACK); |
| Â | display.setCursor(8,22); |
| Â | display.print(“SET CONTRAST”); |
| Â | display.drawFastHLine(0,32,83,BLACK); |
| Â | display.setCursor(5, 38); |
| Â | display.print(“Value: “); |
| Â | display.setCursor(40,38); |
| Â | display.print(contrastValue); |
| Â | display.display(); |
| Â | } |
Conclusion
I hope all of you had understand how to connect an ESP32 DevKit Development Board to a Nokia 5110 LCD. We MATHA ELECTRONICS will be back soon with more informative blogs soon.