Sponsor-Board.de

Normale Version: Raspberry PI - Python Script - Cronjob Problem
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hi Leute,


ich habe ein kleines Problem mit meinem Raspberry PI 2.
Vor wenigen Tagen habe ich ein 16x2 LCD Modul an das PI via GPIO Pins angeschlossen.
Das funktioniert soweit hervorragend und weißt auf dem ersten Blick keine Fehler auf.


Ziel ist es nun, die CPU Temp auf das Display zu bringen. Das entsprechende Script dafür steht bereits und schaut wie folgt aus:


Code:
import time
import RPi.GPIO as GPIO
import os
# Zuordnung der GPIO Pins (ggf. anpassen)
DISPLAY_RS = 7
DISPLAY_E  = 8
DISPLAY_DATA4 = 25
DISPLAY_DATA5 = 24
DISPLAY_DATA6 = 23
DISPLAY_DATA7 = 18
DISPLAY_WIDTH = 16     # Zeichen je Zeile
DISPLAY_LINE_1 = 0x80     # Adresse der ersten Display Zeile
DISPLAY_LINE_2 = 0xC0     # Adresse der zweiten Display Zeile
DISPLAY_CHR = True
DISPLAY_CMD = False
E_PULSE = 0.00005
E_DELAY = 0.00005
def get_cpu_temp():
       tempFile = open("/sys/class/thermal/thermal_zone0/temp")
       cpu_temp = tempFile.read()
       tempFile.close()
       return float(cpu_temp)/1000
def main():
   GPIO.setmode(GPIO.BCM)
   GPIO.setup(DISPLAY_E, GPIO.OUT)
   GPIO.setup(DISPLAY_RS, GPIO.OUT)
   GPIO.setup(DISPLAY_DATA4, GPIO.OUT)
   GPIO.setup(DISPLAY_DATA5, GPIO.OUT)
   GPIO.setup(DISPLAY_DATA6, GPIO.OUT)
   GPIO.setup(DISPLAY_DATA7, GPIO.OUT)
   display_init()
       lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD)
       lcd_string("CPU Temp: " + str(round(get_cpu_temp(), 2)))
       GPIO.cleanup()
def display_init():
   lcd_byte(0x33,DISPLAY_CMD)
   lcd_byte(0x32,DISPLAY_CMD)
   lcd_byte(0x28,DISPLAY_CMD)
   lcd_byte(0x0C,DISPLAY_CMD)  
   lcd_byte(0x06,DISPLAY_CMD)
   lcd_byte(0x01,DISPLAY_CMD)  
def lcd_string(message):
   message = message.ljust(DISPLAY_WIDTH," ")  
   for i in range(DISPLAY_WIDTH):
     lcd_byte(ord(message[i]),DISPLAY_CHR)
def lcd_byte(bits, mode):
   GPIO.output(DISPLAY_RS, mode)
   GPIO.output(DISPLAY_DATA4, False)
   GPIO.output(DISPLAY_DATA5, False)
   GPIO.output(DISPLAY_DATA6, False)
   GPIO.output(DISPLAY_DATA7, False)
   if bits&0x10==0x10:
     GPIO.output(DISPLAY_DATA4, True)
   if bits&0x20==0x20:
     GPIO.output(DISPLAY_DATA5, True)
   if bits&0x40==0x40:
     GPIO.output(DISPLAY_DATA6, True)
   if bits&0x80==0x80:
     GPIO.output(DISPLAY_DATA7, True)
   time.sleep(E_DELAY)    
   GPIO.output(DISPLAY_E, True)  
   time.sleep(E_PULSE)
   GPIO.output(DISPLAY_E, False)  
   time.sleep(E_DELAY)      
   GPIO.output(DISPLAY_DATA4, False)
   GPIO.output(DISPLAY_DATA5, False)
   GPIO.output(DISPLAY_DATA6, False)
   GPIO.output(DISPLAY_DATA7, False)
   if bits&0x01==0x01:
     GPIO.output(DISPLAY_DATA4, True)
   if bits&0x02==0x02:
     GPIO.output(DISPLAY_DATA5, True)
   if bits&0x04==0x04:
     GPIO.output(DISPLAY_DATA6, True)
   if bits&0x08==0x08:
     GPIO.output(DISPLAY_DATA7, True)
   time.sleep(E_DELAY)    
   GPIO.output(DISPLAY_E, True)  
   time.sleep(E_PULSE)
   GPIO.output(DISPLAY_E, False)  
   time.sleep(E_DELAY)  
if __name__ == '__main__':
   main()


Nun wollte ich, dass sich die Temperaturanzeige jede Minute aktuasliert. Also habe ich einen Cronjob erstellt, welcher das Script minütlich ausführt.

Code:
*/1 * * * * /usr/bin/python /home/pi/lcd.py



Funktioniet soweit auch und die Anzeige aktuaslisiert stetig. Nun zum eigentlichen Problem:
Das Ganze funktioniert ca. 24 Stunden oder manchmal auch weniger, danach schmiert der PI einfach ab.
Wenn ich den Cronjob ausgeklammert habe und das LCD dennoch dran steckt, tritt das Problem nicht auf.



Ich hoffe jemand von euch hat eine Idee? eventuell ein Fehler im Script ?

* * * * * ist der Code für jede Minute,jede Std, jeden Monat, jedes Jahr
*/2 * * * * is für jede grade Minute
1-59/2 * * * * für jede ungrade

*/1 hab ich noch nie gesehn, könnte daran liegen
Du hast es doch schon geschrieben Smile

*/2 * * * * is für jede grade Minute

Und ich hab statt 2 eine 1 stehen, für jede Minute.
***** ist jede Minute.
Sorry... hab deinen Beitrag falsch gelesen.
Habe es nun wie von dir vorgegeben eingetragen. Funktioniert soweit auch.
Bin ich mal gespannt, ob es daran lag.

Komisch das meine eigentlich falsche Variante auch funktioniert hat.


#edit

Problem tritt dennoch auf...
Referenz-URLs