I know this is an old question and likely resolved but for anyone still finding this, maybe this will help:
I've been working on a Project using multiple NFC Readers (MFRC522). I used pimylifeup's MFRC522-Python Library and wrote my own NFC class based on the SimpleMFRC522 class provided by the Library. It closes the SPI Connection whenever I want to switch to a different reader and reopens it after setting the appropiate reader's RST Pin to high.
The order of events to copy the contents of a chip on Reader1 to a chip on Reader2 would look a little something like this:
- Set Reader1's RST Pin HIGH
- Set Reader2's RST Pin LOW
- Initialize SPI (see line 129-131 in MFRC522.py)
- Read Chip
- Close SPI (see line 166 in MFRC522.py)
- Set Reader1's RST Pin LOW
- Set Reader2's RST Pin HIGH
- Initialize SPI
- Write Chip
- Close SPI
The readers are all connected in parallel and only the RST Pins are connected to individual GPIOs. This has worked fine for me using 5 readers and should (theoretically) work with an unlimited amount of readers at the same time. Of course, you can't use them at the exact same time, but swapping through them at high speeds did the trick as well.
TLDR:
Code example for a class supporting multiple NFC Readers using this method:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import spidev
class NFC():
def __init__(self, bus=0, device=0, spd=1000000):
self.reader = SimpleMFRC522()
self.close()
self.bus
self.boards = {}
self.bus = bus
self.device = device
self.spd = spd
def reinit(self):
self.reader.READER.spi = spidev.SpiDev()
self.reader.READER.spi.open(self.bus, self.device)
self.reader.READER.spi.max_speed_hz = self.spd
self.reader.READER.MFRC522_Init()
def close(self):
self.reader.READER.spi.close()
def addBoard(self, rid, pin):
self.boards[rid] = pin
def selectBoard(self, rid):
if not rid in self.boards:
print("readerid " + rid + " not found")
return False
for loop_id in self.boards:
GPIO.output(self.boards[loop_id], loop_id == rid)
return True
def read(self, rid):
if not self.selectBoard(rid):
return None
self.reinit()
cid, val = self.reader.read_no_block()
self.close()
return val
def write(self, rid, value):
if not self.selectBoard(rid):
return False
self.reinit()
self.reader.write_no_block(value)
self.close()
return True
if __name__ == "__main__":
nfc = NFC()
nfc.addBoard("reader1",5)
nfc.addBoard("reader2",6)
data = nfc.read("reader1")
nfc.write("reader2",data)