Goodday,
I am stuck at a project I am working on. I am looking to connect multiple MFRC522-readers to the same SPI-bus on an Arduino Mega.
I am using the exact standard code from https://github.com/alex5imon/Arduino-RFID/blob/master/two_readers/two_readers.ino:
/*
* @file two_readers.ino
* Project RFID
* @version 1.0
* @author Alejandro Simon
* @date 29/03/15
* @license MIT - http://opensource.org/licenses/MIT
*
* This sample uses the MFRC522 library created by Miguel Balboa (circuitito.com), Jan, 2012.
*
*/
/*
* Pin layout
* --------------------------
* MFRC522 | Arduino Uno
* --------------------------
* RST | 7/ICSP-5 (shared)
* MOSI | ICSP-4 (shared)
* MISO | ICSP-1 (shared)
* SCK | ICSP-3 (shared)
* SDA1 (SS) | 9 (reader 1)
* SDA2 (SS) | 10 (reader 2)
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 24
#define SS_PIN2 26
#define RST_PIN 25
#define RST_PIN2 27
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create First MFRC522 instance.
MFRC522 mfrc522_2(SS_PIN2, RST_PIN2); // Create Second MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init First MFRC522 card
mfrc522_2.PCD_Init(); // Init Second MFRC522 card
}
void loop() {
check_reader(mfrc522, 1);
check_reader(mfrc522_2, 2);
delay(50);
}
void check_reader(MFRC522 reader, int id) {
// Look for cards
if ( ! reader.PICC_IsNewCardPresent() || ! reader.PICC_ReadCardSerial() ) {
return;
}
Serial.print(F("Card detected in reader: "));Serial.println(id);
// A card has been detected
unsigned int hex_num;
hex_num = reader.uid.uidByte[0] << 24;
hex_num += reader.uid.uidByte[1] << 16;
hex_num += reader.uid.uidByte[2] << 8;
hex_num += reader.uid.uidByte[3];
Serial.print(F("Card UID hex:"));Serial.println(hex_num);
}
I have connected both the readers in parallel to the SPI-bus (
pin 50 - MISO
pin 51 - MOSI
pin 52 - SCK
And the readers both have private pins:
pin 24 - SDA Reader 1
pin 25 - RST Reader 1
pin 26 - SDA Reader 2
pin 27 - RST Reader 2
When I try to scan a tag, nothing happens on both readers.
But, when I disconnect either one from the +3.3v, the other will work flawlessly (both ways). In other words, I suspect the problem to be somewhere in the SPI bus, but I'm having trouble narrowing it down.
Could be the code has a mistake, but it is the exact example code taken from the libraries GitHub.
Thanks in advance