loading

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!

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 theRPI.GPIOmodule.

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 :-)

<p>I don't code in python, find it very annoying. but i went ahead and fixed the code since copy-paste fails on this site.</p><p>http://pastebin.com/wCRWFK6d</p>
<p>Finally got it working!!! </p><p>Used a Pi Zero with a Broadcom HDSP-B09G display from CPC.</p><p>Had the same problem as others with only the far right digit showing, but after much messing and testing finally realised it was an indent prob in python. In the code above I think there should be an additional tab - see attached pic.</p><p>Thanks, great little project!</p>
<p>I started with this tutorial and it was a awesome intro. But I had a few problems, so a friend told me about YL-3 8x7segment display he used on his Arduino Project. It is just 3 $ and it worked out pretty well. </p><p>I wrote a summary here: <a href="http://robinhenniges.com/en/raspberry-pi-with-yl-3-8x7-segment-led-display" rel="nofollow">http://robinhenniges.com/en/raspberry-pi-with-yl-3...</a><br>I also provide the code on github.<br>At the moment I use it to display the price of the next gas-station on it.</p>
<p>Nice.</p>
<p>I did according to the tutorial above, the coding part is good, the wiring is correct as well but the result turn out to be not what im expected, please help =(</p>
<p>In looking at this picture, you have multiple resistors instead of a singular resistor through wires requiring resistors.</p><p>The output on the display indicates wiring errors.</p>
<p>I'm using a raspberry pi 2, reason being of using multiple resistors is because I only have a lots of 100 &Omega; resistor and 220&Omega;, the next power will be 470&Omega; so I uses the combination of 100&Omega; + 220&Omega; to form a 320 &Omega;. I did the wiring according to the table above &gt;&lt;</p>
<p>OK</p><p>Are you sure you've got the right pins?</p>
<p>and what about pi 2??????????????????????????????????????????</p>
<p>It would work.</p>
<p>Just make sure you use the same pins.</p>
<p>Just make sure you use the same pins.</p>
<p>Hello I'm sorry, i have a error on line : 14</p><p>File &quot;script.py&quot;, line 14</p><p> GPIO.setup(segment, GPIO.OUT)</p><p>Why plz ?</p>
<p>I made this, but unfortunately only the leftmost digit lit (although it was correct). I have checked all my connections, as well as the display, but still can't get it to work. Raspberry pi pins 16, 18, and 26 seem to be the issue, as applying voltage to display pins 8, 9, and 12 causes the missing digits to light.</p>
<p>Edit, I meant the rightmost digit.</p>
<p>Hi! Thanks for the instructable, I'm finding it very useful. Unfortunately, I get the same problem as JasperK3, and only the rightmost digit (pin 6-13) ligths up... Did you manage ot solve it, or does it happen to anyone else? I've checkd and rechecked my connections.</p>
<p>Fixed it! It was a matter of indentation in my code, some lines were outside the &quot;for digit&quot; loop... Sorry!</p>
<p>Thanks for fixing.</p><p>Still a little error in line 63.</p><p>if (int (time.ctime()[18:19])%2 == 0) and (digit == 1):</p><p> ^</p><p>IndentationError: unexpected indent</p>
<p>The way to implement code into instructables is terrible!</p><p>It took me ten minutes to fix the other one yesterday!!!</p><p>Looks like there is a space before that line that needs to go poof!</p><p>STOP FINDING ERRORS ;-)</p>
<p>Sorry to break it, but on the same line it seems like the ending &quot;<strong>:</strong>&quot; is missing in your code above.</p>
<p>Fixed,</p><p>It is easier to fix now I have stopped using the code type text.</p>
<p>I get a Syntax Error on line 13.</p><p> = (24,12,19,21,23,22,15,11)</p><p> ^</p>
<p>Oops sorry ....</p><p>Lines:</p><p><em>segments</em></p><p><em>= (24, 12, 19, 21, 23, 22, 15, 11)</em></p><p>Should read:</p><p><em>segments = (24, 12, 19, 21,23, 22, 15, 11)</em></p><p>Thanks for spotting that - fixed :-)</p>
Remember to take pictures next time but other than that good
<p>I took it apart but at the time I wasn't thinking of instructables :-)</p>

About This Instructable

25,259views

37favorites

License:

More by bertwert:Choosing your first DSLR Homemade Camera Lens bertwert 
Add instructable to: