Getting the RFID-RC522 to work! [SOLVED]

@denis222, unfortunately I'm not very familiar with the PIC platform. The original Arduino library I ported is here. The issue I identified with variable types is:

This affected the reading of some cards. I can't speak to writing to the cards but members have not flagged this as a problem. You may want to try to get in touch with the original library author.

Well it was only a matter of time before everyone started trying this even a relative beginner such as myself. I purchased RFID-RC522A
Note the ā€œAā€ ā€“ Did I get the wrong card for this library?

I have soldered the pins (I had to learn to solder to do this) and hooked everything up to sparticale core as advised in the comments of dump.info in the library. The little red led on RFID-RC522 lit up. I took wgbartleyā€™s code which compiled and flashed without issue. But after various attempts at debugging I canā€™t tell if my RC is connected or if my RFID fobs are the wrong kind or donā€™t work ā€¦ how can I determine if the card is connected?

Some photos of the pins and the current set-up. I have also tried this code:

ā€œCard NOT detectedā€

Here is how I have it hooked up.

Great thread but the answer to getting RC522 to work is still unclear to me.

My goal is to Spark.publish the RFID tag to the spark cloud. It should be simple enough but at the moment I canā€™t even get the example dumpinfo.ino to read my cards. My plan was to get dumpinfo.ino working and then modify it to publish the tag to sparkā€™s cloud API as well as light the onboard D7 LED.

I notice that MISO, MOSI, SCK & SDA(SS) donā€™t seem to be #define in the example dumpinfo.ino document (and libraries) - might this be where iā€™m going wrong?

Any advice would be much appreciated @peekay123 & @ParticleCommunity

Thanks everyone! :smile:

Are you hooking them up correctly?

Itā€™s using the default SPI pin - http://docs.particle.io/core/hardware/#pins-and-i-o-spi

1 Like

@Jak, the library uses hardware SPI and you only specify the SS and RST pins. So as @kennethlimcp pointed out and as described at the top of the DumpInfo.cpp file, you need to hook up the SPI line correctly:

Function           Core Pin       MRFC522 Pin
 Reset             ANY (D2)	     RST
 SPI SS            ANY (A2)	     SDA
 SPI MOSI          A5		     MOSI
 SPI MISO          A4		     MISO
 SPI SCK           A3		     SCK

:smile:

Thanks for such rapid replies!

I have hooked it up as suggested and changed how I reading reading the serial output (now using Arduinoā€™s Serial Monitor on OSX.). it read like a charm!!! Thank you ever so much.

Last cheeky question: do you know what the Spark.publish command would be to post the UID (tag) to the spark cloud?

Many Thanks, Jak

@Jak, using Spark.publish() requires that you have the UID in a character string format. Second, and only for now (but donā€™t take my word for it), the string canā€™t be longer than 63 characters (or 255 if Iā€™m full of doodoo). With this being satisfied, the publish would look like:

Spark.publish("myUID", uidstring, 60, PRIVATE);
- myUID is the published event name
- udistring is the string representation of the UID (63 chars max)
- 60 is the TTL
- PRIVATE means it is not seen by the public, only devices/services on your account

:smile:
1 Like

Are you guys doing all this magic with a Spar Core or a Photon? I got my Photon a few days ago with the latest firmware (0.4.3) and all it does when I flash your library on it is flashing red in a weird pattern then resetting and flashing againā€¦ Any Ideas what the problem might be or in which direction I have to dig further?

@ramboldio, Iā€™ll be porting all my libraries to Photon when the official firmware is released to the IDE this coming week. :smile:

@peekay123 :thumbsup: :thumbsup: :thumbsup: Extremley Awesome :wink:

Sounds great @peekay123, canā€™t wait!

Doesnā€™t look like there is any new code it the [Github] (https://github.com/pkourany/MFRC522_RFID_Library) since Jan 24, 2015.
Iā€™m also getting the SOS red blinkingā€¦ Not sure what to do now :frowning:

@anlek, not sure why there is an SOS but Iā€™ll be hooking up a Photon and rfid reader tonight to get a sense of whatā€™s going on.

Thanks! I am using just the basic code found here and used RST pin D2, D3 and A1 and always ending with a red SOS.
Iā€™m now at the point of trying Particle Dev and flashing is working but it seems NONE of the code is being executed, even a simple Particle.publish("Working", "yes"); is not firing.

1 Like

To make it even simpler, Iā€™m trying to flash the Photon (v0.4.5) with this code (Iā€™ve also included the MFRC522 library):

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

#define SS_PIN      A2
#define RST_PIN     A1

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

void setup() {

}

void loop() {

}

And I get the red SOS blinks.

@anlek, are you compiling locally? To get your code working, the bootloader and both system parts needs to be updated.

Nope, that was on the web UI.
I tried compiling locally but it seems to not compile locally. I mean it works but it uploads and nothing happens. (No SOS lights though)

@anlek, I believe I found the problem. Even with local build, I got the same results as you - SOS. Looking at the code I realized that the SPI configuration was being split between the demo app and the MFRC522 constructor. Moving the entire SPI config out of the constructor and into the setSPIConfig() function of the class then calling it in setup() of the demo app removed the problem. The unpredictable nature of class constructor initialization is what I believe caused the problem. I have posted the fix to the repo and the web IDE. :smile: