Error RFID invalid conversion

ShapeShifter:
This is telling you that you have a byte value, which is actually a unsigned char. You are trying to use it as a parameter to a function that is expecting the MFRC522::StatusCode type, and it can't implicitly convert the value for you.

A quick search for MFRC522::StatusCode gives this definition, which is probably what you have in MFRC522.h:

// Return codes from the functions in this class. Remember to update GetStatusCodeName() if you add more.

// last value set to 0xff, then compiler uses less ram, it seems some optimisations are triggered
enum StatusCode : byte {
STATUS_OK , // Success
STATUS_ERROR , // Error in communication
STATUS_COLLISION , // Collission detected
STATUS_TIMEOUT , // Timeout in communication.
STATUS_NO_ROOM , // A buffer is not big enough.
STATUS_INTERNAL_ERROR , // Internal error in the code. Should not happen :wink:
STATUS_INVALID , // Invalid argument.
STATUS_CRC_WRONG , // The CRC_A does not match
STATUS_MIFARE_NACK = 0xff // A MIFARE PICC responded with NAK.
};




So, the type is an enumerated type. While it's encoded as a byte, and you are passing the function a byte, the compiler is giving you that message because it's not necessarily valid to convert any old byte value to the enumerated type. Using the wrong type of parameter is common coding mistake, and the compiler is telling you that you need to make sure that what you're doing is valid.

You can do that by explicitly converting the type yourself:


mfrc522.GetStatusCodeName((MFRC522::StatusCode)status)



This says that the compiler should take the byte value **status** and convert it to **MFRC522::StatusCode** before passing the value to the function. You are telling the compiler that the value is **status** really is a **MFRC522::StatusCode** value, and that the compiler should treat it as one.

That's one way to handle it, but not the best way in this case. Your status value is coming to you as the return value from several different MFRC522 library functions. You are assigning that return value to a variable named **status**, that is of type **byte**. That requires an implicit type conversion from the enumerated status type to the generic numeric byte type. That's a valid implicit conversion from a more specific type to a more general type, and the compiler will do that for you without complaining. But then you are calling GetStatusCodeName() with that byte value, but the compiler won't automatically make the conversion back to the more specific type.

The real answer is to not make that implicit conversion to **byte** in the first place, but instead keep it as a **MFRC522::StatusCode** value. Then there will be no problems passing the value to GetStatusCodeName() since it will already be the correct type. Basically, in your code wherever you are defining you status variable as "**byte status**" you should change it to "**MFRC522::StatusCode status**" and that should get rid of your error messages.

I'm sorry where do I have to put this line of code?

mfrc522.GetStatusCodeName((MFRC522::StatusCode)status)

I'm going crazy