# Is there a way to control a 4 digit 7-segment display without a shift register?

I am trying to run a 4-digit 7-segment display using a RPi as a microcontroller (and there is a reason this is here and not on the RPi stack). However, all the tutorials i found require a 74HC595 shift register. I have one, but I want to simplify it by only using PNP transistors. How do I do this?
Edit: To clarify, My display is common anode, my transistors are S8550 PNP's, I'm okay with using 555 timers, and Raspberry Pi GPIO pins only output, like, 15mA max.

• Such a display is just made out of LEDs – see its datasheet to know how they're connected to the pins. The rest is just "how to drive LEDs with transistors from a raspberry Pi", and I bet you've researched that alread :) Dec 31, 2021 at 21:20
• Do you know about multiplexing? Dec 31, 2021 at 21:23
• How about resistors, are you willing to use those? Is the display CC or CA? What color are the LEDs? Dec 31, 2021 at 21:48
• Welcome to the site. However, you really haven't bothered even looking through this site before posting a new question, otherwise you would have found this question answered already. The site is not a free design house or personal tutorial service. Look at electronics.stackexchange.com/questions/56123/… You can modify the circuit in that answer yourself to suit the Raspberry Pi. Dec 31, 2021 at 21:56
• Does this answer your question? solution for driving multiple 7 segment LED display from 3 volt µC Dec 31, 2021 at 21:57

Without driver chips you're going to chew up a number of gpios. 7 (8 if you want the decimal point) plus one for each digit = 12 gpios.

Since your digits are CA (common anode), the pnp transistors will be ok to select the digits, but you'll also need npn transistors for each of the segments along with base resistors and current limit resistors for each segment. You need the segment transistors to amplify the gpio current as when multiplexing you need to run a higher current to achieve an acceptable brightness. If you calculate the segment resistors to achieve a given current, this is divided by 4 due to the multiplexing. Or looking at it the other way, the segment current is four times what you want it to be. As well, the gpio has a combined maximum current, so we'd probably exceed this if we used the gpio to switch the segments directly.

Considering you can get chips that basically do all the work for you, doing it 'old skool' like you want is making it more difficult.

This is not the solution I would personally choose, but it is still a possible solution that someone may choose to use if they enjoy electronics and happen to have a box of transistors and resistors with no better purpose.

It's possible to construct a memory cell that will drive a single segment of the display using five transistors and 7 resistors. You can construct 28 of these, one for each display segment.

Get ready to break out the extra jumbo-sized breadboards. The total component count will be 196 resistors, and 140 transistors. It will use 12 GPIO pins (7 SET pins, 4 INHIBIT pins, 1 CLR pin).

simulate this circuit – Schematic created using CircuitLab

The memory cells can be wired together as follows...

• A group of seven memory cells should be connected on one seven-segment display. There should be four groups of seven.
• The CLR signal on all cells are wired together and attached to one GPIO pin. Asserting CLR to 0V will clear all memory cells and enable all display segments.
• The INHIBIT pins on all cells in a group of seven should be wired together and attached to a single GPIO pin. There are four groups so four GPIO pins are used. Asserting INHIBIT to 0V inhibits the SET pin on that cell from setting the memory cell. By keeping the INHIBIT signal for some group at 3.3V, and keeping the other three at 0V, the memory cells for that specific group can be set without affecting the other groups.
• Each seven-segment display has seven segments A-G. The SET pin for corresponding segments in each group should be wired together. Four SET signals to a pin, and 7 pins total.

A schematic showing just segments A, B, C is given below. Four more columns need to be added to the grid to handle all seven segments on each display.

simulate this circuit

To do without the shift register instead use 7 GPIO lines to drive the LEDs

You need 7 GPIOs to control each 7 segment display. For 4, that is 28 GPIO pins.

If you want to display 4 of them, you can use a trick called multiplexing so that you only need 11 GPIOs to control all of them.

Wire it so 'a' on digit 1 is connected to 'a' on digit 2, digit 3, and digit 4. Same for the b-g. Now, connect 'a' to GPIO0, b to GPIO1, etc.

Using 4 more GPIO pins, connect each of them to one of the bases of 4 PNP transistors (through a 220 ohm resistor). Connect the collector to the anode of a digit, and the emitter to the 5V rail (through a 100 ohm resistor? I'm not sure here. Experiment.)

Now, if you output the appropriate GPIO pattern in a-g (in this situation, 0 means ON, 1 means OFF), and pull ONE of the 4 GPIOs down to zero (leaving the other 3 at digital 1), that digit will show the value you've encoded into a-g.

You use a loop to quickly display each of the 4 digits in turn, setting up a-g for the digit, enabling the digit, waiting, disabling the digit, then moving on to the next one.

Your persistence of vision will make it look like all the digits are lit at the same time.

This will only work if your 7 segment displays require 15mA or less for each segment to light, but it works pretty well, and only requires 11 pins.

I haven't prototyped this, but I've built similar displays in the past, and they worked a treat.

• the devil is in the details. The RasPi uses 3V3 logic so connecting the emittor to 5V won't work in this instance. The RasPi gpio isn't too beefy, so running the segments might be a challenge to get adequate brightness vs not smoking the RasPi. The other challenge is getting a non-real time operating system to multiplex at a consistent rate. Not impossible, but a more significant challenge than something like an Arduino. Jan 1, 2022 at 3:49
• If, rather than using logic 1, he uses open collector, making a 'logic high' be high-z instead of 3.3V, this will all work with a 5V LED, I believe (assuming he has enough resistance to protect the board). Switch between output port with a 0 written to it and an input with no pullup. That should work Now, getting the rasp-pi to switch quickly enough could be an issue unless he uses some sort of driver. There are also real time kernels out there he might be able to use. Or, just make the process very high priority? The other issue is current. 15mA per segment might be too little. Jan 1, 2022 at 6:16
• I used this same time-multiplexing method for the 7-segment displays on an industrial timer I designed a few years back. We sold thousands of units, and it worked quite well. I was using a PIC microcontroller and had a reliable timer interrupt. Jan 1, 2022 at 6:27
• @bob_monsen, i’d like to know how you’d drive pnp transistors with the emitter at 5V without exceeding the gpio specs of the raspi? Using hi-z doesn’t stop the clamp diodes working. Maybe zeners or a string of normal diodes to drop the voltage enough to be in spec. Jan 1, 2022 at 7:44
• @kartman There is a clamp diode, and the PNP has effectively a diode at the base, so that's 2 diodes already. So, 5-3.3-1.2 = 0.5V. The 220 ohm resistor will limit any current from the rail to the GPIO to 2.3mA. That's probably not going to hurt anything, but it could actually power the CPU, I guess. Another diode in series would prevent it entirely. Not sure if I should change the original post to include the diode. Hopefully the OP will read this note... Jan 1, 2022 at 20:06

Given the interrupt latency variation in the Raspberry Pi, if you're intending on operating under Linux you'd be better off using a controller chip that handles the multiplexing autonomously, and you just send it a bitmap representing the LED segment pattern via serial interface (eg. SPI).

Maxim makes some (with some second sources) and there are some nice ones from Asian suppliers that lack the 'boutique' pricing structure.

Of course you can always program just about any MCU of your choice to do this function, including an Arduino.

Take a few minutes and look up LED display driver chips, there are a lot of them that would be compatible with the RP. The Maximum MAX7219 comes to mind, it is SPI and only needs three wires. There are also I2C drivers that will do it as well. Try this link for starters: https://www.circuitbasics.com/led-display-drivers/

• No, I don't want a driver chip either. Dec 31, 2021 at 21:41
• That's actually a shift register. It's just hidden inside the IC. See page 5 of the datasheet where they write, "Data is loaded into the internal 16-bit shift register on CLK’s rising edge." I think the OP said "without a shift register."
– jonk
Jan 1, 2022 at 1:03
• The pi has shift registers internal as well. He referenced the 595 initially.
– Gil
Jan 9, 2022 at 22:39