Created
September 30, 2015 19:58
-
-
Save Azuxul/f9d19b3d31725eb34937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Created by Azuxul, September 2015 | |
* http://azuxul.fr/ | |
* | |
* --------------------------------- | |
* | |
* Print UID of RFID card to I2C LCD scren for nano Arduino v3 | |
* | |
* RFID MODULE : RFID-RC522 | |
* LCD : GDM1602A | |
* | |
* Used library : MFRC522, LiquidCrystal | |
*/ | |
#include <SPI.h> | |
#include <MFRC522.h> | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // LCD | |
MFRC522 mfrc522(10, 9); // RFID MODULE | |
void setup() { // Init | |
SPI.begin(); // Init SPI bus | |
mfrc522.PCD_Init(); // Init MFRC522 card | |
lcd.begin(16, 2); // Init lcd | |
// Print txt to LCD | |
lcd.setCursor(0, 0); | |
lcd.print(" -- RFID UID --"); | |
lcd.setCursor(0, 1); | |
lcd.print(" Azuxul "); | |
} | |
void loop() { // Loop start | |
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) { // If no card -> return | |
return; | |
} | |
lcd.clear(); // Clear LCD | |
// Print text to LCD | |
lcd.setCursor(0, 0); | |
lcd.print("..."); | |
String uid = ""; // UID | |
for (byte i = 0; i < mfrc522.uid.size; i++) { // Get UID | |
uid += String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); | |
uid += String(mfrc522.uid.uidByte[i], HEX); | |
} | |
uid.remove(0, 1); // Remove first char (equals to " ") | |
uid.toUpperCase(); | |
lcd.clear(); // Clear LCD | |
// Print text to LCD | |
lcd.setCursor(0, 0); | |
lcd.print("RFID card UID :"); | |
lcd.setCursor(0, 1); | |
lcd.print(uid); | |
// Add delay | |
delay(500); | |
} // Loop end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment