Pages

2012-07-21

Raspberry Pi 7 segment displays

This post shows how to drive two 7 segment displays from 6 gpio pins on the Raspberry Pi without a continual refresh loop. The software is simple with very low cpu usage - only processing when you want to change the displayed numbers. The electronics are pretty easy too (I'm a novice myself!) It's also a fun way to learn about BCD (Binary-coded decimal) and latches.

Basically you take 6 gpio pins through current limiting resistors and then on to the second breadboard. You'll see from the picture below that I have added an LED as a confidence indicator for each gpio pin. I've labelled these in the picture for the latches and data lines that then need to be wired up to the HEF4543Bs:

If you look at the data sheet for the HEF4543B you'll see that the labels I've put on this picture match. These labels are also used in the software later.

LD = Latch disable (for first digit)

DD = 8 (BCD bit)

DC = 4 (BCD bit)

DB = 2 (BCD bit)

DA = 1 (BCD bit)

LD2 = Latch disable (for second digit)

The gpio pins for the latches are then connected directly to the two ICs, The data pins are connected in parallel to both ICs:

Now follow the data-sheets for the ICs and the displays to connect the IC output pins to the 7 segment displays. The phase input (PH) and the blanking input (BI) should both be connected to ground. I left a longer loop of wire on the blanking input as I was considering using it to blank the display but this would have used another gpio pin. Instead, if you check the data-sheet, you'll find that if you set the data to a decimal number higher than 9 it will blank the display anyway.

Note, this is all 3.3v and I've used another couple of 220ohm resistors to limit the current into the ICs.

Software

To set a number on the display you follow this sequence:

Keep what's on the display now - latch disable = off

Set the data pins for the required number

Disable the latch to take the value to the display - latch disable = on

For timing purposes wait for a short period

Keep what's on the display now - latch disable = off

The Python below counts from 0 to 99 in a continuous loop as seen in the video above.

This uses numdisplay.py and adds a very simple web interface. Run this up and go to http://{ip address}:8092/num/{number}. e.g. http://192.168.0.2:8092/num/12 to display 12.

Kits

I'm considering putting some kits together with the resistors, ICs and displays for people to buy if there's enough interest. It may turn out to be more cost effective if I buy some in bulk and then sell on to you. Let me know if you would be interested by leaving a comment below. Thanks.