I want to print the UID of a card as an HID with the Arduino Leonardo.
Here is the code that I have
void loop() {
if ( mfrc522.PICC_IsNewCardPresent()) {
// Select one of the cards
if ( mfrc522.PICC_ReadCardSerial()) {
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Keyboard.print(mfrc522.uid);
}
}
}
and this is what the compiler says
note: no known conversion for argument 1 from 'MFRC522::Uid' to 'const Printable&'
exit status 1
Does anyone know how to do it?
I believe that the isse you are facing is that you are trying to print a MFRC522::Uid
which is a HEX number such as 00 00 00 00
while the keyboard.print()
only accepts char
, int
or string
according to: Arduino.cc. I found the following code snippet here. I believe it might resolve your issue. It should write: "Card UID: 00 00 00 00"
.
Serial.print("Card UID:"); //Dump UID
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
NOTE: If you are using Keyboard.print()
I believe you need to use Keyboard.begin()
in your setup method.