I'm trying to intercept sensor data with the RPi3. I use Raspbian and a Python script. One sensor is captured accurately, the other one prints results from both sensors. The sensor cables are the RPi3 inputs. The wiring is as follows on picture 1. I used resistors as in picture 2.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) from time import sleep GPIO.setup(20, GPIO.IN) GPIO.setup(21, GPIO.IN) buttonstate = 0; lastbuttonstate = 0; buttonstate1 = 0; lastbuttonstate1 = 0; while True: buttonstate = GPIO.input(20) buttonstate1 = GPIO.input(21) if buttonstate !=lastbuttonstate: if buttonstate == 1: print("Sensor1 on") time.sleep(0.1) buttonstate = lastbuttonstate if buttonstate1 !=lastbuttonstate1: if buttonstate1 == 1: print("Sensor2 on") time.sleep(0.1) buttonstate1 = lastbuttonstate1
When triggering the sensors (e.g.): Triggering sensor 2 Sensor2 on Sensor2 on Sensor2 on Sensor2 on Sensor2 on result without break
Triggering sensor 1 Sensor1 on Sensor1 on result with break between (had to stop trigger the sensor and trigger it again)
sometimes when triggering sensor 1 Sensor1 on Sensor1 on Sensor2 on Sensor1 on Sensor1 on Sensor2 on Sensor2 on Sensor1 on Sensor1 on Sensor1 on randomly printing wrong sensor
When connecting the inputs with terminal ground and reading the input directly the signals won't be send to the terminal but to the RPi3.
Where is the mistake?