Skip to content
/ i2c-lcd Public

Small library for interacting with HD44780U displays via I2C bus

License

Notifications You must be signed in to change notification settings

a13x5/i2c-lcd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i2c-lcd

Really small library for working with HD44780U LCD with PCF8574T I2c expander card.

Tested on Raspberry Pi 5.

Rationale

My goal was to learn how to work with the LCD, since I wanted to use it in my project.

Unfortunately there is not much of a documentation out there on how this actually works. Usually all manuals are like: “just use RPLCD”.

And if Python is not an option, you have to write all from scratch, this is exactly what I did here.

Using this code

Just run make to build everything including example program.

To check LCD’s I2c bus and address the i2c-detect tool could be used.

To get list of i2c buses (on RPi 5 i2c-1 is the one connected to GPIO):

$ i2cdetect -l
i2c-1   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-11  i2c             107d508200.i2c                          I2C adapter
i2c-12  i2c             107d508280.i2c                          I2C adapter

To check exact I2c address the following command could be used:

$ i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

In the example it’s 0x27, the same is used in the example.c.

LCD layout and operations

Layout

LCD layout with I2c expander card on the PCF8574T chip looks like this:

8 / 0x807 / 0x406 / 0x205 / 0x104 / 0x083 / 0x042 / 0x021 / 0x01
DB7DB6DB5DB4BLERWRS

As you can see only 4 data pins (DB4-DB7) are exposed, so display should be initialized in 4 bit mode.

Backlight pin BL should be set to desired value on all operations. Otherwise it will be blinking.

Pin E is used for clock and it’s always used when data is transfered.

RW is used to set read or write operation. I use only write operations.

And RS is used for setting data or instructions mode. High means data.

Operations

On Linux for interacting with I2c from userspace i2c-dev.h is used. It’s described pretty thoroughly in the docs.

Before LCD could be used is should be initialized (in our case in 4bit mode). This is described in detail on pages 23 and 46 of HD44780 datasheet.

After initializing all data should be transfered in 2 parts 4 bits each 3 times with manual clocking. For details look and the page 22 of the datasheet.

Custom characters

HD44780U has an ability to use custom characters (see the manual page 19).

Custom characters are written into to CGRAM, so the have to be written each time display is restarted.

Each character must be defined with specific 3 bit address (since only 8 custom characters are supported). Character map must consist of 8 chunks of 5 bit data.

This stands for 5 dots to 8 lines which depict each character.

To ease generation of such characters lcdchargen app could be used.

After defining characters return_home function must be executed again.

References

About

Small library for interacting with HD44780U displays via I2C bus

Resources

License

Stars

Watchers

Forks