Member #642108

Member Since: January 23, 2015

Country: United States

  • TO Member #910971 Thank you! for porting much of the arduino example over to python, I searched all over and I found you posted it in another place as well but couldn't find any working versions ANYWHERE ELSE. So I modified it a little further (in my simple python/pi noob way) and made it function. I also found you were using GPIO.BOARD but referencing pins number in GPIO.BCM

    #!/usr/bin/env python
    
    import RPi.GPIO as GPIO
    import time
    
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    
    segmentClock=11
    segmentLatch=13
    segmentData=15
    
    GPIO.setup(segmentClock,GPIO.OUT)
    GPIO.setup(segmentData,GPIO.OUT)
    GPIO.setup(segmentLatch,GPIO.OUT)
    
    GPIO.output(segmentClock,GPIO.LOW)
    GPIO.output(segmentData,GPIO.LOW)
    GPIO.output(segmentLatch,GPIO.LOW)
    
    number=0
    
    
    def loop(number):
        showNumber(float(number)) #Test Pattern
    
    
    def showNumber(value):
        number = abs(value) #Remove negative signs and any decimals
    
        if number>=10:
            remainder = number % 10
            postNumber(remainder, False)
            number = int(number/10)
            postNumber(number, False)
        else:
            postNumber(number, False)
            postNumber("0", False)
    
        #Latch the current segment data
        GPIO.output(segmentLatch,GPIO.LOW)
        GPIO.output(segmentLatch,GPIO.HIGH) #Register moves storage register on the rising edge of RCK
    
    #Given a number, or - shifts it out to the display
    def postNumber(number, decimal):
        segments=bytes()
        a=1<<0
        b=1<<6
        c=1<<5
        d=1<<4
        e=1<<3
        f=1<<1
        g=1<<2
        dp=1<<7
        if number == 1: segments = b | c
        elif number == 2: segments = a | b | d | e | g 
        elif number == 3: segments = a | b | c | d | g
        elif number == 4: segments = b | c | f | g
        elif number == 5: segments = a | c | d | f | g
        elif number == 6: segments = a | c | d | e | f | g
        elif number == 7: segments = a | b | c
        elif number == 8: segments = a | b | c | d | e | f | g
        elif number == 9: segments = a | b | c | d | f | g
        elif number == 0: segments = a | b | c | d | e | f 
        elif number == ' ': segments = 0
        elif number == 'c': segments = g | e | d
        elif number == '-': segments = g
        else : segments = 0
    
     ##mistake likely here   
     #   if ((decimal segments) |= dp ):
        y=0
        while(y<8):
           GPIO.output(segmentClock,GPIO.LOW)
           GPIO.output(segmentData,segments & 1 << (7-y))
           GPIO.output(segmentClock,GPIO.HIGH)
           y += 1
    
    
    while True:
        number = number + 1
        print number
        loop(count)
        time.sleep(2)
        if number>=99:
            number = 0
    
    
    GPIO.cleanup()
    

    I hope this can help someone else as well!

No public wish lists :(