Buongiorno a tutti,
come da oggetto sto impazzendo con un lettore NFC/RFID acquistato su internet.
Viene venduto con queste caratteristiche: Lettore/scrittore NFC/RFID dotato di 1 LED di stato, antenna integrata sul PCB, interfaccia di comunicazione I²C, SPI e HSU (High Speed UART). Può funzionare come lettore/scrittore di RFID card, come lettore NFC con smartphone Android e in modalità wireless con due dispositivi identici. Può essere utilizzato con Arduino per realizzare dispositivi di controllo accessi, ecc. La confezione comprende il lettore, un trasponder a portachiavi, un trasponder a tessera e i cavetti di collegamento.
Ho scaricato le Librerie PN532, PN532_HSU, PN532_I2C, PN532_SPI in modo da poterlo utilizzare come voglio.
Mi sono messo alla ricerca di un programma già fatto su google ed ho trovato molte cose carine tra cui una guida per vedere se tutto funziona prima di creare apri porta o altro.
Ho aperto l'esempio contenuto nelle librerie scaricate (iso14443a_uid) e notando che veniva inclusa la libreria PN532_SPI.h ho programmato il lettore come SPI.
Collegato il tutto ad Arduino UNO ho inviato il programma e da Monitor Seriale ho atteso la lettura della tessera quando l'ho avvicinata al lettore.
Il messaggio è stato:
Hello!
Didn't find PN53x board
Non trovo PN53x ??? :o
Da qui in poi ho trascorso almeno 3 ore su google alla ricerca del problema ma niente notizie utili.
Lo Sketch è il seguente:
/**************************************************************************/
/*!
This example will attempt to connect to an ISO14443A
card or tag and retrieve some basic information about it
that can be used to determine what type of card it is.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
To enable debug message, define DEBUG in PN532/PN532_debug.h
*/
/**************************************************************************/
#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"
PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
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);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void loop(void) {
boolean 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)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// wait until the card is taken away
while (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength)) {}
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}