chayzze
As part of a project, I need to know by which reader the tag was read.
Reader 1 is connected to the pin:
SDA : pin 24
SCK : pin 23
MOSI : pin 19
MISQ : pin 21
IRQ : pin 11
GND : pin 14
RST : pin 29
3.3V : pin 1
Reader 2 is connected to the pin:
SDA : pin 26
SCK : pin 23
MOSI : pin 19
MISQ : pin 21
IRQ : pin 11
GND : pin 14
RST : pin 29
3.3V : pin 1
And I'm stuck with the code because when I ask to read on reader 2 it always reads on 1
from mfrc522 import SimpleMFRC522
import RPi.GPIO as GPIO
import time
reader = SimpleMFRC522()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
CS_1 = 8
CS_2 = 7
GPIO.setup(CS_1, GPIO.OUT)
GPIO.setup(CS_2, GPIO.OUT)
try:
while True:
GPIO.output(CS_1, GPIO.LOW)
GPIO.output(CS_2, GPIO.HIGH)
print("Approchez une carte du lecteur 1")
id, text = reader.read()
print("ID : %s\nText : %s" % (id, text))
time.sleep(1)
GPIO.output(CS_1, GPIO.HIGH)
GPIO.output(CS_2, GPIO.LOW)
print("Approchez une carte du lecteur 2")
id, text = reader.read()
print("ID : %s\nText : %s" % (id, text))
time.sleep(1)
except KeyboardInterrupt:
print("Arrêté par l'utilisateur")
finally:
GPIO.cleanup()