pietermartens
Posts: 5
Joined: Wed Nov 28, 2018 8:06 pm

program stops at random

Wed Nov 28, 2018 8:12 pm

Hello,
I am not very experienced in Python programming.
But I succeeded to make a led light show on my raspberrypi.
It works okay. But it usually stops somtimes after 10 hours but also after 10 minutes.
Do you know what is the problem?

CODE:

Code: Select all

import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
reeks_led = (2,3,4,5,6,7,8,9,10,11,12)

for led in reeks_led:
    GPIO.setup(led, GPIO.OUT)
    GPIO.output(led, 0)

n = 1
 
def lamp(sec1,status, *vartuple ): # functie lamp (tijd,status, led, led,....)
    global n
    global l
    n = n +1
    for var in vartuple:
            if  status == 1 or status == 0:
                
                GPIO.output(var,status)
                if   var == 2: l = "zolder"      # LED CODES, LED NRS 2-12
                elif var == 3: l = "bedlamp P"
                elif var == 4: l = "bedlamp T"
                elif var == 5: l = "tv"
                elif var == 6: l = "badkamer"
                elif var == 7: l = "babykamer"
                elif var == 8: l = "keuken"
                elif var == 9: l = "aanrecht"
                elif var == 10: l = "kamer"
                elif var == 11: l = "piano"
                elif var == 12: l = "hal"
                
                if status == 1:   # LED ON
                   print (n-1),sec1,"aan",'(',l,')'
                if status == 0:  # LED OFF
                   print (n-1),sec1,"uit",'(',l,')'
                
                ##print (n-1),time.time() -t,sec1,status,'(',var,')'
                time.sleep(2)
                       
    return

while True:
         
     if n == 1:lamp(0.01,    1,2)               # lightshow starts
     if n == 2:lamp(4.0,    1,3,4)
     if n == 3:lamp(4.0,    0,2)
     if n == 4:lamp(9.0,    1,6)
     if n == 5:lamp(9.0,    0,3,4)
     if n == 6:lamp(13.0,    1,7)
     if n == 7:lamp(13.0,    0,6)
     if n == 8:lamp(17.0,    1,8,9)
     if n == 9:lamp(17.0,    0,7)
     if n == 10:lamp(21.0,    1,10,11,5)
     if n == 11:lamp(21.0,    0,8,9)
     if n == 12:lamp(25.0,    1,12)
     if n == 13:lamp(25.0,    0,10,11,5)
     if n == 14:lamp(30.0,    0,12) 
     if n == 15:
         
         n = 1
sys.exit()

ghp
Posts: 1241
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: program stops at random

Fri Nov 30, 2018 7:31 pm

Hello,
looks pretty good here. How do you start this program ? Are there error messages when it stops ?

pietermartens
Posts: 5
Joined: Wed Nov 28, 2018 8:06 pm

Re: program stops at random

Fri Nov 30, 2018 8:20 pm

Hello, thank you for your reaction.

I start it on my SSH connection on my labtop.
There are no errors to see.
I only see it stops running and I break it bu ctr-Z

ghp
Posts: 1241
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: program stops at random

Fri Nov 30, 2018 8:52 pm

Hmm, when ssh terminal (putty ?) gets a ctrl-s, then output stops and program is halted. Ctrl-q restarts in these cases.
When I close putty using the [X], the process is stopped also.
Try to detach process from console with "nohup <command> &".

pietermartens
Posts: 5
Joined: Wed Nov 28, 2018 8:06 pm

Re: program stops at random

Fri Nov 30, 2018 9:24 pm

hello,

This happens:

pi@raspberrypi:~ $ nohub python discotest2.py &
[1] 11985
-bash: nohub: command not found

ghp
Posts: 1241
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: program stops at random

Fri Nov 30, 2018 9:55 pm

Hello, perhaps you want do try "nohup" in place of "nohub" ?

pietermartens
Posts: 5
Joined: Wed Nov 28, 2018 8:06 pm

Re: program stops at random

Sat Dec 01, 2018 5:57 pm

ha ha thank you for your reaction. A detail but important!

It works! I have just start the lightshow.
I wait 24 hours before taking any conclusion. So far the longest period was about 12 hours.

I let you kwow the results.

Pieter

pietermartens
Posts: 5
Joined: Wed Nov 28, 2018 8:06 pm

Re: program stops at random

Sat Dec 01, 2018 10:41 pm

Hello,

It didn't work long. The program stopped after a few minutes.

Why?

rkn704
Posts: 30
Joined: Sun Dec 30, 2012 4:25 pm

Re: program stops at random

Sat Dec 08, 2018 10:50 am

Did you resolve this issue?

I left your program running on a Pi using Putty to SSH to it. It ran fine for 48+ hours.

I would disconnect the LED's and any external hardware and see if the program runs OK.

How are you powering the LED's? Try a different power supply. I had all sorts of problem when using a cheap USB PSU.

If the program works OK with the outputs disconnected then it suggests it is either a wiring issue, power issue or some type of interference.
I would re-connect everything and put some simple logging in to record which LED's are about to be turned on. If a particular output keeps appearing when it fails you can concentrate on that part of the circuit.

If you have any relays being controlled by the PI make sure you have flywheel (flyback) diodes fitted to eliminate spikes when the relay is turned off.

Return to “Python”