Getting the RFID-RC522 to work! [SOLVED]

That’s a bit more complicated then, since this is a forum dedicated to Particle devices.
While a lot of things are similar to Arduino, not everything is and hence we may not be able to help with your specific question.
You may be better off with a community that explicitly targets Arduinos.

But if we spot something, we may still point you to it.

Ok I didn’t know. Well thanks anyway :wink:

Hello.

I don’t know if this is the right post but i have one week with one same problem.

I have tested this python code

https://github.com/mxgxw/MFRC522-python

Inside with one raspberry and one MFRC522, and it works great!, It does the authentication.

I have translated this code to STM32F0, and it get rights the UID but it get MI_NOTAGERROR when I tried to pass the SelectTag step and one MI_ERR when I tried to do the authentication step.

I suppose that the problem was SPI, because I had to translate SPI function from python to STM32F.

I simulated and used Hardware SPI. In both cases I can read register, even I can get right ID but I have problems with SelectTag and Authentication process. It seems that errors are when I tried to send more than 2 bytes to MFRC522_REG_FIFO_DATA.

What is wrong?

Thanks in advance.

Best regards.

Francis.

@francisjjp, this is a forum for Particle devices, Photon and Electron. If you were using one of those devices we could help you but you are not.

Hello peekay123.

Sorry.

Anyway, thanks!

Hello All !
I have a particle photon working with a RFID-RC522 board. It works great for reading the board. I am triggering a relay based on successful reading of a card and that works great, and will swipe and trigger the relay forever.
However, when i hook up a door lock to the relay, i can get one or two swipes before the card becomes unresponsive.
The relay (SRD-5VDC-SL-C) is using a separate 5 v power supply and I have a diode on the common ground with the photon. I do not have a diode on the trigger to the relay (have to get another one :)) just in case the door lock / relay are sending voltage back.
The door lock is using a separate 12 v power supply.
It seems to be a shielding issue, it just triggered 11 times in a row with the door lock.
When I reset the photon, it will work again. I am considering adding a system.reset after a successful door open, but would rather not.
Is there a way to actually reset the RFID card? i thought there was a reset() but it is not recognized.
Has anyone ran into a similar issue?

// This #include statement was automatically added by the Particle IDE.
#include <MFRC522.h>

If your relay has not got a (built-in) flyback diode, you will definetly see some effect to the common ground possibly upsetting - and maybe over time damaging - your device.

(SRD-5VDC-SL-C)
Get this one.

Hello ,someone can help me ?
my rfid522 i use library code the original but something error . :frowning:

What device are you trying to program? This forum is dedicated to the Particle product suite, and it seems as though you’re trying to flash an Arduino by the looks of the IDE.

Please no double posting!

2 Likes

Ignore it. You almost there. :stuck_out_tongue_winking_eye:

ah sorry. yes it’s arduino

hi
i want to send the serial number of rfid tag to mysql database, where i use arduino and gsm for sending the data…
can any one help

1 Like

Im having same problem. These days im using ESP8266 module to send data to database but no luck. Are you figure out to this? Please help @zah

I never could get this to work with the Particle Boron using the code I’ve found in this thread. I think it’s because calling delay() does magic things on Particle GEN3 devices, and breaks things. Anyway, here’s my current code that resets the RFID reader after each tag scan and every 5 seconds, whichever comes first. That’s a bit aggressive, but it’s helping with reliability.

// This #include statement was automatically added by the Particle IDE.
#include <MFRC522.h>

#define LED_PIN D7
#define TONE_GND D5
#define TONE_PIN D4

// Define the serial data and reset pins.
#define SS_PIN SS
#define RST_PIN D8

// NFC card reader init
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Keep track of the last time we recorded the time
uint32_t lastMillis = 0;


void setup() {
    pinMode(TONE_GND, OUTPUT);
    pinMode(TONE_PIN, OUTPUT);
    digitalWrite(TONE_GND, LOW);
    digitalWrite(TONE_PIN, LOW);
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);
    Particle.publish("status", "boot", 60, PRIVATE, WITH_ACK);
}

void initRC522() {
    SPI.begin(); // Init SPI bus
    SPI.setClockDivider(SPI_CLOCK_DIV16);
    mfrc522.PCD_Init(); // Init MFRC522
    delay(50);
    digitalWrite(LED_PIN, HIGH);
}

void killRC522() {
    digitalWrite(RST_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
}

void beep() {
    tone(TONE_PIN, 1500, 400);
    delay(500);
    tone(TONE_PIN, 2000, 400);
    delay(500);
}

void blink() {
  RGB.color(0, 255, 255);
  delay(90);
  RGB.color(0, 0, 0);
  delay(90);
  RGB.color(5, 5, 5);
}

void loop() {
    RGB.control(true); // take control of onboard RGB led
    // Indicate we're in our card reading loop
    RGB.color(3, 3, 3);
    
    // Initialize RFID reader
    initRC522();

    // Reset last ms timer    
    lastMillis = millis();

    // Wait up to N ms for card reading
    while (millis() - lastMillis < 5000) {
        // Look for a new NFC card to be present
        if (!mfrc522.PICC_IsNewCardPresent()) {
            continue;
        }
        // Attempt to read the card serial number (uid)
        if (!mfrc522.PICC_ReadCardSerial()) {
            continue;
        }
    
        // Card was read
        char cardID[32] = "";
    
        for (byte i = 0; i < mfrc522.uid.size; i++) {
         char hex[4];
         snprintf(hex, sizeof(hex), "%02x", mfrc522.uid.uidByte[i]);
         strncat(cardID, hex, sizeof(cardID));
        }
        
        // tell the card to go to sleep
        mfrc522.PICC_HaltA();
    
        // Green indicator for card read
        RGB.color(0, 255, 0);
        Particle.publish("tag", cardID, 60, PRIVATE, WITH_ACK);
        beep();
        break;
    }
    killRC522();
    blink();
}
1 Like

HI @jtwalters -

I have found similar “issues” but not particular to Gen 3 devices also not only with MRFC522 reader. I found this in two project using Particle.publish() and ‘solved’ it in a similar fashion. Not every 5 seconds though but using IF statement to determine whether it was published to not. If no, reset… Not ideal I agree, but in my case it works :slight_smile:

  if (sensor_value >= 0) {

     char data[16];
     snprintf(data, sizeof(data), "%.3f", sensor_value);
     Particle.publish("WEBHOOK", data, PRIVATE); 
     delay(1000);
       
  } else {
       
    //--TEST DEBUG--//
     debug = analogRead(A4);
     char debug[16];
     Particle.publish("debug", debug, PRIVATE);

     Serial.print(debug);
     Serial.print(sensor_value);
     delay(1000);
     //--TEST DEBUG--//
     
     System.reset();
  }

I have since started using non-blocking delays instead and have not encountered this error again. My C++ knowledge is lacking so I cannot offer this as a solution, but it helped me out :joy:

Regards,
Friedl.