ich habe ein kleines script (button.py) erstellt, dass die zuletzt gespeicherte MQTT Message aus einem csv-file liest und auf einem OLED-Display anzeigt.
Das script funktioniert ohne Fehlermeldung, wenn es in der Console mittels sudo python3 button.py aufgerufen wird, unabhängig davon, ob bereits ein pythonscrpt läuft oder nicht.
Code: Alles auswählen
import RPi.GPIO as GPIO
import time
from time import *
import csv
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import ssd1309
from PIL import ImageFont, ImageDraw, Image
from pathlib import Path
serial = i2c(port=1, address=0x3C)
device = ssd1309(serial)
font1 = ImageFont.truetype('/home/pi/oled/fonts/DejaVuSansMono.ttf', 11)
font2 = ImageFont.truetype('/home/pi/oled/fonts/C&C Red Alert [INET].ttf', 12)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(27, GPIO.RISING, bouncetime=200)
while True:
if GPIO.event_detected(27):
print('Edge detected on channel', 27)
with open('msg.csv', 'r') as file:
reader = csv.reader(file)
data = file.readlines()
lastrow = data[-1]
split_row = lastrow.rstrip('\n').split(',')
event_date = split_row[0]
event_time = split_row[1]
topic = split_row[2]
msg = split_row[3]
print(event_date)
print(event_time)
print(topic)
print(msg)
with canvas(device) as draw:
device.show()
draw.text((5,3),event_date, font = font1, fill = "white")
draw.rectangle((5, 19, 128, 20), outline="white", fill="white")
draw.text((5,25), topic, font = font2, fill = "white")
draw.text((5,39), msg, font = font2, fill = "white")
draw.text((5,55), event_time, font = font2, fill = "white")
file.close()
sleep(5)
device.hide()
sleep(2)
Code: Alles auswählen
python3 /home/pi/oled/button2.py &
Ergebnis ist ebenfalls negativ.
Egal ob ich das script alleine über rc.local starte oder mit einem anderen script zusammen, keine Funktion.
Nun weiß ich nicht mehr weiter und wäre für einen Tipp dankbar.