LCD 1602 Driver with ESP32 I2C 1.1
This is a complete driver for LCD 1602 using I2C with the ESP32
Loading...
Searching...
No Matches
LCD 16X2 I2C ESP32 Driver

About the project

A complete driver for Hitachi compatible 16 x 2 modules with the i2c expander on ESP32. The driver runs the LCD in 4-bit mode and exposes a small and easy to use API for initialization and writing.

Functions

  • Automatic background light (controlled by the i2c expander-pins)
  • Logic for handling
    and character overflow.

Pre-requisites

ESP-IDF

Espressifs IoT development framework, which contains all the essential dependencies for this project. You can find a guide for installing it here: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/index.html

ESP32 device

You can use any device, but might need to configure the pins.

LCD 1602

Make sure it's Hitachi 44780 compatible and has a I2C expander.

GCC and Cmake

For compiling and building the project.

GCC For windows
Guide for windows

GCC For Mac
brew install gcc

GCC For Linux
sudo apt-get install gcc

Cmake
This is our build tool for the project and routinely used for raspberry pi pico projects.

You can download it here

Pinout

The driver standard pinout is set in lcd_i2c.h:

#define I2C_MASTER_SCL_IO GPIO_NUM_2
#define I2C_MASTER_SDA_IO GPIO_NUM_3

Example of circuit for this driver

Example of circuit schematic for this project

Installation

1. Clone the project

Clone this project into components/ in your project. ESP-IDF will automatically recognize the file and it can then be used in your project.

git clone https://github.com/lafftale1999/lcd_1602_i2c_driver.git

API-reference

lcd_1602_init()
Initializes the LCD according to the datasheet. Returns 0 if successful.

uint8_t lcd_1602_init(i2c_master_dev_handle_t handle);
uint8_t lcd_1602_init(i2c_master_dev_handle_t handle)
initializes the LCD 1602 correctly according to the datasheet.
Definition lcd_1602.c:141

lcd_1602_send_string()
Writes out string on the display. Returns LCD_WRITE_FINISHED if successful. LCD_WRITE_INTERRUPTED if string is too long for screen.

LCD_WRITE_STATUS lcd_1602_send_string(i2c_master_dev_handle_t handle, char *str);
LCD_WRITE_STATUS lcd_1602_send_string(i2c_master_dev_handle_t handle, char *str)
Writes out data to the LCD.
Definition lcd_1602.c:111
LCD_WRITE_STATUS
Enum for returning the result of writing to the LCD.
Definition lcd_1602.h:58

Macros

These can be changed to fit your own project.

#define DEVICE_ADDRESS 0x27
#define LCD_1602_SCREEN_CHAR_WIDTH 16
#define LCD_1602_MAX_ROWS 2

Build and flash

This project is not made to build on its own, it needs to be incorporated into a bigger system with a CMake build file.

About the author

I'm currently studying to become an embedded developer and learning about writing drivers based on datasheets from manufacturers. If you have any questions please feel free to reach out!