0
votes

To pimp up my Carrera I'm going to build a round counter. It contains an Arduino Nano, a lcd and 2 rc522 rfid-reader. The readers share the pins for scd, miso, mosi and have own pins for sda and rst.

Actually I'm not able to get the two readers work together at the same time. Only if the one or the other reader is physically plugged (hardcore!) into the breadbord it works (without code changing). But not together.

It has to be an issue with my code, but where? (The RFID-Communication ist inpired by the example from [addicore][1]http://www.addicore.com/v/vspfiles/downloadables/Product%20Downloadables/RFID_RC522/RFIDQuickStartGuide.pdf)

Is there anyone who has a hint for me?

    #include <AddicoreRFID.h>
    #include <SPI.h>
    #include <LiquidCrystal.h>

    #define uchar unsigned char
    #define uint unsigned int

    // create AddicoreRFID object to control the RFID module
    /////////////////////////////////////////////////////////////////////
    //set the pins
    /////////////////////////////////////////////////////////////////////
    //2 - SCK Digital 13
    //3 - MOSI Digital 11
    //4 - MISO Digital 12

    const int SS1 = 8; //RFID1
    const int RST1 = 9;
    AddicoreRFID myRFID1 (SS1, RST1);

    const int SS2 = 10; //RFID2
    const int RST2 = A0;
    AddicoreRFID myRFID2 (SS2, RST2);

    //Maximum length of the array
    #define MAX_LEN 16

    //LCD init
    // * LCD RS pin to digital pin 7
    // * LCD Enable pin to digital pin 6
    // * LCD D4 pin to digital pin 5
    // * LCD D5 pin to digital pin 4
    // * LCD D6 pin to digital pin 3
    // * LCD D7 pin to digital pin 2
    LiquidCrystal lcd1(7, 6, 5, 4, 3, 2);

    //Counter
    int a = 0;
    int b = 0;

    void setup() {
      Serial.begin(9600);

      //LCD init
      init_lcd1();

      myRFID1.AddicoreRFID_Init();
      myRFID2.AddicoreRFID_Init();

    }


    void loop() {
      uchar i, tmp, checksum1;
      uchar status;
      uchar str1[MAX_LEN];
      uchar str2[MAX_LEN];

      ///////////// RFID1 ///////////////////
      // 0x4400 = Mifare_UltraLight -Tag Type
      str1[1] = 0x4400;
      //Find tags, return tag type
      // Manipuliert str1(!);
      //AddicoreRFID::AddicoreRFID_Request(byte reqMode, byte *TagType)
      status = myRFID1.AddicoreRFID_Request(PICC_REQIDL, str1);
      if (status == MI_OK) {
        serial_TagDetect(str1, 1);
      }
      //Anti-collision, return tag serial number 4 bytes
      // Manipuliert str1(!);
      status = myRFID1.AddicoreRFID_Anticoll(str1);
      if (status == MI_OK) {
        serial_TagData(str1);
        lcd_counter(str1, lcd1);
        //delay(500);
      }
      myRFID1.AddicoreRFID_Halt(); //Command tag into hibernation

      ///////////// RFID2 ///////////////////
      str2[1] = 0x4400;
      //Find tags, return tag type
      status = myRFID2.AddicoreRFID_Request(PICC_REQIDL, str2);
      if (status == MI_OK) {
        serial_TagDetect(str2, 2);
      }

      //Anti-collision, return tag serial number 4 bytes
      status = myRFID2.AddicoreRFID_Anticoll(str1);
      if (status == MI_OK) {
        serial_TagData(str2);
        lcd_counter(str2, lcd1);
        // liest sonst nonstop die Tags!
        //delay(500);
      }

      myRFID2.AddicoreRFID_Halt(); //Command tag into hibernation
    }

    void init_lcd1() {
       ... inits the lcd ...
    }

    // Zählt das Auftreten der Tags
    void lcd_counter (uchar *str, LiquidCrystal lcd ) {
       ... output to the lcd ....
    }

    // Meldet gefundenen Tag auf der Konsole
    void serial_TagDetect(uchar *str, int reader) {
        if (reader == 1) {
            Serial.print("RFID1 tag detected: ");
        } else {
            Serial.print("RFID2 tag detected: ");
        }
        Serial.print(str[0], BIN);
        Serial.print(" , ");
        Serial.print(str[1], BIN); Serial.println(" ");
   }

  // gibt  Tagdaten auf der Konsole aus
  void serial_TagData(uchar *str) {
      uchar checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
      Serial.print("The tag's number is: ");
      //Serial.print(2);
      Serial.print(str[0]);
      Serial.print(" , ");
      Serial.print(str[1], BIN);
      Serial.print(" , ");
      Serial.print(str[2], BIN);
      Serial.print(" , ");
      Serial.print(str[3], BIN);
      Serial.print(" , ");
      Serial.print(str[4], BIN);
      Serial.print(" , ");
      Serial.println(checksum1, BIN);
  }

I wonder about that the same(!!) rfid tag has different values depending it gets read from RFID1 or RFID2:

RFID1 tag detected: 1000100 , 0 The tag's number is: 136 , 100 , 11100 , 1101011 , 11111011 , 11111011

RFID2 tag detected: 1000100 , 0 The tag's number is: 68 , 0 , 0 , 0 , 0 , 1000100

2
I've had similar problem with Orange pi zero and multiple RFID modules. Look at my answer in another thread, maybe it could be useful to you too. Dual RC522 on Orange PI - Davor Dundovic

2 Answers

1
votes

I use 10 RC522 together at the same time with Ardunio mega .

Try this example for 2 ncf reader, its work for me. I tested in Arduino Nano. The readers share the pins for 3,3V, GND. SCD, MISO, MOSI, RST and have own pins for SDA. I don't use the IRQ pin.

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

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS1_PIN          10         // Configurable, see typical pin layout above
#define SS2_PIN          8         // Configurable, see typical pin layout above

MFRC522 mfrc522_1(SS1_PIN, RST_PIN);  // Create MFRC522 instance
MFRC522 mfrc522_2(SS2_PIN, RST_PIN);
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_1.PCD_Init();       // Init MFRC522
    mfrc522_1.PCD_DumpVersionToSerial();    // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

  mfrc522_2.PCD_Init();   // Init MFRC522
  mfrc522_2.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
}

void loop() {
    // Look for new cards
  if ( mfrc522_1.PICC_IsNewCardPresent() ||  mfrc522_2.PICC_IsNewCardPresent()) {
    Serial.println(F("New card..."));
  } else {

        return;
    }




    // Select one of the cards
    if ( ! mfrc522_1.PICC_ReadCardSerial() && ! mfrc522_2.PICC_ReadCardSerial()) {
  Serial.println(F("Read..."));
        return;
    }

    // Dump debug info about the card; PICC_HaltA() is automatically called
    mfrc522_1.PICC_DumpToSerial(&(mfrc522_1.uid));
  mfrc522_2.PICC_DumpToSerial(&(mfrc522_2.uid));
}
-1
votes
//Anti-collision, return tag serial number 4 bytes
status = myRFID2.AddicoreRFID_Anticoll(str1); // <<<< needs to be strl2