Hi Guys,
Yesterday I received the arduino RFID module I ordered a while ago:
(http://i61.tinypic.com/29dddsl.jpg)
I've been breaking my head over how to get it to work. It would keep giving me an error "Communication Failure, check connection with RC522" or something like that in the serial monitor.
The connection scheme is pretty straightforward:
(http://i61.tinypic.com/zj7azq.png)
Also GND and 3.3v are connected to the moteino.
But for some reason it just wouldn't work. I tried changing pin 9 to pin 8 (thinking maybe the moteino's led on pin 9 could cause problems). No effect. Changed it to pin 5 (PWM, 8 was not). No effect.
It would always just say:
(http://i58.tinypic.com/2wr3nsj.png)
Then I tried it on my Arduino Uno. Worked like a charm instantly. What could be the difference? Only thing I can think of is that the Moteino's HIGH on the digital pins is 3.3v and the Arduino's HIGH is 5v. Could this be the problem?
Thanks in advance!
Marko
P.S. I already checked for shorts between all soldered parts.
Can you include more details about that module, how it communicates to your Arduino, if it's a 3.3V or 5V logic device?
I'm not exactly sure. Here's a close up of the connections:
(http://i59.tinypic.com/33ma3vs.jpg)
The library: https://github.com/miguelbalboa/rfid
Also, I found this in the datasheet:
(http://i57.tinypic.com/141oc5z.png)
So it uses SPI to communicate with the arduino?
The sketch I used is the example "Dumpinfo".
/*
* ----------------------------------------------------------------------------
* This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
* for further details and other examples.
*
* NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
*
* Released into the public domain.
* ----------------------------------------------------------------------------
* Example sketch/program showing how to read data from a PICC (that is: a RFID
* Tag or Card) using a MFRC522 based RFID Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout
* below), load this sketch into Arduino IDE then verify/compile and upload it.
* To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M).
* When you present a PICC (that is: a RFID Tag or Card) at reading distance
* of the MFRC522 Reader/PCD, the serial output will show the ID/UID, type and
* any data blocks it can read. Note: you may see "Timeout in communication"
* messages when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs
* presented (that is: multiple tag reading). So if you stack two or more
* PICCs on top of each other and present them to the reader, it will first
* output all details of the first and then the next PICC. Note that this
* may take some time as all data blocks are dumped, so keep the PICCs at
* reading distance until complete.
*
* Typical pin layout used:
* ------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3
* Signal Pin Pin Pin Pin
* ------------------------------------------------------------
* RST/Reset RST 9 5 D9
* SPI SS SDA(SS) 10 53 D10
* SPI MOSI MOSI 11 / ICSP-4 51 D11
* SPI MISO MISO 12 / ICSP-1 50 D12
* SPI SCK SCK 13 / ICSP-3 52 D13
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 //
#define SS_PIN 10 //
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
Serial.println("Scan PICC to see UID, type, and data blocks...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("MFRC522 Software Version: 0x");
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(" = v1.0");
else if (v == 0x92)
Serial.print(" = v2.0");
else
Serial.print(" (unknown)");
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println("WARNING: Communication failure, is the MFRC522 properly connected?");
}
}
P.S. Is there a way to keep the IMG size under control? =p
Could it be the SPI bit rate? Think I found another toy to waste time with!!!
Is there a way to check the SPI bitrate? And does the moteino's differ from an Arduino Uno? It would explain it.
I think the first place to start is to reassign the RFID SS & Reset pins to something other than pins 9 & 10. These are already used by the Moteino. D9 for LED and D10 for SS on the RFMxx module.
You should be able to move the pins to something unused (like 3,4,5,6,7) and change the pin values in the sketch.
Also, you should be able to read the atmega328P registers to see what the SPI base frequency is. Moteino default is 4MHz which may be too fast for the RFID module (I don't have either spec handy so can't provide any more info at this point in time...)
You may need to put some 'peaceful coexistence' code into the RFID driver to keep from stomping on RFMxx code (see RFM69 select() and unselect() methods for good examples on how to do this).
Tom
BTW, I once knew a woman who, when I mentioned R F I D, said that she didn't know what that was but knew what the 'F' stood for. She was wrong...
Thanks for the reply. I just tried resoldering the D10 to D3 (D9 was already moved to D5). No joy.
Also I found this in the datasheet:
8.1.2 Serial Peripheral Interface
A serial peripheral interface (SPI compatible) is supported to enable high-speed
communication to the host. The interface can handle data speeds up to 10 Mbit/s. When
communicating with a host, the MFRC522 acts as a slave, receiving data from the
external host for register settings, sending and receiving data relevant for RF interface
communication.
Guess it supports up to 10Mbit.
Shouldn't by the way, since I'm not even including the RFM library for now, the RFM pinout have no effect at all at the arduino operation?
I got it to work!
Read this on http://arduino.cc/en/Reference/SPI :
Note about Slave Select (SS) pin on AVR based boards
All AVR based boards have an SS pin that is useful when they act as a slave controlled by an external master. Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.
Tried it:
(http://i59.tinypic.com/dc4ol0.png)
(https://mjanja.ch/wordpress/wp-content/uploads/2013/09/borat_great_success.jpg)
Thanks for pointing me in the right direction (SPI) guys.
Hi Istria,
I am facing the same problem trying to connect an RC522 RFID reader (the same as your photo) with Moteino to build an access control system with a remote reader.
Until now I was not able to obtain a working prototype due to the "interferences" between the RC522 and the RF69HW module over the SPI port.
I followed your suggestions about pin assignments and initial configuration for SS and RST, but without success.
Can you please post the code of your solution to help me solve the problem?
Thank you in advance!
Regards
Hi,
I still haven't got around to actually using the RFID thing for something. I tried to find the code I was using back then. I think this was the one. See attachment.
I think it did something like scan the UID of the card and then send it to a second Moteino which would print it to serial monitor. Just a POC thingy.
For me, it always worked on an Arduino Uno (scanning the card, not sending =p ). Even without setting the pin to OUTPUT. But on the Moteino and Pro Mini it was necessary for it to work.
Just a tip:
Later I also noticed it had a power problem. I was powering it (as well as the Moteino or Arduino Pro Mini 3.3v) from a USB to Serial FTDI converter. It read the small key chain tags perfectly, but the normal cards very difficultly and more often then not, it would just not see them. I thought for months it was the cards, but connecting a better power supply made it read cards perfectly as well.
Let me know if it works! Good luck.