Bus Pirate LCD adapter v2

From DP

Jump to: navigation , search
Project Summary
Name: Bus Pirate LCD adapter v2
Buy it: Get one for $9 at Seeed Studio
Price: $9
Status: Test production
Manufacturing: Shipping
Forum: Bus Pirate LCD adapter v2 Forum
BusPirateLCDv2.jpg


Control HD44780 LCDs from the Bus Pirate with this breakout board (v3 only!, adapter for v4 coming soon). The Bus Pirate LCD mode uses an adapter because there aren't enough pins to directly control a character display.

You can build the adapter with a few parts and a bread board, or you can buy it ready-made at Seeed Studio for $9. Includes a short connector cable. Every sale directly supports open source development of the Bus Pirate.

  • HD44780 LCD adapter v2 for the Bus Pirate

Contents

Overview

Lcdv2-overview.jpg

It takes at least 6 pins to control a common character LCD based on the HD44780 chipset. The Bus Pirate only has five free pins, so we made a small adapter board to test LCDs. The adapter has an 8 pin output expander, standard LCD connector, and other stuff LCDs usually need like a contrast adjustment resistor.

The v2 LCD adapter is a major update from v1. V1 was never produced because the parts were too expensive. The new surface mount design using a simple shift register is much cheaper and much faster than v1. LCD adapter v2 requires firmware v5.4+.

Requirements

  • Bus Pirate v3 or v2go
  • Firmware v5.4+

Using it

Connections

Connect the Bus Pirate to the LCD adapter with a 10 pin ribbon cable.

Connect an HD44780 LCD to the 1x16 header on the adapter. Most character LCDs use the same pinout, but be sure to verify the voltage and pinout before starting.

Backlight

Lcdv2-backlight.jpg

The LCD adapter doesn't power the backlight directly. There are lots of different backlights - some need a resistor, some need negative voltages, some just use too much current for the Bus Pirate to supply. To make the adapter compatible with the maximum number of LCDs, it simply brings the backlight pins to headers BLA (anode, +) and BLC (cathode, -).

Jumpers can be placed over the BLA and BLC headers to connect them to +5volts and ground (respectively). Be sure your backlight doesn't need a resistor, and won't exceed the Bus Pirate maximum current (<150mA).

Jumper BLA to connect pin 15 to ground
Jumper BLC to connect pin 16 to +5volts (150ma max)

Contrast adjust

Lcdv2-contrast.jpg

Turn potentiometer R1 to adjust the LCD contrast as needed.

Bus Pirate setup

Bus-pirate-terminal.png

Open a terminal to the Bus Pirate.

LCD adapter v2 requires firmware v5.4+

HiZ> m <<<select mode
1. HiZ
...
9. LCD
x. exit(without change)
(1)> 9 <<<LCD mode
This mode requires an adapter
Ready
LCD>

Press 'm' in the Bus Pirate terminal and choose the LCD mode. Firmware v5.4+ supports HD44780 character LCDs using adapter v2.

LCD> W <<<power supplies on
Power supplies ON
LCD> v <<<check voltages
Pinstates:
GND 3.3V 5.0V
GND 3.35V 5.00V
LCD>

Enable the power supplies (W) to power the adapter and the LCD. Check the voltage monitor (menu 'v') and make sure the 5volt monitor reads around 5volts.

Remember that the adapter is intended for 5volt LCD displays only.

LCD mode macros

HD44780 Instructions
Instruction RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
Clear display 0 0 0 0 0 0 0 0 0 1
Cursor home 0 0 0 0 0 0 0 0 1 x
Entry mode set 0 0 0 0 0 0 0 1 I/D S
Display on/off control 0 0 0 0 0 0 1 D C B
Cursor/display shift 0 0 0 0 0 1 S/C R/L x x
Function set 0 0 0 0 1 DL N x BR1 BR0
CGRAM address set 0 0 0 1 CGRAM address
DDRAM address set 0 0 1 DDRAM address
Address counter read 0 1 BF=0 AC contents
DDRAM or CGRAM write 1 0 Write data
DDRAM or CGRAM read 1 1 Read data

x=don't care

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.

LCD> (0) <<<macro menu
0.Macro menu
1.LCD Reset <<<reset the LCD
2.Init LCD <<<initialize the LCD
3.Clear LCD <<<clear the display
4.Cursor position ex:(4) 0 <<<set the cursor position
6.Write test numbers ex:(6) 80
7.Write test characters ex:(7) 80
LCD>

Macro 0 displays the macro menu for any Bus Pirate mode.

LCD reset and initialization

Lcd-clear.jpg

LCD> (2) <<<initialize LCD macro
RESET <<<macro 2 includes macro 1/reset
Display lines:
1. 1 <<<single line displays
2. Multiple <<<all other displays
(2)> 2 <<<set display lines
INIT
LCD>

HD44780 LCDs need to be reset with a special signal sequence before they can be initialized for 4bit or 8bit interface mode. Macro 1, LCD Reset, creates this sequence.

Macro 2, initialize LCD, configures the screen for 4bit interface mode, enables cursor display, and sets a few other helpful options. Macro 2 includes the reset sequence, so there's no need to use macro 1 before macro 2.

To initialize the display, enter (2) into the Bus Pirate terminal. Configure the number of display lines when prompted: 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. LED 1 on the adapter should light to indicate successful communication with the Bus Pirate. If it didn't work, check the contrast adjustment, adapter connection, and power supply, then try again.

Write text

Lcd-text-1.jpg

LCD> "HD44780 LCD demo" <<<text to display
WRITE: "HD44780 LCD demo"
LCD>

After reset the LCD cursor is positioned at the first block on the display. This is address 0 (see the table below).

Use the Bus Pirate string syntax to write text to the display. Text entered between " and " is sent to the LCD.

Position the cursor

Display memory (DDRAM) addresses for a 4-line LCD
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53
14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67

LCD> (4) 0x00 <<<set cursor to first character
CURSOR SET
LCD>

The cursor position can be set with macro (4). Use (4) 0 to set the cursor to the first block of the display (remember, numbering starts at 0). Use (4) 2 to set the cursor at the third position.

Writing to the second, third, and fourth lines is a little more complicated. The numbering on the LCD is not continuous. On a 4x20 LCD the second line actually starts at character 64 (0x40), not 20 (0x14). If you continue writing from the end of line 1 (character 19/0x13) then you'll end up at the beginning of line three!

On a typical 4x20 HD44780 LCD, the characters are mapped as shown in the table above. The first character of the first line starts at 0x00, the second line starts at 0x40 (64), the third 0x14 (20), and the last 0x54 (84). Here are memory maps for common character LCD sizes.

Lcd-text-2.jpg

LCD> (4) 0x40 <<<set cursor to line 2
CURSOR SET
LCD> "Bus Pirate v3" <<<send text to the LCD
WRITE: "Bus Pirate v3"
LCD>

Use (4) 0x40 to position the cursor at the beginning of line two. Text between " and " is displayed on the second line of the LCD.

Lcd-text-3.jpg

LCD> (4) 0x14 "Firmware v5.4+" (4) 0x54 "DangerousPrototypes"
CURSOR SET
WRITE: "Firmware v5.4+"
CURSOR SET
WRITE: "DangerousPrototypes"
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) 0x00 "Line 1" (4) 0x40 "Line 2" (4) 0x14 "Line 3" (4) 0x54 "Line 4" to clear the LCD and write all four lines with a single syntax entry.

Clear LCD

Lcd-clear.jpg

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

The clear LCD macro sends the HD44780 command to erase the screen. The cursor returns 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.

Test numbers

Lcd-numbers.jpg

LCD> (6) 80 <<<write 80 test numbers
01234567890123456789012345678901234567890123456789012345678901234567890123456789
LCD>

Macro 6 fills the LCD with test numbers between 0 and 9. The number after the macro tells the Bus Pirate how many test numbers to write, default is 80. 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'.

Test characters

Lcd-characters.jpg

LCD> (7) 80 <<<write 80 test characters
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop
LCD>

Macro 7 fills the LCD with ASCII characters. The trailing values indicates how many characters to write, the default is 80.

Notice that the first 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.

Get one

LCDadapterv2.jpg

The LCD adapter is easy to build on a breadboard with a few components. You can also buy an assembled version, and kick a few dollars to the open source project behind the Bus Pirate.

The LCD adapter v2 for the Bus Pirate is available at Seeed Studio for $9. Each sale directly supports this open source project.

Hardware

Lcdv2-cct.png

Click for a larger schematic image. The circuit and PCB were designed with the free version of Cadsoft Eagle. The design files can be downloaded from the Bus Pirate project.

The circuit is simple enough to build on a breadboard. We used a single shift register and 4bit mode instead of two in 8bit mode because it would be easier to make a single-chip circuit on a breadboard.

Before using the adapter board, be sure to verify the datasheet for your LCD against the adapter pinout. Not all LCDs are the same.

HD44780 LCD

LCDv2-HD44780header.jpg


Common HD44780 pinout
12345678910111213141516
GND+5voltContrastRSRWEND0D1D2D3D4D5D6D7BLA(+)BLC(-)
  1. Ground
  2. VCC (+5V)
  3. Contrast adjustment (VO)
  4. Register Select (RS). RS=0: Command, RS=1: Data
  5. Read/Write (R/W). R/W=0: Write, R/W=1: Read
  6. Clock (Enable). Falling edge triggered
  7. Bit 0 (Not used in 4-bit operation)
  8. Bit 1 (Not used in 4-bit operation)
  9. Bit 2 (Not used in 4-bit operation)
  10. Bit 3 (Not used in 4-bit operation)
  11. Bit 4
  12. Bit 5
  13. Bit 6
  14. Bit 7
  15. Backlight Anode (+)
  16. Backlight Cathode (-)

source: Wikipedia:HD44780 Character LCD

Character LCDs have two standard interface modes, 4bit and 8bit parallel. 8bit requires a total of 11 data lines for control, while 4bit requires only 7. Each mode requires one less pin if we hard-wire it for write-only. Some LCDs support an additional serial data mode, like the VFD Ian covered at Hack a Day.

Most HD44780 LCDs use a 1 row by 16 pin connector with the signals shown in the table. Some smaller LCDs have a 2x8 pinout, these will not work with the adapter directly.

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 74HCT595 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.

The adapter provides +5volts through pin 2 to power the LCD. Pin 1 is connected to ground.

Contrast adjustment

LCDv2-contrast.jpg

Most LCD character displays have a contrast adjustment pin. A 10K ohm potentiometer (R1) connected between 5volts and ground provides a contrast voltage to pin 3 of the LCD header.

Backlight header

Lcdv2-backlightheader.jpg

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.

The round via closest to the edge of the board connects to the backlight pins. The interior square vias connect to +5volt and ground.

The LCD backlight pins are brought to two headers, BLA and BLC, that can be connected to the proper external supply.

  • BLA is pin 15, the most common backlight anode (positive supply). The other pin of BLA is connected to +5volts.
  • BLC is pin 16, commonly the backlight cathode (ground). The other pin of BLC is connected to ground.

If your backlight uses less than 150mA of current at 5volts with no current limiting resistor, then these pins can be jumpered for direct supply of the backlight. BLA and BLC are spaced one row apart to prevent incorrect connections.

74HCT595 shift register

Lcdv2-595.jpg

In 4bit mode the HD44780 LCD requires a minimum of 6 pins to interface. The Bus Pirate only has five digital outputs, it comes up one short.

The LCD adapter uses a 74HCT595 shift register (IC1) to get 8 outputs from only three control pins. The '595 is a classic 7400 series logic device that's plentiful and inexpensive. One limitation is that we use the chip as an output only, it's not possible to read from the LCD.

The '595 is powered by the Bus Pirate's 5volt supply, the power pins gets a 0.1uF decoupling capacitor (C1). The decision to be 5volts-only is partly because the 5volt supply pin is the same position on v2go and v3, but the 3.3volt pin is swapped.

The HCT logic family was used because an HCT chip running from a 5volt supply can be controlled from a Bus Pirate running at 3.3volts. HCT only needs 2.0volts on a pin to register a high-state, so it's compatible with the Bus Pirate outputs.

Astute observers will note that the picture shows a 74HC595 logic chip. HC logic running from a 5volt supply requires 3.5volts minimum to register a high-state, thus is is technically out of spec with the Bus Pirate's 3.3volt normal output. A HC part worked fine in our prototype, but there would be lots of failures when scaled to production levels.

There are seven connections from the 74HCT595 to the LCD:

  • four data bits (D7-D4)
  • read/write (RW)
  • register select (RS)
  • enable (EN)

Read/write is not required and could be hard-wired in the write position.

Three Bus Pirate pins drive the 595:

  • Data out from the Bus Pirate (MOSI)
  • Clock out from the Bus Pirate (CLK)
  • Data latch, moves data to 595 pins (CS)

LED1 lights after the Bus Pirate successfully communicates with the adapter. LED1 is connected to pin A (the least significant bit) of the 595. It draws 3mA with current limiting resistor R2 (1Kohm), which is within the 74HCT595 limit of 35mA.

PCB

Bp-lcdv2-brd.png

The circuit and PCB were designed with the free version of Cadsoft Eagle. The design files can be downloaded from the [Bus Pirate project].

Seeed Studio sells an assembled version of the LCD adapter. Buy one for $9, each sale supports this open source project.

Partlist

PartValuePackage
IC174HCT595SO16
C10.1uF capacitor805
LED1Yellow LED805
R110K potentiometerCA6V/6mm
R21K resistor805
BLA, BLC2x1 pins 0.1” pin header2X01
Bus Pirate IO5X2 0.1” shrouded header2X5-SHROUDED
LCD116x1 pins 0.1” (fe)male header16x01 (fe)male

CABLE - 6cm 1x10 cable with 2 2x5 female connectors. This cable connects the Bus Pirate to the LCD adapter It needs 2x5 female connectors on each end. Length can be very short >6cm.

LCD1 can be male or female. We use female or no header on our LCDs, so male header works best. Female has the advantage that you can also put a 0.1" pin header in it and it will work the same way. The current Seeed adapter ships with a male header.

Firmware

The Bus Pirate firmware has macros that reset the LCD, initialize it to 4bit mode, and send data.

The LCD mode source code is public domain. You can prototype with the Bus Pirate, and then use the source in your own project without any limits or attribution.

Interfacing the 74HCT595

To learn how the 595 chip works, let's use the Bus Pirate to toggle the LED on the adapter board.

Connections

Bus Pirate Dir. 74HCT595 Description
MOSI SER serial data
CLK SCK/SH serial clock
CS RCK/LAT/ST data latch
+5V SCL/MR clear (active low)
GND G/OE output enable (active low)
+5V VCC power supply
GND GND Signal Ground


The adapter connects the Bus Pirate to the 74HCT595 as shown in the table above.

Setup

HiZ> m <<<select mode menu
1. HiZ
...
7. 3WIRE
...
x. exit(without change)
(1)> 7 <<<choose raw3wire
Set speed:
1. ~5KHz
...
4. ~400KHz
(1)> <<<any speed
CS:
1. CS
2. /CS *default
(2)> <<default /CS
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)
(1)> 2 <<<normal output type
Ready
3WIRE> W[ <<<power on, CS low to start
Power supplies ON
/CS ENABLED
3WIRE>

Configure the Bus Pirate for raw 3wire mode (m,7). Set any speed, default /CS, and normal pin outputs. Enable the power supplies (W), and set the CS line to 0 before sending any data ([).

Toggle the LED

3WIRE> 0b00000001 ][
WRITE: 0x01
/CS DISABLED
/CS ENABLED
3WIRE>

LED 1 on the adapter board is connected to output A / bit 0 of the 595. To turn it on, send an 8bit byte with the first bit set to 1. Next, raise (]) then lower ([) the CS pin to move the new data onto the '595 output pins.

Lcdv2-timing.png

The value of each bit in 0b00000001 is moved into the 595 each time the clock signal transitions from high to low. This doesn't actually change the output on the pins. The output on the pins doesn't change until the latch (called strobe, etc in various datasheets) goes from high (]) to low ([).

3WIRE> 0b00000000 ][
WRITE: 0x00
/CS DISABLED
/CS ENABLED
3WIRE>

To turn the LED off, set its bit to 0 and update the 595 as shown here.

You can also turning on different bits and test the output on the LCD hearer with a multimeter. Hold the ground probe on pin 1, test the other pins with the positive probe.

There's a bunch of great 74xx595 tutorials out there if you're looking for more. See the Ardunio shift-out tutorial, and the Protostack 74HC595 tutorial.

Controlling an LCD with a 74HCT595

The previous section demonstrates how the Bus Pirate manipulates the LCD pins, but controlling the LCD is a little more complicated.

The LCD reads data from pins D0-D7 each time its EN pin is raised and lowered. It takes three updates of the '595 to enter a single value.

  1. The first '595 update sets the LCD data pins to the desired value.
  2. The next update keeps the data pins the same and raises the LCD EN pin.
  3. The final update maintains the data but lowers the LCD EN pin. The LCD now reads the value on the data pins.

Since we're driving the LCD in 4bit mode, it actually takes two of these operations (six '595 updates) to send a command to the LCD. Converting from a serial but to a parallel bus takes a lot of operations, but the SPI connection is very fast so there's no noticeable lag.

Taking it further

V2a is shipping now. It has several updates from v2, but there's room for finesse. A future version could have:

  • shrouded header
  • better labeling
  • a female header
  • adjustable power supply
  • backlight dimming

Get one

LCDadapterv2.jpg

The LCD adapter is easy to build on a breadboard with a few components. You can also buy an assembled version, and kick a few dollars to the open source project behind the Bus Pirate.

The LCD adapter v2 for the Bus Pirate is available at Seeed Studio for $9. Each sale directly supports this open source project.

Links

References

Development history and production resources