HD44780 LCD to I2C adapter board for the Bus Pirate

Cheap character LCDs based on the HD44780 chipset come in a variety of sizes: 2x16, 4x20, etc. These displays have two standard interface modes, 4bit and 8bit parallel. 8bit requires a total of 11 data lines, 4bit requires 7 (6 for write-only). Some LCDs support an additional serial data mode, like the VFD I covered at Hack a Day.

HD44780 LCDs are generally 5volt parts with a separate supply for the back light. The Bus Pirate only has five 5volt tolerant I/O pins, so we made a small adapter board with enough pins to control the LCD. The Bus Pirate controls the adapter board through its LCD interface library.

Full size circuit image [PNG]. The circuit and PCB were designed with the free version of Cadsoft Eagle. The design files can be downloaded from the Bus Pirate SVN. Before using the adapter board, be sure to verify the datasheet for your LCD against the adapter pinout. Not all LCDs are the same.

PCF8574 I/O expander IC

This is a simple 8 I/O expander chip that's controlled through the two-wire I2C interface. The I2C interface is accessible from header JP1.

The PCF8574 works from 2.5 to 5volts. The I/O pins operate at the supply voltage, so if we feed it 5volts it interfaces the LCD at 5volts. C1 (0.1uF) decouples the IC from fluctuations in the power supply.

One pin of the PCF8574 controls a 3mm LED (LED1) through current limiting resistor R2 (1000 ohms). The LED lights to indicate successful communication between the Bus Pirate and the adapter. The PCF8574 can't source enough current to power the LED, so we power the LED from the 5volt supply and switch the ground.

LCD

The adapter board communicates with an HD44780-based character LCD in 4bit parallel interface mode. The 4bit interface pins - RS, RW, EN, and D4-D7 - are connected to seven of the PCF8574 I/O pins. We like to use 0.1" male pin header to connect the adapter to an LCD, you can usually lean the LCD against the pins to create sufficient contact for a quick test.

We didn't connect the backlight pins because there's so many different backlight styles. Providing power for an LED backlight might damage a screen that requires a negative voltage supply.

Power supply

Most LCDs require 5volts, provide an external power supply through header JP2. We provided a second power supply pin to connect the Bus Pirate's pull-up resistors.

PCB

The circuit and PCB were designed with the free version of Cadsoft Eagle. The design files can be downloaded from the Bus Pirate SVN. The PCB is a single-sided, all through-hole design with a single jumper wire (shown in red).

We can have PCBs, kits, or assembled kits produced by Seeed Studio for about $15, including worldwide shipping, more here.

Press 'm' in the Bus Pirate terminal and choose the LCD library. It currently it only supports HD44780 character LCDs using the PFC8574 adapter described in the first half of this article (option 1).

Enable the power supplies (big 'W') and pull-up resistors (menu 'p'). Check the voltage monitor (menu 'v') and make sure that the pull-up voltage (Vpullup) reads around 5volts.

Step 4 Step 2. Reset and initialization

This table outlines the single-byte commands that control an HD44780 LCD, here's a detailed reference. These commands can be entered from the Bus Pirate command line, but we've made macros for most of them to save time.

Theinitialize LCD macro (2) configures the screen for 4bit interface mode, enables cursor display, and sets a few other helpful options. Configure the number of display lines, choose 1 for a single line display, or 2 for all other displays.

After initialization, the screen should be clear with a cursor visible in the corner. If it didn't work, check the I2C connection, pull-up resistors, and power supply, then try again.

HD44780 LCDs need to be reset with a special signal sequence before they can be initialized for 4bit or 8bit interface mode. Macro 1 creates this sequence. Macro 2 includes the reset sequence, so there's no need to use macro 1 before macro 2.

Step 5 Step 3. Write test characters

LCD>(6:80)<<<write 80 numbers LCD>

Thewrite numbers macro fills the LCD with test numbers between 0 and 9. The number after the colon tells the Bus Pirate how many test numbers to write, we're using a 4x20LCD, so we write 80 numbers to fill it. Notice that the cursor ends at position 0, under the first '0'.

LCD>(7:80)<<<write 80 charactersLCD>

Thewrite characters macro fills the LCD with ASCII characters, enter the quantity after the colon. Notice that the fist line continues on the third, the third on the second, and the second on the last. The characters aren't continuous because character LCDs don't wrap from one line to the next. We'll talk a little more about this later.

Step 6 Step 4. Clear LCD

LCD>(3)<<<clear the LCDCLEAREDLCD>

Theclear LCD macro sends the HD44780 command that erases the screen and returns the cursor to the first position.

You could also do any of these operations without the macros, refer to the command table at the beginning of this section. Enter '[0b1' in the Bus Pirate to set the interface to command mode ([) and send the HD44780 clear screen command (0b00000001) without a macro.]

Writing to the second line is a little more complicated, it actually starts at character 64 on a 4x20 LCD. If you continue writing from the end of line 1 (character 20) then you'll end up at the beginning of line three! This page has a nice collection of memory maps for most character LCD sizes.

First, we position the cursor on the second line (4:0x40). Next, the 'insert text' macro grabs our input and copies it to the LCD.

The Bus Pirate accepts multiple macros on the same line, so the entire screen can be written at once. We wrote to the last two lines with a single line of syntax.

We could use '(3)(4:0)(8)(4:0x40)(8)(4:0x14)(8)(4:0x54)(8)' to clear the LCD and write all four lines with a single syntax entry.

Step 8 Step 6. Reading from the LCD

The Bus Pirate and LCD adapter board can read from the LCD. We'll read the text we wrote to the screen (DDRAM), but you can also read settings and custom character ram (CGRAM) by setting the correct address.

First, we tell the Bus Pirate to send data to the LCD command register ([). Next, we use the set DDRAM address command (0b1xxxxxxx) to set the read pointer to the beginning of the DDRAM (xxxxxxx=0000000).]