Ich möchte gerne die UID eines RFID-Chips auslesen und weiter verarbeiten.
Leider klappt das nicht so, wie ich möchte, weshalb ich mal hier nachfrage.
Ich habe meinen Raspberry Pi mit Arduino IDE, an dem habe ich einen Arduino Nano (?) und einen Kartenleser mit PN532-Chip per Software-Serial angeklemmt.
Einen passenden Beispielcode habe ich auch schon gefunden, das funktioniert auch soweit, nur bekomme ich die UID nicht rausgequetscht, damit ich sie weiter verarbeiten kann.
Naiv wie ich bin, dachte ich, ich könnte eine einfache if-Abfrage ab Zeile 75 machen, nach dem Motto if (uid) == ("12ABC789"){, dann digitalWrite(13, HIGH); oder so, das klappt aber nicht.
Ausgabe auf dem seriellen Monitor sieht so aus, aber Abfragen enden bei mir im Chaos.
Starte Programm ...
RFID gefunden:32
Firmware ver. 1.6
Warte auf ISO14443A Karte ...
UID Länge: 4 bytes
UID: 12ABC789
Der Beispielcode:
#include <PN532Interface.h>
#include <llcp.h>
#include <PN532.h>
#include <PN532_debug.h>
#include <mac_link.h>
#include <emulatetag.h>
#include <snep.h>
/*
PN532-NFC-RFID-Module-Library
modified on 18 Nov 2020
by Amir Mohammad Shojaee @ Electropeak
Home
based on www.electroschematics.com Arduino Examples
*/
#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>
SoftwareSerial SWSerial( 7, 8 ); // RX, TX
PN532_SWHSU pn532swhsu( SWSerial );
PN532 nfc( pn532swhsu );
void setup(void) {
Serial.begin(115200);
Serial.println("Starte Programm ...");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Kein RFID-Modul gefunden !");
while (1); // Halt
}
// Got valid data, print it out!
Serial.print("RFID gefunden:"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Warte auf ISO14443A Karte ...");
}
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)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
//Serial.println("Found A Card!");
Serial.print("UID Länge: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(uid[i], HEX);
}
Serial.println("");
delay(2000);
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out! Waiting for a card...");
}
}
Display More
Kann mir da jemand auf die Sprünge helfen ?