FireSpear
Posts: 6
Joined: Sat Dec 13, 2014 2:14 am

Python script randomly dies RPI3 + PiGlow script

Sat Dec 16, 2017 11:04 pm

Hello all,

I have been using my PiGlow as a LED clock for a few months now and the script that is driving the PiGlow seems to die randomly. The times in between when I turn the Pi on and when the script dies seem to be random, sometimes it lasts for over a week and sometimes for less than a day. I also have a second python script running for a shutdown button and that script keeps working even if the clock one fails. I have looked through the script but I don't know much about python and everything seems to be good to me. Also this is basically the only thing that the Pi does when it is on.

Im running this on a Raspberry Pi 3 fully updated and its being launched at system start using rc.local.

Anyone have any ideas?


This is the code that I am using.

Code: Select all

##
##  PyGlow
##
##      python module to control Pimoronis PiGlow (http://shop.pimoroni.com/products/piglow)
##
##      * clock.py - binary clock by Jason (@Boeeerb https://github.com/Boeeerb/PiGlow)
##


from pyglow import PyGlow
from time import sleep
from datetime import datetime

pyglow = PyGlow()


### You can customise these settings ###

show12hr = 1            # Show 12 or 24hr clock - 0= 24hr, 1= 12hr
ledbrightness = 50      # Set brightness of LED - 1-255 (recommend 10-20, put 0 and you won't see it!)
hourflash = 1           # Choose how to flash change of hour - 1= white leds, 2= all flash

armtop = "s"            # h= hour, m= minutes, s= seconds
armright = "m"
armbottom = "h"

### End of customising ###

pyglow.all(0)

hourcount = 0
hourcurrent = 0

while True:
    time = datetime.now().time()
    hour,min,sec = str(time).split(":")
    sec,micro = str(sec).split(".")
    
    hour = int(hour)
    if show12hr == 1:
        if hour > 12:
            hour = hour - 12

    min = int(min)
    sec = int(sec)


    binhour = "%06d" % int(bin(hour)[2:])
    binmin = "%06d" % int(bin(min)[2:])
    binsec = "%06d" % int(bin(sec)[2:])

    # Check if current hour is different and set ready to flash hour
    if hourcurrent != hour:
        hourcount = hour
        hourcurrent = hour

    
    if armbottom == "h":
	arm3 = list(binhour)
    elif armbottom == "m":
        arm3 = list(binmin)
    else:
        arm3 = list(binsec)
    led13 = ledbrightness if arm3[5] == "1" else 0
    pyglow.led(13,led13)
    led14 = ledbrightness if arm3[4] == "1" else 0
    pyglow.led(14,led14)
    led15 = ledbrightness if arm3[3] == "1" else 0
    pyglow.led(15,led15)
    led16 = ledbrightness if arm3[2] == "1" else 0
    pyglow.led(16,led16)
    led17 = ledbrightness if arm3[1] == "1" else 0
    pyglow.led(17,led17)
    led18 = ledbrightness if arm3[0] == "1" else 0
    pyglow.led(18,led18)

    if armright == "h":
	arm2 = list(binhour)
    elif armright == "m":
        arm2 = list(binmin)
    else:
        arm2 = list(binsec)
    led07 = ledbrightness if arm2[5] == "1" else 0
    pyglow.led(7,led07)
    led08 = ledbrightness if arm2[4] == "1" else 0
    pyglow.led(8,led08)
    led09 = ledbrightness if arm2[3] == "1" else 0
    pyglow.led(9,led09)
    led10 = ledbrightness if arm2[2] == "1" else 0
    pyglow.led(10,led10)
    led11 = ledbrightness if arm2[1] == "1" else 0
    pyglow.led(11,led11)
    led12 = ledbrightness if arm2[0] == "1" else 0
    pyglow.led(12,led12)


    if armtop == "h":
	arm1 = list(binhour)
    elif armtop == "m":
        arm1 = list(binmin)
    else:
        arm1 = list(binsec)
    led01 = ledbrightness if arm1[5] == "1" else 0
    pyglow.led(1,led01)
    led02 = ledbrightness if arm1[4] == "1" else 0
    pyglow.led(2,led02)
    led03 = ledbrightness if arm1[3] == "1" else 0
    pyglow.led(3,led03)
    led04 = ledbrightness if arm1[2] == "1" else 0
    pyglow.led(4,led04)
    led05 = ledbrightness if arm1[1] == "1" else 0
    pyglow.led(5,led05)
    led06 = ledbrightness if arm1[0] == "1" else 0
    pyglow.led(6,led06)


    # Flash the white leds for the hour
    if hourcount != 0:
        sleep(0.5)
        if hourflash == 1:
            pyglow.color("white",ledbrightness)
        if hourflash == 2:
            pyglow.all(ledbrightness)
        sleep(0.5)
        hourcount = hourcount - 1
    else:
        sleep(0.1)


Thanks a ton for any help!

Return to “Troubleshooting”

Who is online

Users browsing this forum: sachinkv and 31 guests