Controlling a 7 segment 4 digit display with a Raspberry Pi

http://www.techni.ca/2014/11/drive-7-segment-4-dig...

http://www.raspberrypi.org/forums/viewtopic.php?f=...

Here is a way to control 7 segment 4 digit display with a Raspberry Pi.

Please vote as I really want to win one contest in my life :-)

Sorry no pictures :-(

Step 1: The wiring!

Controlling a 7 segment 4 digit display with a Raspberry Pi
Controlling a 7 segment 4 digit display with a Raspberry Pi

We need to wire from the Pi GPIO to the pins on the display:

Resistors are all 390 Ω

Pin 1 on the display goes to pin 23 on the GPIO with a resistor

2 to 21 resistor

3 to 11 resistor

4 to 19 resistor

5 to 15 resistor

6 to 13 no resistor

7 to 12 resistor

8 to 16 no resistor

9 to 18 no resistor

10 to 22 resistor

11 to 24 resistor

12 to 26 no resistor

That is the wiring done :-)

Step 2: The code!

Now we need to code it to work, I am using python, for this we need the time module and the RPI.GPIO module.

This code displays the time and updates it.

Here is the code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setwarnings(False)

GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

segments = (24,12,19,21,23,22,15,11)

for segment in segments:

GPIO.setup(segment, GPIO.OUT)

GPIO.output(segment, 0)

digits = (26,18,16,13)

for digit in digits:

GPIO.setup(digit, GPIO.OUT)

GPIO.output(digit, 1)

num = {' ':(0,0,0,0,0,0,0),

'0':(1,1,1,1,1,1,0),

'1':(0,1,1,0,0,0,0),

'2':(1,1,0,1,1,0,1),

'3':(1,1,1,1,0,0,1),

'4':(0,1,1,0,0,1,1),

'5':(1,0,1,1,0,1,1),

'6':(1,0,1,1,1,1,1),

'7':(1,1,1,0,0,0,0),

'8':(1,1,1,1,1,1,1),

'9':(1,1,1,1,0,1,1)}

try:

while True:

n = time.ctime()[11:13]+time.ctime()[14:16]

s = str(n).rjust(4)

for digit in range(4):

for loop in range(0,7):

GPIO.output(segments[loop], num[s[digit]][loop])

if (int(time.ctime()[18:19])%2 == 0) and (digit == 1):

GPIO.output(11, 1)

else:

GPIO.output(11, 0)

GPIO.output(digits[digit], 0)

time.sleep(0.001)

GPIO.output(digits[digit], 1)

except KeyboardInterrupt:

GPIO.cleanup()

That is the code :-)

Step 3: Were DONE!

Now we are done and you have a working clock :-)

Please help me win!

If you have any questions please comment :-)

 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel