DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

7 segment LED

Tue May 08, 2018 9:59 am

Hi,

I have been searching around for instructions on how to connect a 7 segment LED (in fact i need 2 juxtaposed, but that should be 'easy'.)
(To display numbers up to 10)

I find many examples, but the more i find, the more i get confused as to the best way to proceed.
As i need 2, i would like to limit the number of GPIO pins, because i need some for extra devices.

What would you recommend to a beginner:
- Start with 2 simple Leds, add a "shift register" (whatever that is) and limit the GPIO's to 2 x 3 ?
- Buy some "backpack" exquipped ones, if i can find them...
- or.....

Thanks
Paul

scotty101
Posts: 3863
Joined: Fri Jun 08, 2012 6:03 pm

Re: 7 segment LED

Tue May 08, 2018 11:13 am

An off-the-shelf solution with 7 segments on board will be the easiest option particularly if it is from a dedicated Pi accessory supplier. They will no doubt provide you with code examples and a library to make controlling the display easy.

Anything else and its going to be a little more complicated as you'll need to figure out how to control the GPIO pins or any shift register or IO port expanded you use.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5468
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: 7 segment LED

Tue May 08, 2018 11:27 am

scotty101 wrote: An off-the-shelf solution with 7 segments on board will be the easiest option particularly if it is from a dedicated Pi accessory supplier. They will no doubt provide you with code examples and a library to make controlling the display easy.
Anything else and its going to be a little more complicated as you'll need to figure out how to control the GPIO pins or any shift register or IO port expanded you use.
+1 FWIW, there are quite a few examples, both "home built/designed" and pre-built modules, with supporting 'C' code within this section of my web-site: http://www.cpmspectrepi.uk/raspberry_pi ... Boards_Etc. NB: it's generally easier to work with "hardware multiplexed" (dedicated i.c.) than "software multiplexed" approaches.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
mark3112
Posts: 46
Joined: Mon Apr 09, 2018 10:39 am

Re: 7 segment LED

Tue May 08, 2018 6:11 pm

Maybe not exactly suitable for a beginner, but here’s an option.
Instead of using GPIO pins, how about using I2C?
The HDSP-523E device is a dual 7 segment display, which meets one of your criteria, and the MCP23017 can handle it using only 2 GPIO pins.
I (along with many on here) can supply the code and the digit lookup mapping table using the WiringPi/PIGPIO library if you need the details.
The MCP23017 may look a bit complicated at first, but for driving LED’s, it’s really not that bad when you start to understand it.
P.S. The Decimal Point LED’s are hard wired to illuminate on startup, but can be overridden once the code starts running.
Attachments
7seg.PNG
7seg.PNG (60.11 KiB) Viewed 980 times
You can make a real CPU in a FPGA, but you can’t make a real FPGA in a CPU.

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: 7 segment LED

Wed May 09, 2018 6:54 am

Hi,

This MCP23017 stuff looks tempting, but i have never used a microchip before.
Is the python code very complicated ?

thx,
Paul

User avatar
mark3112
Posts: 46
Joined: Mon Apr 09, 2018 10:39 am

Re: 7 segment LED

Wed May 09, 2018 10:41 am

Hi
Sorry, never used Python so can’t help with that, but there are plenty of examples here.

viewtopic.php?t=173781

Address for the I2C device (as wired in diagram) is 0x22, see pins A0,A1,A2 (could have up to 8 devices at address 0x20-0x27).

To set the chips mode to Output write 0x0 the IODIR registers (Address 0x0 & 0x1)
Write display data to the chips Output Latch registers (Address 0x14 & 0x15):

To set the digits here is an array containing the segments for displaying 0 – 9
DigitSettings[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7C, 0x07, 0x7F, 0x67 };

So if you want to display 4: tempval = DigitSettings[4]

From looking at an example from the link, this should be close:
import smbus as smbus
bus = smbus.SMBus(1)
bus.write_byte_data(0x22, 0x0, 0x0) // Port A to Output
bus.write_byte_data(0x22, 0x1, 0x0) // Port B to Output

bus.write_byte_data(0x22, 0x14, tempval) // Display 4 on RHS Display (Port A)
You can make a real CPU in a FPGA, but you can’t make a real FPGA in a CPU.

Return to “Beginners”