2

I'm using an RC522 RFID reader with an Arduino UNO. There is a function?? (or whatever it's called :)) in Miguel Balboa's new MFRC522.h library which is mfrc522.uid.uidByte[i] that prints the bytes of the unique ID. The repetition of the function results in 8 piece of HEX digits that are from the 2 numbers that each function outputs (2+2+2+2=8). Whenever I use the line of codes that are commented out, the serial monitor outputs them successfully. So for example, 12345678 is the unique id, each array displayed 12, then 34, then, 56, then 78 which is 12345678 in the serial. which is fast and unnoticeable besides that there are no spaces included when on output. The thing is, I want to output all of these into a single variable.(Please help me also on how to concatenate) How can I do this? An attempt was done below (not commented out) but it outputs only the number 16, consistently, which is I think due to a data type problem. The variables are initialized as int. The "function" which I found in the library is initialized as byte (correct me If I'm wrong). But when the variables are initialized as byte, I cannot upload the sketch since there are errors. Please help. :( (The reason I need it to be saved into a single variable is because I am placing it in the GET method of an Ethernet Client. I don't think the bare function can do that. (Or if it can, can you please help with the code? :)) Thanks

 
// Dump UID
        //Serial.print("Card UID:");

//Serial.print(mfrc522.uid.uidByte[0], HEX); //Serial.print(mfrc522.uid.uidByte[1], HEX); //Serial.print(mfrc522.uid.uidByte[2], HEX); //Serial.print(mfrc522.uid.uidByte[3], HEX); serNum0={mfrc522.uid.uidByte[0], HEX}; serNum1={mfrc522.uid.uidByte[1], HEX}; serNum2={mfrc522.uid.uidByte[2], HEX}; serNum3={mfrc522.uid.uidByte[3], HEX}; Serial.print(serNum0); Serial.print(serNum1); Serial.print(serNum2); Serial.print(serNum3);
2

As far as I can understand, you expect to receive byte data from the RFID reader, you would like to store this data into a single variable, and eventually print its content, or manipulate it in some way. You could do this maintaining a byte array (or uint8_t array).

Let's suppose, for example, to receive a unique ID of length 4 from the RFID reader. In this case you could simply store it into a serNum[serNum_size] array, where serNum_size is just the number of data you are expecting to receive, and later access its content for whatever manipulation you would like to do.

int serNum_size = 4;        // reader data size
byte serNum[serNum_size];   // reader data content

for(int i = 0; i < serNum_size; i++){
 serNum[i] = mfrc522.uid.uidByte[i]; // store reader data block
 Serial.print(serNum[i], HEX);       // hexadecimal form
}

As far as the print is concerned, you can simply print the byte entry and apply the HEX format. In this way, the stored value will be considered as its hexadecimal value.

  • Welcome to Arduino SE! Can you add a bit of explanation to your answer explaining how this works, etc.? Thanks! – Anonymous Penguin Mar 7 '15 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.