Getting the RFID-RC522 to work! [SOLVED]

@Ambition1906, obviously the two libraries work differently since the UID on the non-working library is 91 7E 48 B5 for the Mifare 1K card and 83 B0 E3 C7 17 for the working library. Not sure why that is. Do you have an Arduino you could test the original (Arduino) library with?

Trabajé con el ejemplo y la libreria del RFID-RC522 que se encuentra en el Web IDE y todo funcionó ok (detección y lectura de tarjeta). Al querer hacer una App mia no pude cargar en el web IDE del Spark las librerias. Siempre respondía no encontrarlas. Con el Spark-CLI compile y flashee los archivos .ino, .h y .cpp.

Trabajo con Windows 7 y con usuario genérico (usuario). La consola abre en c:\users\user\ y ahí puse los archivos .ino, MFRC522.h y MFRC522.c.

Para compilar edite un archivo .bat para ejecutar:

login local y en la nube

spark login

spark cloud login

compilaciĂłn:

c:\users\usuario>spark compile archivo.ino MFRC522.cpp MFRC522.h

flasheo

c:\users\usuario>spark flash sparkID archivo.ino MFRC522.cpp MFRC522.h

Donde sparkID es el ID de cada spark.

Es un poco tedioso trabajar con esta consola pero parece ser el Ășnico camino.

NOTA: No olvidar los tres archivos en la raiz de trabajo y quitar en el include de la libreria el subdirectorio.

#include "MFRC522/MFRC522.h" >>>> #include "MFRC522.h"

TRADUCCION POR GOOGLE.COM

I worked example and the library of RFID - RC522 found in the Web IDE and everything worked ok (detection and card reading ) . Wanting to make an App mia I could not upload to the web IDE Spark bookstores . Always answered not find them. With Spark -CLI compile and flashee the .ino files, .h and .cpp .

Working with Windows 7 and generic user (user). The console opens in c: \ users \ user \ and then put the .ino files, MFRC522.hy MFRC522.c .

To compile releases a .bat file to run :

Local login and cloud

spark login

spark cloud login

compilation:

c: \ users \ username > spark archivo.ino compile MFRC522.cpp MFRC522.h

flash

c: \ users \ username > spark flash sparkID archivo.ino MFRC522.cpp MFRC522.h

SparkID Where is the ID of each spark .

It's a bit tedious to work with this console but it seems the only way.

NOTE : Do not forget the three files in the root and remove work in the library include the subdirectory.

My problem is that sometimes spark will not start or turn ten or fifteen minutes after connected . Someone this happens ?

@peekay123 Sorry for the delayed response, had another fire to put out over the last week.
Anyway, correct the non-working library is spitting out garbage. I have an rfid reader app on my phone and it can read both tag types. The tag UIDs should be 83 B0 E3 C7 for the 1k and 04 3F C3 C2 83 36 80 for the Ultralight. (4 bytes for the 1k and 7 bytes for the Ultralight).

Yes, the Arduino version works perfectly. I’ll do a print screen when I get home and post it for you.

@peekay123 Here’s the Arduino output and the hyperlink to the files I used:

Print block 0 of a MIFARE PICC
Card UID: 83 B0 E3 C7 PICC type: MIFARE 1KB
83 B0 E3 C7 17 08 04 00 69 73 73 69 35 36 35 30
Card UID: 83 B0 E3 C7 PICC type: MIFARE 1KB
83 B0 E3 C7 17 08 04 00 69 73 73 69 35 36 35 30
Card UID: 83 B0 E3 C7 PICC type: MIFARE 1KB
83 B0 E3 C7 17 08 04 00 69 73 73 69 35 36 35 30
Card UID: 04 3F C3 C2 83 36 80 PICC type: MIFARE Ultralight or Ultralight C
PCD_Authenticate() failed: Error in communication.
Card UID: 04 3F C3 C2 83 36 80 PICC type: MIFARE Ultralight or Ultralight C
PCD_Authenticate() failed: Error in communication.
Card UID: 04 3F C3 C2 83 36 80 PICC type: MIFARE Ultralight or Ultralight C
PCD_Authenticate() failed: Error in communication.
Card UID: 04 3F C3 C2 83 36 80 PICC type: MIFARE Ultralight or Ultralight C
PCD_Authenticate() failed: Error in communication.

@Ambition1906, can you tell me which Arduino model and voltage you are using?

The fact that the reader works on the Arduino tells me these may be likely:

  1. The current available on the Spark 3.3v pin is not adequate
  2. The timing of the Spark SPI is off vs the Arduino
  3. The code works but some data types are not matched (eg int on Core is 4 bytes but 2 bytes on Arduino)

How are you powering the RC522 with the Arduino?

I will verify how the Core defines certain types (byte, char) used in the code. The best approach is to verify that communications works first. If it does, then it is a data type issue. Do you have a logic analyzer to test the SPI with?

I don’t have a unit to test with so I will have to order one but it will take a while (3+ weeks) to get to me (from China to Canada).

@peekay123, its a UNO R3 Arduino.

I think it may be 2.The timing of the Spark SPI is off vs the Arduino. as you suggested.
I have the Arduino connected to the RC522 just like this

I don’t have a logic analyzer. I can probably get my hands on one next weekend and record the SPI signals to see if the rising and falling edges of the data streams look correctly spaced apart.

If you have a logic analyzer, I could send you a RC522 to test. If you PM me an address I can priority flat rate mail it to you. Im sure it would get there quicker than 3 weeks. Last time I sent something to Canada, it got there within a week.

@Ambition1906, I do have a logic analyzer! I will PM you with my details and please make sure to include the necessary tags/cards for testing. Sorry for the hassles! I look forward to getting this library fixed once and for all :stuck_out_tongue:

2 Likes

@peekay123 Great! yeah, I’ll send you the RC522 reader board, a 1k tag and a Ultralight tag. Its no hassle, I really appreciate your help.

2 Likes

I got the SainSmart RFID-RC522 working with the MF’er library! Just a fair warning that the fob that came with the board doesn’t work. All the other tags I got from Adafruit work fine however. Even the card that half melted while trying to look at the RFID internals by placing it over a halogen lamp. Ooops!

Thanks a ton to everyone who chipped in here! I believe my boss now owes me a 3D printer (for work, naturally).

3 Likes

@wgbartley, what changes did you make to the library to get it working? Can you do a screen print to show what is read on the serial port when you place a tag in front of the reader?

Fortunately I didn’t have to make any changes to the code. I did have to triple-check all my wiring. Here’s the basic code I started with:

// This #include statement was automatically added by the Spark IDE.
#include "MFRC522/MFRC522.h"

#define SS_PIN SS
#define RST_PIN D2

MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.

String lastRfid = "";

void setup() {
    Serial.begin(57600);
    
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    
    mfrc522.PCD_Init();
}

void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }
    
    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }
    
    
    // Dump UID
    String rfid = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
        rfid += mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ";
        rfid += String(mfrc522.uid.uidByte[i], HEX);
    }
    
    rfid.trim();
    rfid.toUpperCase();

    // Prevent multiple scans
    if(rfid==lastRfid)
        return;
    
    lastRfid = rfid;
    Serial.println(rfid);
}

The output looks like:

Card UID: 84 C4 17 53
Card UID: 97 4C 2D 21
Card UID: 34 26 EA 3F
Card UID: C5 F5 CC 28
Card UID: 13 D2 27 D0
Card UID: 9D 97 82 FF
3 Likes

@wgbartley, thanks for the data dump. I notice your output says “Card UID:” but your code doesn’t define that text. Do you have the exact code you used to produce that output?

@Ambition1906, you can see it here: https://github.com/pkourany/MFRC522_RFID_Library/blob/master/firmware/MFRC522.cpp#L1069

It’s part of a function in the library but not sure where @wgbartley called it :wink:

2 Likes

@kennethlimcp, thanks for pointing that out. I thought all the print functions were in the ino file.

Hi,

Just to let you know that I used the MFRC522 found on the Web IDE and have absolutely no problem (Read/Write to blocks using default key, Card Serial number dump) working with the RC522 hardware as shown at the top of this thread. I have also connected the set with a 0.9" OLED display which also require SPI and they works together happily without any problem.

MIFARE 1k cards and key rings were used.

–Ed

2 Likes

@edwintam, @kennethlimcp, @wgbartley thanks for trying to help out but I should have been clearer in identifying the issue. The issue is that the library does not work for all Mifare cards identified in the file. I am using 1k cards and Ultralight cards in my application. The Ultralight cards are not being read correctly. The 1k cards are being read. If any of you have Ultralight cards (or cards other than 1k), let me know if you can confirm this issue in your setup.

1 Like

@Ambition1906 - The Serial.println(rfid); is where it was printing. Once I had the example code running, I quickly mangled it to suit my own purposes, so I stripped out the “Card UID:” text. Sorry about that confusion!

The cards I have are from the Adafruit MiFare Classic (13.56 MHz) tag assortment - 1KB set. I’m just now getting into RFID. I think I have a whopping 8 hours of hacking on it under my belt, so it’s all pretty new to me.

2 Likes

@wgbartley, ok thanks for the update.

@peekay123 - I’ve submitted a pull request for the MFRC522_RFID_Library that adds some updates from the original library:

  • PCD_RxGain enum
  • PCD_AntennaOff()
  • PCD_GetAntennaGain()
  • PCD_SetAntennaGain()
  • MIFARE_GetValue()
  • MIFARE_SetValue()
  • MIFARE_OpenUidBackdoor()
  • MIFARE_SetUid()
  • MIFARE_UnbrickUidSector()

I wanted the PCD_SetAntennaGain() functionality to see if I could get better range out of the device. Setting it to RxGain_max resulted in about an extra cm of range. Too bad it’s still half of what my boss wants.

Does anyone know of a reasonable way to get 6" range out of these things? One doesn’t ship from China and take 2-4 weeks to arrive?

1 Like

As always, the folks looking to show how these system can be broken are ahead in the game:

http://www.eng.tau.ac.il/~yash/kw-usenix06/

See particularly sections 3 and 4.

1 Like