Notifications
Clear all

Arduino nano with 2 RC522

24 Posts
4 Users
2 Likes
3,124 Views
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

I'm working with project that need me to connect 10 RC522 to Arduino mega device to control 5 rooms the idea was the user use his tag to enter the room then use it enable electricity after he finish using the room he take his tag witch power off the room, but i had a problem with that it was the rang between the RC522 module and the Arduino.

I switch to use 1 Arduino nano and 2 RC522 for each room however now the nano didn't read any RC522 if both connected how to fix this

 

Note the mega was work fine with all the RC522 connected within a small rang

This topic was modified 3 years ago by BlackGhost

   
Quote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

@blackghost

We need more information in order to help you.

What is your wiring? What pins are thing connected to?

 

What library are you using?

 

What is your code?

 

Did you readdress one of them so that they are communicating using the same address?

 

Also, double and triple check your wiring/connections while you are at it. We all get tripped up there sometimes.


   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

@madmisha

the code

#include <SPI.h>
#include <MFRC522.h>

#define SS_DoorPIN 9
#define SS_LightPIN 8
#define RST_PIN 10
//#define Light 3
//#define MotorIN 5
//#define MotorOUT 6

MFRC522 DoorPin(SS_DoorPIN, RST_PIN); // Instance of the class
MFRC522 LightPin(SS_LightPIN, RST_PIN); // Instance of the class

//MFRC522::MIFARE_Key key;

// Init array that will store new NUID
byte nuidPICC[4];

void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
DoorPin.PCD_Init(); // Init MFRC522 Door
LightPin.PCD_Init(); // Init MFRC522 Light

Serial.println(F("This code scan the MIFARE Classsic NUID."));
Serial.print(F("Using the following key:"));
}

void loop() {

// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( DoorPin.PICC_IsNewCardPresent() && DoorPin.PICC_ReadCardSerial())
{
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = DoorPin.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:"));
Serial.print(F("In dec: "));
printDec(DoorPin.uid.uidByte, DoorPin.uid.size);
Serial.println();
delay(1000);
}
if ( LightPin.PICC_IsNewCardPresent() && LightPin.PICC_ReadCardSerial())
{
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = LightPin.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:"));
Serial.print(F("In dec: "));
printDec(LightPin.uid.uidByte, LightPin.uid.size);
Serial.println();
}
}

/**
* Helper routine to dump a byte array as dec values to Serial.
*/
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
}

 

Pins

MOSI   D11
MISO   D12
SCK     D13

RST     D10

SDA1   D9
SDA2   D8

 

Libray

MFRC522-1.4.8

 

Note when i remove the MISO from any one the other work

This post was modified 3 years ago by BlackGhost

   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1657
 

Hi @blackghost,

  It might help if you could expand on your answers to @madmisha 's questions:

  Showed your wiring as a diagram.

  Clarify the address select mechanism, including any changes you have made to the modules.


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

@blackghost

Look in the examples of the library you provided and open the sketch for ReadUidMultiReader.

 

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_1_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 2
#define SS_2_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 1

#define NR_OF_READERS   2

byte ssPins[] = {SS_1_PIN, SS_2_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.

 

Creating 2 instances is not what was intended. I would start there. Try making basing your sketch off this example instead.

Forget about addressing, now that I know you are using SPI and chip select, it makes sense.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 
Posted by: @blackghost

I'm working with project that need me to connect 10 RC522 to Arduino mega device to control 5 rooms the idea was the user use his tag to enter the room

Just idle curiosity about a few cases.

1) suppose A comes along and cards the door and is let in and then puts his card in the inside slot and get the electricity on. Is the door re-locked after A puts his card into the reader for power ? If so, any accident or emergency A has inside the room won't be detected early (or maybe even in time to save A). If not, the the room could be used my multiple people once A has unlocked it.

2) suppose A has unlocked the door and entered the room and now has his card in the power slot. What happens if B comes along and enters his card into the door slot ? Does the door get unlocked again or does it refuse access until A withdraws his card and leaves ?

3) are the card IDs unique and checked for valid numbers or will just any card do ?

4) how do you prevent others from reading and duplicating the RFID cards ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

@will

1) the is freely opens from inside however from outside you must use you tag, so there no problem there and the door auto look it self and if any one inside there no way any one else can enter the room useless the first one allow it and it will be his responsibility

2) the cards are checked by database when you get the card it will be registered to allow access for selected time after that it will not open the room any more i plan to do that by add network card to the nano after i fix the 2 readers problem

3) prevent others to read the card i don't care about that because the card have expired date so even if you copy the card it will be no use after 2 or 3 days


   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

@madmisha

I tried it with no luck at all same problem i even use the example code without any edit but still same problem didn't work

same connection without any edit

/**
 * --------------------------------------------------------------------------------------------------------------------
 * Example sketch/program showing how to read data from more than one PICC to serial.
 * --------------------------------------------------------------------------------------------------------------------
 * This is a MFRC522 library example; for further details and other examples see:  https://github.com/miguelbalboa/rfid
 *
 * Example sketch/program showing how to read data from more than one PICC (that is: a RFID Tag or Card) using a
 * MFRC522 based RFID Reader on the Arduino SPI interface.
 *
 * Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
 *          and knowledge are required!
 *
 * @license Released into the public domain.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_1_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 2
#define SS_2_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 1

#define NR_OF_READERS   2

byte ssPins[] = {SS_1_PIN, SS_2_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.
/**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *bufferbyte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}

/**
 * Initialize.
 */
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

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    Serial.print(F("Reader "));
    Serial.print(reader);
    Serial.print(F(": "));
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
}

/**
 * Main loop.
 */
void loop() {

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    // Look for new cards

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
      Serial.print(F("Reader "));
      Serial.print(reader);
      // Show some details of the PICC (that is: the tag/card)
      Serial.print(F(": Card UID:"));
      dump_byte_array(mfrc522[reader].uid.uidBytemfrc522[reader].uid.size);
      Serial.println();
      Serial.print(F("PICC type: "));
      MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
      Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));

      // Halt PICC
      mfrc522[reader].PICC_HaltA();
      // Stop encryption on PCD
      mfrc522[reader].PCD_StopCrypto1();
    } //if (mfrc522[reader].PICC_IsNewC
  } //for(uint8_t reader
}
*RST               D9      
*SDA1(SS)      D10
*SDA2(SS)      D8
*MOSI             D11
*MISO             D12
*SCK               D13
This post was modified 3 years ago 3 times by BlackGhost

   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

I have question, dos different wires length matter because one of them longer than the other ?

This post was modified 3 years ago by BlackGhost

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@blackghost

Try explicitly declaring the SS pins (8 and 10) as OUTPUT.

pinMode(SS_1_PIN,OUTPUT);

pinMode(SS_2_PIN,OUTPUT);

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 
Posted by: @blackghost

I have question, dos different wires length matter because one of them longer than the other ?

It shouldn't matter.

 

As a sanity check, I would test both individually using the single sketch to make sure they both are still working properly. You might have done this but I'm not sure if you tested both. I would also use the proper SS line for this.

 

It does note in the sketch that using 2 might not work right away and might need some work.

 

Try this: After you power your Arduino, power cycle the RC522's. It auto selects what communication mode it is in after a power cycle.

 

The datasheet says that for SPI, SS should be connected to the SDA pin of each unit. Can you confirm that is how it is hooked up? That is why it is better to post a wiring diagram as @davee stated. We can only guess.


   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

@will

didn't work


   
ReplyQuote
BlackGhost
(@blackghost)
Member
Joined: 3 years ago
Posts: 27
Topic starter  

here is the diagram

Screenshot 2021 07 20 203844
This post was modified 3 years ago by BlackGhost

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

@blackghost

Maybe the reader isn't initialized ?

 

In your loop() section after the for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) { put

// Initialise the sensor
    mfrc522[reader].PCD_Init();

Before the if (mfrc522[reader].PICC_IsNewCardPresent() ... to make sure the reader is initialized for use in the loop.

Also, you may want to add a delay of a second or more at the end of the for loop to let the readers stabilize.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
MadMisha
(@madmisha)
Member
Joined: 4 years ago
Posts: 340
 

@blackghost

It would also be helpful to know exactly what you are getting over the serial monitor. I don't know how it is failing. But if I knew where it is being hung up, it would be easier to point you in the right direction.

 

Edit: You can comment out the line about waiting if there is no serial present because you should not be using the chip that it was added for.


   
ReplyQuote
Page 1 / 2