I'm trying to get two MFRC522 readers to work with a Raspberry Pi 3 Model B. I started off using the pi my life up tutorial to get one working and it worked brilliantly. To get the second one going I tried a couple of different repos I found in github but none of them worked. I was sort of able to get both to read but it behaves oddly. The status is always MI_ERR but it will read the card. The other issues I'm seeing are it randomly displays a different uid and it will indicate card 2 is read when I'm putting the tag on card 1. Below is the pin configuration along with my code. Please note that each MFRC522.py was updated to indicate pin 15 or 22 for the NRSTPD. Any help would be greatly appreciated.
Reader 1 3.3v = Pin 1 RST = Pin 15 GND = Pin 9 MISO = Pin 21 MOSI = Pin 19 SCK = Pin 23 SDA = Pin 24
Reader 2 3.3v = Pin 1 RST = Pin 22 GND = Pin 9 MISO = Pin 21 MOSI = Pin 19 SCK = Pin 23 SDA = Pin 24
import RPi.GPIO as GPIO
import MFRC522_Chip2
import MFRC522
import signal
plate1 = [222, 86, 127, 87, 246]
plate2 = [86, 126, 214, 255, 87]
indicator1 = 0
indicator2 = 0
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
continue_reading = True
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create an object of the class MFRC522
MIFAREReader_Chip2 = MFRC522_Chip2.MFRC522()
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
# Scan for chip 1
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
#print (status)
# If a card is found
if status == MIFAREReader.MI_OK:
print ("Card 1 detected")
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
if indicator1 == 1:
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.LOW)
print ("!")
else:
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
indicator1 = 0
print (uid)
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
if uid[:5] == plate1:
print ("Plate 1 in position")
indicator1 = 1
else:
("Find plate 1")
indiator1 = 0
# Scan for chip 2
(status,TagType) = MIFAREReader_Chip2.MFRC522_Request(MIFAREReader_Chip2.PICC_REQIDL)
#print (status)
# If a card is found
if status == MIFAREReader_Chip2.MI_OK:
print ("Card 2 detected")
# Get the UID of the card
(status,uid) = MIFAREReader_Chip2.MFRC522_Anticoll()
if indicator2 == 1:
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.LOW)
print ("?")
else:
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.HIGH)
indicator2 = 0
print (uid)
#If we have the UID, continue
if status == MIFAREReader_Chip2.MI_OK:
if status == MIFAREReader.MI_ERR:
if uid[:5] == plate2:
print ("Plate 2 in position")
indicator2 = 1
else:
print("Find plate 2")
indiator2 = 0