I am using a library that prints out the "card number" when it detects a NFC tag with the MFRC522. It doesn't print it out in a normal fashion but uses a custom function to print out the card number, "rfid.showCardID(serNum);". When I hover over the "showCardID" part, it shows that the parameter is "unsigned char * id". I want to capture the output in Serial monitor and store that as a variable to compare. The reason why I am using this particular library and not the newer/common one is because I can set MISO to any pin I want. Before, the MFRC522 would not play nice with being on the same MISO pin as my LCD display. The code I am using is just to test the RFID.
Parts:
Arduino Mega
RFID scanner - Mifare RC522 : Amazon.com: HiLetgo 3pcs RFID Kit - Mifare RC522 RF IC Card Sensor Module + S50 Blank Card + Key Ring for Arduino Raspberry Pi : Electronics
3.5 Inches TFT LCD Touch Screen - 480x320 SPI Serial ILI9488 : Amazon.com: Hosyond 3.5 Inches TFT LCD Touch Screen Shield Display Module 480x320 SPI Serial ILI9488 with Touch Pen Compatible with Arduino R3/Mega2560 Development Board : Electronics
Code:
#include"rfid.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
RFID rfid;
#define relayPin 8
uchar serNum[5];
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
rfid.begin(7, 52, 51, 53, 9, 8);//rfid.begin(IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN)
delay(100);
rfid.init();
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin,HIGH);
//Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
delay(2000);
}
void loop()
{
uchar status;
uchar str[MAX_LEN];
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK)
{
return;
}
rfid.showCardType(str);
status = rfid.anticoll(str);
if (status == MI_OK)
{
//Serial.print("The card's number is: ");
lcd.setCursor(0,0);
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);
// Check people associated with card ID
uchar* id = serNum;
if( id[0]==0x0E && id[1]==0x8F && id[2]==0x8A && id[3]==0x3F )
{
digitalWrite(relayPin,LOW);
// Serial.println("Hello Dannel!");
lcd.setCursor(0,1);
lcd.print(" Hello Dannel! ");
delay(2000);
lcd.clear();
digitalWrite(relayPin,HIGH);
}
else if(id[0]==0x5A && id[1]==0xE4 && id[2]==0xC9 && id[3]==0x55)
{
digitalWrite(relayPin,LOW);
//Serial.println("Hello SunFounder");
lcd.setCursor(0,1);
lcd.print("Hello SunFounder");
delay(2000);
lcd.clear();
digitalWrite(relayPin,HIGH);
}
else
{
//Serial.println("Hello unkown guy!");
lcd.setCursor(0,1);
lcd.print("Hello unkown guy");
delay(2000);
lcd.clear();
}
}
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
delay(2000);
rfid.halt(); //command the card into sleep mode
}