I am working on a project that uses an Adafruit RFID reader with an Arduino UNO. When I test readMifareClassic from the Adafruit PN532 library, it works, and it displays the address of the card. However, when I used the same code in an Arduino sketch, the reader did not identify the cards. I attached an image that shows the result.
The code is added below. Can you assist, please?
Code: Select all
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#define PN532_IRQ (2)
#define PN532_RESET (3) // Not connected by default on the NFC Shield
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
void setup(void) {
Serial.begin(9600);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}
void loop() {
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc.PrintHex(uid, uidLength);
Serial.println("");
/////// Use the address information to save the crediet value
if( uid[0]==12 && uid[1]==209 && uid[2]==114 && uid[3]==59 )
{
Serial.println("Card #1: Ahmed ");
}
if( uid[0]==164 && uid[1]==61 && uid[2]==78 && uid[3]==18 )
{
Serial.println("Card #2: Latifa ");
}
if( uid[0]==131 && uid[1]==130 && uid[2]==27 && uid[3]==188 )
{
Serial.println("Card #3: Amna ");
}
if( uid[0]==243 && uid[1]==102 && uid[2]==29 && uid[3]==188 )
{
Serial.println("Card #4: Mayasa ");
}
if( uid[0]==51 && uid[1]==13 && uid[2]==26 && uid[3]==188 )
{
Serial.println("Card #5: Sara ");
}
if( uid[0]==3 && uid[1]==194 && uid[2]==27 && uid[3]==188 )
{
Serial.println("Card #6: Omer ");
}
}