Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I connected a 4-digit 7-segment display to the GPIO-port. It uses 8 ports for the LEDs and 4 ports for multiplexing via PNP-transistors. It is running so far with a loop written in C program:

while(1) {
  for(j = 0; j < 4; j++) { // Loop through 4 digits
    writeSegments(j+1, values[j]);
    delayMicroseconds(500); // approximately 500 Hz total refresh frequency

In general this works fine but maybe once or two times a second there is some irregular flickering. There is no XSession running and only MPD plays music. I run the program with a very high priority:

nice -n -19 /home/pi/mpd/C/main &

What else can I do?

I already did some research and found out the following options:

Both ways seem to be very complicated for just using such a simple display.

What do you suggest?

share|improve this question
This doesn't directly answer your question but, have you thought about changing your hardware -- you can get a 4 digit 7-segment display with an I2C interface and let it manage the multiplexing. As an added bonus it should only need 2 pins. –  Craig Nov 21 '12 at 21:15
You are right. Changing the hardware is a solution. For example using another small Atmel dedicated for the display might do the job as well. I would like to stick to the original hardware. –  Lukas Nov 21 '12 at 23:15
What happens when you shorten that delay you are using. Based on your 500 Hz for 32 segments is only 15 Hz per segment. For a steady display you need at least 20Hz (or better 25Hz) per segment. If it still flickers at that rate, you can start to blame the scheduler. An other solution might be to use a D-latch and use those 4 GPIO's to control the state of the D-latch, this way you don't need any high frequency to update. Just write when needed, so no scheduler or flickering problems at all. –  ikku Nov 22 '12 at 2:37
Only the digits are multiplexed. 500m microseconds already result in 50 Hz update rate for each digit. The segments are enabled parallel. The display flickers only once up on a time (maybe two times a second) but in general it is updated fast enough. A D-latch would mean, I have to change the hardware as well. Any other suggestions? –  Lukas Nov 22 '12 at 17:47
@Craig How to use a 4 digit 7-segment display with I2C interface with the Raspberry Pi? Is there a high level Python library? Like segmentdisplay.print(23) (outputs 0023) ? –  Basj Mar 25 at 7:20

2 Answers 2

To avoid flickering of the segments, you really do need hard real time control of the multiplexing. Even small variations in the timing will be quite noticeable.

Using the timer on the CPU should work quite well, but as you observed it seems a lot of hassle for one simple thing. Perhaps it's worth doing if it's not just a one-off thing you are making.

Using a smart display, or making one by adding a small micro is probably the easier route. I'd probably opt for the micro since it gives the most flexibility.

share|improve this answer

If you avoid multiplexing there will be no flickering, but it will cost you higher current usage and extra hardware. Just search for disp7s2 in http://www.e-lab.de/AVRco/DOC_en/DocuStdDriver.pdf document. It will show you an example schematics for non-multiplexed 7-segment display driver using 74HC595 shift register and 8 resistors for each digit. The advantage of this mode is ultra low radiation and therefore no EMR problems.

share|improve this answer
I think maybe the display is already multiplexed - ie 12 pins. –  John La Rooy Apr 9 '13 at 12:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.