Skip to content

Instantly share code, notes, and snippets.

@yeffrimic
Created February 17, 2020 17:32
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 yeffrimic/8d9c11ae333de75e42c0f2fa0a1756c9 to your computer and use it in GitHub Desktop.
Save yeffrimic/8d9c11ae333de75e42c0f2fa0a1756c9 to your computer and use it in GitHub Desktop.
/*
* RFID wemos
*
* feb 2020
* Yeffrimic,Xibalba Hackerspace.
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN D4
#define SS_PIN D8
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
mfrc522.PCD_DumpVersionToSerial();
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
}
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment