ich habe das ausprobiert, das Programm funktioniert. Jedoch fängt nach einiger Zeit die Ausgabewerte nicht anzuzeigen.
Das programm soll ja in einem 10 Sekundenraster jeweils die Systemzeit, Temperatur1 und Temperatur 2, seriel anzeigen.
Die Tempwerte lese ich über die siemens Logo aus, wie oben beschrieben und zeige im Multiplexbetrieb die Werte auf 4 LED-Module an.
Vielleicht hast du oder noch jemand anders ein Tipp für mich, wie ich den Schleifenablauf synchronisieren kann, falls die Anzeigewerte wieder ausbleiben.
Da die Systemanzeige ebenfalls nach einiger Zeit nicht dargestellt wird, glaube ich nicht das es was mit der Logoanbindung zu tun hat, aber genau weiss ich das nicht.
Schonmal vorab vielen Dank.
Code: Alles auswählen
code]#!/usr/bin/env pythoimport osn3
import RPi.GPIO as GPIO
import time, datetime
import string
import snap7
import sys
import os
ADDRESS_TEMPERATURE_POOL = "VW1118"
ADDRESS_TEMPERATURE_AUSSEN = "VW1120"
delay_time = 0.005
# kontrolliert Programm beenden mit ctrl + c
# python /home/pi/Desktop/finale/masterpool.py
# Pinbelegung raspberry
# led segmente pi 4B
# a=4, b=27, c=22, d=5, e=6, f=26, g=23, point=24
# lede module
# digit1=12,digit2=13,digit3=20,digit4=19,
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
segment8 = (4,27,22,5,6,26,23,24)
for segment in segment8:
GPIO.setup(segment, GPIO.OUT)
GPIO.output(segment, 0)
#Digit 1
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, 0) #Off initially
#Digit 2
GPIO.setup(13, GPIO.OUT)
GPIO.output(13, 0) #Off initially
#Digit 3
GPIO.setup(20, GPIO.OUT)
GPIO.output(20, 0) #Off initially
#Digit 4
GPIO.setup(19, GPIO.OUT)
GPIO.output(19, 0) #Off initially
null = [0,0,0,0,0,0,0]
zero = [1,1,1,1,1,1,0]
one = [0,1,1,0,0,0,0]
two = [1,1,0,1,1,0,1]
three = [1,1,1,1,0,0,1]
four = [0,1,1,0,0,1,1]
five = [1,0,1,1,0,1,1]
six = [1,0,1,1,1,1,1]
seven = [1,1,1,0,0,0,0]
eight = [1,1,1,1,1,1,1]
nine = [1,1,1,1,0,1,1]
ten = [1,0,0,0,0,1,1]
eleven = [0,0,0,0,0,0,1]
def print_segment(charector):
if charector == "1":
for i in range(7):
GPIO.output(segment8[i], one[i])
if charector == "2":
for i in range(7):
GPIO.output(segment8[i], two[i])
if charector == "3":
for i in range(7):
GPIO.output(segment8[i], three[i])
if charector == "4":
for i in range(7):
GPIO.output(segment8[i], four[i])
if charector == "5":
for i in range(7):
GPIO.output(segment8[i], five[i])
if charector == "6":
for i in range(7):
GPIO.output(segment8[i], six[i])
if charector == "7":
for i in range(7):
GPIO.output(segment8[i], seven[i])
if charector == "8":
for i in range(7):
GPIO.output(segment8[i], eight[i])
if charector == "9":
for i in range(7):
GPIO.output(segment8[i], nine[i])
if charector == "0":
for i in range(7):
GPIO.output(segment8[i], zero[i])
if charector == 10: #Gradsymbol
for i in range(7):
GPIO.output(segment8[i], ten[i])
if charector == " ": #Space
for i in range(7):
GPIO.output(segment8[i], null[i])
if charector == "-": #minus zeichen
for i in range(7):
GPIO.output(segment8[i],eleven[i])
return;
def print_temperatur(temp,station):
if not temp:
print("Kein Wert",temp)
else:
print(station,"=",temp)
#time.sleep(10)
if temp.count("-") == 1:
#lese Temperatur aus Logo ohne komma
GPIO.output(12,1) #Turn on Digit One
print_segment(str(temp[0])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(12,0) #Turn on Digit One
if len(temp) == 4:
GPIO.output(13,1) #Turn on Digit One
print_segment(str(temp[1])) #Print h1 on segment
#GPIO.output(24,1) #Display point On
time.sleep(delay_time)
#GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn off Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[2])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
if len(temp) == 3:
GPIO.output(13,1) #Turn on Digit One
print_segment(str(temp[1])) #Print h1 on segment
GPIO.output(24,1) #Display point On
time.sleep(delay_time)
GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn off Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[2])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
if len(temp) == 2:
GPIO.output(13,1) #Turn on Digit One
print_segment(str(0)) #Print h1 on segmen
GPIO.output(24,1) #Display point On
time.sleep(delay_time)
GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn off Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[1])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
GPIO.output(19,1) #Turn on Digit One
print_segment(10) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(19,0) #Turn on Digit One
digit_aus()
else:
if len(temp) == 3:
GPIO.output(12,1) #Turn on Digit One
print_segment(str(temp[0])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(12,0) #Turn on Digit One
GPIO.output(13,1) #Turn on Digit One
print_segment(str(temp[1])) #Print h1 on segment
GPIO.output(24,1) #Display point On
time.sleep(delay_time)
GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn off Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[2])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
if len(temp) == 2:
GPIO.output(13,1) #Turn on Digit One
print_segment(str(temp[0])) #Print h1 on segment
GPIO.output(24,1) #Display point On
time.sleep(delay_time)
GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn on Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[1])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
if len(temp) == 1:
GPIO.output(13,1) #Turn on Digit One
print_segment(str(0)) #Print h1 on segment
GPIO.output(24,1) #Display point On
time.sleep(delay_time)
GPIO.output(24,0) #Display point Off
GPIO.output(13,0) #Turn on Digit One
GPIO.output(20,1) #Turn on Digit One
print_segment(str(temp[0])) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(20,0) #Turn on Digit One
GPIO.output(19,1) #Turn on Digit One
print_segment(10) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(19,0) #Turn on Digit One
digit_aus()
def digit_aus():
GPIO.output(19, 0) #Turn off Digit One
GPIO.output(12, 0) #Turn on Digit One
GPIO.output(13, 0) #Turn on Digit One
GPIO.output(20, 0) #Turn on Digit One
GPIO.output(24, 0) #Tur
def print_zeit():
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
hour = now.strftime("%H")
minute = now.strftime("%M")
h1 = str(int(hour[0:1]))
h2 = str(int(hour[1:2]))
m1 = str(int(minute[0:1]))
m2 = str(int(minute[1:2]))
print ("time:", now.strftime("%H:%M"))
#delay_time = 0.001 #delay to create virtual effect
GPIO.output(12, 1) #Turn on Digit One
print_segment(h1) #Print h1 on segment
time.sleep(delay_time)
GPIO.output(12, 0) #Turn off Digit One
GPIO.output(13, 1) #Turn on Digit One
print_segment(h2) #Print h1 on segment
GPIO.output(24, 1) #Display point On
time.sleep(delay_time)
GPIO.output(24, 0) #Display point Off
GPIO.output(13, 0) #Turn off Digit One
GPIO.output(20, 1) #Turn on Digit One
print_segment(m1) #Print h1 on segment
GPIO.output(24, 1) #Display point On
time.sleep(delay_time)
GPIO.output(24, 0) #Display point Off
GPIO.output(20, 0) #Turn off Digit One
GPIO.output(19, 1) #Turn on Digit One
print_segment(m2) #Print h1 on segment
time.sleep(delay_time)
digit_aus()
def do_loop():
try:
plc = snap7.logo.Logo()
plc.connect("192.168.178.6",1118,1245)
plc.get_connected()
while True:
start = time.monotonic()
while (round((time.monotonic() - start),1) < (10.3)):
print_zeit()
start = time.monotonic()
temperatur = str(plc.read(ADDRESS_TEMPERATURE_POOL))
#print("na")
while (round((time.monotonic() - start),1) < (10.3)):
if not temperatur:
print_temperatur("---- Temp. Pool")
else:
print_temperatur(temperatur, "Temp. Pool")
start = time.monotonic()
temperatur = str(plc.read(ADDRESS_TEMPERATURE_AUSSEN))
#print("und")
while round((time.monotonic() - start),1) < (10.3):
if not temperatur:
print_temperatur("---- Temp. Außen")
else:
print_temperatur(temperatur, "Temp. Außen")
finally:
digit_aus()
plc.disconnect()
plc.destroy()
def main():
while True:
try:
do_loop()
except KeyboardInterrupt:
break
except Exception as error:
print(error)
if __name__ == "__main__":
main()