-
Notifications
You must be signed in to change notification settings - Fork 0
/
RC522-UID-HEX-array.ino
70 lines (55 loc) · 2.3 KB
/
RC522-UID-HEX-array.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <SPI.h>
#include <MFRC522.h>
#include <Keyboard.h>
#include <ctype.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
char UID_buff[100];
String UIDstring = String(UID_buff);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
// Serial1.begin(9600); // Initialize serial for bluetooth link only for bluetooth version
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
// ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details for debug only
// Serial.println(F("Skanuj PICC aby zobaczyć UID...")); //=== this line for debug only
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) { //=== Look for new cards
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) //=== Select one of the cards
return;
// Serial.print("Card UID:"); //Dump UID , this line for debug only
String rfidUid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
rfidUid += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
rfidUid += String(mfrc522.uid.uidByte[i], HEX);
}
Serial.println(rfidUid); //=== Dump UID for debug
// Serial.println("");
rfidUid.toCharArray(UID_buff, rfidUid.length()+1); //=== Create array for bluetooth link and HID keyboard
// Serial1.println(UID_buff); // Send array to bluetooth, This line only for bluetooth version
Keyboard.println(rfidUid); //===Send UID to keyboard
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1();// Stop encryption on PCD
}
/* //===================== for debug only
void ShowReaderDetails() {
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); // Get the MFRC522 software version
Serial.print(F("NFC Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (Spartan 1.0)"));
Serial.println("");
if ((v == 0x00) || (v == 0xFF)) { // When 0x00 or 0xFF is returned, communication probably failed
Serial.println(F("WARNING: Communication failure, is the module properly connected?"));
}
}
*/ //======================