I have successfully managed to use the MIFARE_Write function to store a servo's position onto an RFID card. I did this by converting the integer to a string, and copying it to a buffer which MIFARE_Write uses to store the data onto the card in the form of hex-represented ASCII ("31 37 38" representing "178").
After looking around in MFRC522.cpp, I have decided to make use of its MIFARE_Read function to "reverse" the process and obtain the hex values so they can be "reassembled" into an integer and used by the servo.
Here is what I have so far:
//READ MODE
} else {
//read from tag
block = 1;
Serial.println(F("Authenticating using key A..."));
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(F("PCD_Authenticate() success: "));
// Read block
status = mfrc522.MIFARE_Read(block, buffer, 16); //<----- I get an error here
if (status != MFRC522::STATUS_OK) {
Serial.print(F("MIFARE_Read() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println(F("MIFARE_Read() success: "));
for (byte emptybuffer = 0; emptybuffer < 16; emptybuffer++)
{
analog_servo1_string[emptybuffer] = buffer[emptybuffer];
}
analog_servo1 = analog_servo1_string.toInt();
servo1.write(analog_servo1);
}
The error I get (at the line indicated by the comment) says:
error: invalid conversion from 'int' to 'byte* {aka unsigned char*}' [-fpermissive]
MFRC522.h:367:13: error: initializing argument 3 of 'MFRC522::StatusCode MFRC522::MIFARE_Read(byte, byte*, byte*)' [-fpermissive]
StatusCode MIFARE_Read(byte blockAddr, byte *buffer, byte *bufferSize);
^
exit status 1
invalid conversion from 'int' to 'byte* {aka unsigned char*}' [-fpermissive]
According to the second line of the error, the issue seems to be specifically with the integer 16 that is being sent. But I don't understand why it wants "bufferSize" to be type "byte *", and I'm not sure how I would satisfy that either.
Thanks!
EDIT: I'd like to add that MIFARE_Write also asks for a byte as the "bufferSize" argument, yet, unlike MIFARE_Read, it does not return an error when 16 is provided.