Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The power for MFRC522 modile and LCD 5110 is 3.3 volts!!
- Pin for MFRC522:
- -----------------------------------------------------------------------------------------
- MFRC522 Arduino Arduino Arduino Arduino Arduino
- Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
- Signal Pin Pin Pin Pin Pin Pin
- -----------------------------------------------------------------------------------------
- RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
- SPI SS SDA(SS) 10 53 D10 10 10
- SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
- SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
- SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
- Pin for LCD 5110:
- pin 22 - Serial clock out (SCLK)
- pin 23 - Serial data out (DIN)
- pin 24 - Data/Command select (D/C)
- pin 25 - LCD chip select (CS)
- pin 26 - LCD reset (RST)
- */
- #include <SPI.h>
- #include <MFRC522.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_PCD8544.h>
- #define SS_PIN 53
- #define RST_PIN 5
- MFRC522 rfid(SS_PIN, RST_PIN);
- MFRC522::MIFARE_Key key;
- Adafruit_PCD8544 display = Adafruit_PCD8544(22, 23, 24, 25, 26);
- void setup() {
- Serial.begin(9600);
- SPI.begin(); // Init SPI bus
- rfid.PCD_Init(); // Init MFRC522
- for (byte i = 0; i < 6; i++) {
- key.keyByte[i] = 0xFF; // Key used is FF FF FF FF FF FF
- }
- // Init LCD
- display.begin();
- display.setContrast(50);
- display.setTextSize(1);
- display.setTextColor(BLACK);
- display.setRotation(2); // using it upside down
- display.setCursor(0,0);
- display.clearDisplay();
- display.display();
- }
- void loop() {
- // Look for new cards
- if ( ! rfid.PICC_IsNewCardPresent())
- return;
- // Verify if the UID has been readed
- if ( ! rfid.PICC_ReadCardSerial())
- return;
- // Check is the PICC of Classic MIFARE type and exit otherwise
- MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
- if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
- piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
- piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
- return;
- }
- // Print the UID
- SerialPrintHex(rfid.uid.uidByte, rfid.uid.size);
- Serial.println();
- display.clearDisplay();
- display.setCursor(3,display.height()/2-8);
- display.print("UID: ");
- lcdPrintHex(rfid.uid.uidByte, rfid.uid.size);
- // Halt PICC
- rfid.PICC_HaltA();
- }
- // Function for print byte array in hex
- void SerialPrintHex(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? "0" : "");
- Serial.print(buffer[i], HEX);
- }
- }
- void lcdPrintHex(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- display.print(buffer[i] < 0x10 ? "0" : "");
- display.print(buffer[i], HEX);
- display.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement