Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 23, 2020 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/bff603dc879b7eb7da95d804c213f0bc to your computer and use it in GitHub Desktop.
Save parzibyte/bff603dc879b7eb7da95d804c213f0bc to your computer and use it in GitHub Desktop.
void loop()
{
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if (!reader.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards. This returns false if read is not successful; and if that happens, we stop the code
if (!reader.PICC_ReadCardSerial())
{
return;
}
// At this point, the serial can be read. We transform from byte to hex
String serial = "";
for (int x = 0; x < reader.uid.size; x++)
{
// If it is less than 10, we add zero
if (reader.uid.uidByte[x] < 0x10)
{
serial += "0";
}
// Transform the byte to hex
serial += String(reader.uid.uidByte[x], HEX);
// Add a hypen
if (x + 1 != reader.uid.size)
{
serial += "-";
}
}
// Transform to uppercase
serial.toUpperCase();
Serial.println("Read serial is: " + serial);
// Halt PICC
reader.PICC_HaltA();
// Stop encryption on PCD
reader.PCD_StopCrypto1();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment