I'm working with an Adafruit RFID reader (PN532) and I'm using the example code they provided to help me read the ID numbers for each RFID tag. I wanted to use the UID Value for other purposes but I can't seem to figure out which variable is storing the ID number. I thought it was uid[] but since it's a buffer, it's not letting me use it as a variable. I basically want to serial print that UID value later on in the code.
I have attached initial part of the code for your reference. Any help is much appreciated! Thanks!
[code]
void loop(void)
{
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)
//Wait for an ISO14443A type cards (Mifare, etc.)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
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("");
I guess what I'm asking is how to retrieve the ID number stored in the uid[] array to be able to use it later. The UID value shows up in the serial monitor similar to this: "0xF4 0xB3 0x67 0x22" and I wanted to be able to refer to this entire value later. When I try to use just uid an error shows up saying "call of overloaded 'print(uint8_t[7])' is ambiguous". Sorry I'm such a beginner at this!
Ohh I see. I wanted to log this value into Excel using a data logging shield. This is the code that I used to log the value. I wasn't sure what to put in the bracket with the "UNSURE" to be able to log the UID value.
[code]
logfile.print(UNSURE); // Write id number to the SD card
logfile.print(",");
#if ECHO_TO_SERIAL
Serial.print(", ");
Serial.println(UNSURE;
Serial.println("");
#endif //ECHO_TO_SERIAL
sjacob:
I guess what I'm asking is how to retrieve the ID number stored in the uid[] array to be able to use it later. The UID value shows up in the serial monitor similar to this: "0xF4 0xB3 0x67 0x22" and I wanted to be able to refer to this entire value later.
Are you thinking to accommodate your array contents as a numerical value in a single variable? If so, you can use the union data structure:
void setup()
{
Serial.begin(9600);
union
{
uint8_t uid[4] = {0xF4, 0xB3, 0x67, 0x22};
uint32_t x;
} myData;
Serial.print(myData.x, HEX); //Prints: 2267B3F4; take care of endianness of your data
}
void loop()
{
}
Sorry for the late reply. Thanks for all the replies that you've given! I don't think that I've been explaining my situation properly. I'm really new to this so I didn't know the terminology that I should use to explain what's happening. I've attached my full code here so that it's easier to understand what I'm trying to do: [code]#include <SD.h> //load the SD library#include <SPI.h> //load the SPI - Pastebin.com
I have a RFID shield stacked on top of a data logging shield and an Arduino. Every time I detect an RFID tag with the PN532 RFID reader, I want it to log the ID number (looks something like this 0xB4 0x7F 0x66 0x43) into the SD card. I've been trying to use this (Adafruit-PN532/Adafruit_PN532.cpp at master · adafruit/Adafruit-PN532 · GitHub) to figure out what function to use in order to retrieve that ID number. I've been using nfc.PrintHex(uid, uidLength) to print the ID number to the serial monitor. But I'm not sure what to use to print that same number onto the SD card. The code I've pasted down below is what I tried to do to print the ID number based on what you guys were saying before, but it only prints the first section (for example, 0xB4, instead of 0xB4 0x7F 0x66 0x43). I'm not sure why that's happening either. So could anyone help me figure out how to print the ID number onto the SD card?Thanks for all your help! I really appreciate it!
for (uint8_t i=0; i < uidLength; i++)
{
if(uid[i]<0x10);
}
logfile.print(uid[i], HEX); // Write id number to the SD card
logfile.print(",");
#if ECHO_TO_SERIAL
Serial.print(", ");
Serial.print(F(" 0x")); Serial.print(uid[i], HEX);
//nfc.PrintHex(uid, uidLength);
Serial.println("");
#endif //ECHO_TO_SERIAL
Convert your 64-bit (8-byte) ID (which is in this array uint8_t uid[8] = {0x12, 0x34, 0x56, 0x78, 0xF4, 0xB3, 0x67, 0x22} into character array and then write this character array into the SD card using print() method.