This repository contains a custom lcd driver for 16x02 lcd. The driver has the most common function calls
that are use for LCDs. ESP32 have limited GPIO pins, therefore 4-bit mode was use as it requires a total of 6 GPIO
pins. However, there are two configurations for the driver: default and custom. The default configurations uses this pinout while the custom allows the user to select whichever GPIO
are avaiable simple by using lcdCtor()
.
+-----------------------+
| O | USB | O |
| ------- |
3V3 | [ ] [ ] | VIN
GND | [ ] [ ] | GND
Touch3 / HSPI_CS0 / ADC2_3 / GPIO15 | [ ] [ ] | GPIO13 / ADC2_4 / HSPI_ID / Touch4
CS / Touch2 / HSPI_WP / ADC2_2 / GPIO2 | [ ] [ ] | GPIO12 / ADC2_5 / HSPI_Q / Touch5
Touch0 / HSPI_HD / ADC2_0 / GPIO4 | [ ] [ ] | GPIO14 / ADC2_6 / HSPI_CLK / Touch6
U2_RXD / GPIO16 | [ ] [ ] | GPIO27 / ADC2_7 / Touch7
U2_TXD / GPIO17 | [ ] [ ] | GPIO26 / ADC2_9 / DAC2
V_SPI_CS0 / GPIO5 | [ ] ___________ [ ] | GPIO25 / ADC2_8 / DAC1
SCK / V_SPI_CLK / GPIO18 | [ ] | | [ ] | GPIO33 / ADC1_5 / Touch8 / XTAL32
U0_CTS / MSIO / V_SPI_Q / GPIO19 | [ ] | | [ ] | GPIO32 / ADC1_4 / Touch9 / XTAL32
SDA / V_SPI_HD / GPIO21 | [ ] | | [ ] | GPIO35 / ADC1_7
CLK2 / U0_RXD / GPIO3 | [ ] | | [ ] | GPIO34 / ADC1_6
CLK3 / U0_TXD / GPIO1 | [ ] | | [ ] | GPIO39 / ADC1_3 / SensVN
SCL / U0_RTS / V_SPI_WP / GPIO22 | [ ] | | [ ] | GPIO36 / ADC1_0 / SensVP
MOSI / V_SPI_WP / GPIO23 | [ ] |___________| [ ] | EN
| |
| | | ____ ____ | |
| | | | | | | | |
| |__|__| |__| |__| |
| O O |
+-----------------------+
The following pinout is the default configuration of the ESP-LCD driver. However, the driver is customizable to allow users to change GPIO pins if necessary.
ESP32 Pins | LCD Pin | Description |
---|---|---|
GND , 10k Potentiometer Output (V±) |
1 | GND |
VCC , 10k Potentiometer Output (V±) |
2 | VCC |
10k Potentiometer Output (Vo) | 3 | Contrast |
GPIO23 |
4 | RS (Register Select): 0–Command, 1-Data |
GND |
5 | R/W (Read/Write): 0 – Write, 1 - Read |
GPIO22 |
6 | Clock Enable |
NC |
7 | Data 0 |
NC |
8 | Data 1 |
NC |
9 | Data 2 |
NC |
10 | Data 3 |
GPIO19 |
11 | Data 4 |
GPIO18 |
12 | Data 5 |
GPIO17 |
13 | Data 6 |
GPIO16 |
14 | Data 7 |
100Ω to VCC |
15 | Backlight Anode (+) |
GND |
16 | Backlight Cathode (-) |
- LCD default pin configuration
Function | Description |
---|---|
lcdDefault | Default pinout |
lcdCtor | Customizable pinout constructor |
lcdSetText | Set text |
lcdSetInt | Set integer |
lcdClear | Clear previous data |
lcdFree | Free LCD pins |
assert_lcd | Check lcd status |
The follow section of code demostrate how to use the lcd driver with default configuration.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/esp_lcd.h"
/* LCD task */
void lcd_task(void *pvParameters){
/* Create LCD object */
lcd_t lcd;
/* Set lcd to default pins */
lcdDefault(&lcd);
/* Initialize LCD object */
lcdInit(&lcd);
/* Clear previous data on LCD */
lcdClear(&lcd);
while(1){
/* Display text */
lcdSetText(&lcd,"Hello World!", 0,0);
/* 1 second delay */
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
/* Create LCD task */
xTaskCreate(lcd_task, "LCD task", 2048, NULL, 4, NULL);
}
- Copy driver folder
- Paste into esp project
- Edit project CMakeLists.txt to use esp_lcd:
idf_component_register(SRCS "main.c"
"driver/esp_lcd.c"
INCLUDE_DIRS ".")
Microcontroller | Software | Enviroment | Operating System |
---|---|---|---|
License | Release |
---|---|