Hey Leute,
habe da ein kleines Problem. Und zwar habe ich 12 Endlagentaster, jeweils 2 in Reihe. Also ich benutze 6 GPIO-EINGANG. Nun entsteht folgendes Mysterium, öfter wenn ich einen von den 2 in Reihe drücke und dann nach einer kurzen Zeit den anderen. Erkennt er das als ein Eingangssignal. Die Kabel waren vom Kollegen gelegt und haben schon eine Strecke von knapp 20m insgesamt.
Die Mqtt Sachen könnt ihr ruhig außen vor lassen.
Ich habe momentan 10kO Pull Up Widerstände für jeden Eingang. An der Verkabelung gibt es sonst nichts zu meckern. Wie gesagt manchmal geht es das man beide drücken muss und manchmal reicht einfach ein nacheinander. Die Stellung der Taster sind auch alle korrekt.
Falls ihr noch eine Idee habt. Lasst es mich wissen.
Code
import RPi.GPIO as GPIO
import time
import paho.mqtt.client as mqtt
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t5 = 0
t6 = 0
start = 0
status = 0
topic = "dracula/grave/taster"
GPIO.setmode(GPIO.BOARD)
control_pins = [11,12,13,15,29,31]
for pin in control_pins:
GPIO.setup(pin, GPIO.IN)
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe(topic)
client.publish("riddle",(topic + " Grave Buttons Online Commands: start // restart "))
client.publish('0000/0007/v','{"d": 0}')
#if message == "start":
def on_message(client, userdata, msg):
global start
global t1
global t2
global t3
global t4
global t5
global t6
global status
message = msg.payload
print(message)
if message == "start":
print("ok")
start=1
client.publish("riddle"," Grave Buttons Start")
elif message == "restart":
status = 0
client.publish('0000/0007/v',('{"d": %i}' %status))
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t4 = 0
t5 = 0
t6 = 0
start = 1
##MQTT Variablen und Settings
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.178.40", 1883, 60)
client.loop_start()
while 1:
input_state1=GPIO.input(11)
input_state2=GPIO.input(12)
input_state3=GPIO.input(13)
input_state4=GPIO.input(15)
input_state5=GPIO.input(29)
input_state6=GPIO.input(31)
if input_state1 == False and t1 == 0 and start == 1:
status = status + 1
print("Taste1")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t1 = 1
elif input_state2 == False and t2== 0 and start == 1:
status = status + 2
print("Taste2")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t2 = 1
elif input_state3 == False and t3 == 0 and start == 1:
status = status + 4
print("Taste3")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t3 = 1
elif input_state4 == False and t4 == 0 and start == 1:
status = status + 8
print("Taste4")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t4 = 1
elif input_state5 == False and t5== 0 and start == 1:
status = status + 16
print("Taste5")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t5 = 1
elif input_state6 == False and t6 == 0 and start == 1:
status = status + 32
print("Taste6")
print(status)
client.publish('0000/0007/v',('{"d": %i}' %status))
time.sleep(0.5)
t6 = 1
elif t1 == 1 and t2 == 1 and t3 == 1 and t4 == 1 and t5 == 1 and t6 == 1 and start == 1:
client.publish((topic),"Done")
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t5 = 0
t6 = 0
start=0
time.sleep(5.0)
Alles anzeigen