I picked up a Vellman VMA405 RFID reader/writer not noticing it wasn't Arduino. I found examples for a base mfrc522 on GitHub and an example on YouTube. The Arduino Mega is sending to the Serial port, but doesn't seem to read the card or fob. Is there something different with them? The connectors didn't seem bad and the serial monitor is getting the, "Scan PICC to see UID...". maybe something like a 5 instead of 4 product array?
// Here's the code:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); //Create MFRC522 instance.
int readsuccess; //pin 13?
byte readcard[4];
char str[32] = "";
String StrUID;
void setup() {
Serial.begin(9600); //initialize serial communication with PC
SPI.begin(); //Init SPI bus
mfrc522.PCD_Init(); //init MFRC522 card
Serial.println("Scan PICC to see UID...");
Serial.println("");
}
// =========================================
void loop() {
readsuccess = getid();
if(readsuccess){
Serial.println(StrUID);
Serial.println("");
/*
if (StrUID=="Fob Number") {
Serial.println("Status : Registered");
Serial.println("");
}
else if (StrUID=="Fob Number") {
Serial.println("Status : Registered");
Serial.println(""); // However many Fobs.... else ifs
}
else {
Serial.println("Status : Unknown");
Serial.println("");
} */
}
}
// =========================================
int getid(){
if(!mfrc522.PICC_IsNewCardPresent()){
return 0;
}
if(!mfrc522.PICC_ReadCardSerial()) {
return 0;
}
Serial.println("The UID of the scanned card is:");
for(int i=0;i<4;i++){
readcard_=mfrc522.uid.uidByte*; //storing the UID of the tag in readcard*_
* array_to_string(readcard, 4, str);
_ StrUID = str;_
_ }_
mfrc522.PICC_HaltA();
_ return 1;_
_}_
_// =========================================_
void array_to_string(byte array[], unsigned int len, char buffer[])
_{_
_ for (unsigned int i = 0; i < len; i++)_
_ {_
_ byte nib1 = (array >> 4) & 0x0F;
byte nib2 = (array >> 0) & 0x0F;
buffer[i*2+0] = nib1 <0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 <0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len2] = '\0';
}_