극한의 아두이노 DIY생활 - NFC RC카4
안녕하세요 Jimae입니다.
NFC가 SPI통신으로 사용하고 라이브러리를
https://github.com/addicore/AddicoreRFID
이것을 사용하는대 음 문제는 데이터가 어떤식으로 들어오느냐가 문제내요.
https://www.hadex.cz/navody/m490a.pdf
이 PDF 파일에 그 해답이 있습니다.
언어가 영어지만 이런식으로 모듈을 제조하는 업체에서 사용하는 방법에대해 어떻게 할것인지 이렇게 정리를해서 유포를 합니다.
PDF의 자료를 따르면 이렇게 배선을 해야합니다.
그리고 라이브러리를 어떻게 추가하는지와 라이브러리의 링크도 있습니다.
하나하나 따라하다보면 NFC의 모듈을 사용하는 방법을 알수있습니다.
// Example sketch to read the ID from an Addicore 13.56MHz RFID tag
// as found in the RFID AddiKit found at:
// http://www.addicore.com/RFID-AddiKit-with-RC522-MIFARE-Module-RFID-Cards-p/126.htm
#include <AddicoreRFID.h>
#include <SPI.h>
#define uchar unsigned char
#define uint unsigned int
//4 bytes tag serial number, the first 5 bytes for the checksum byte
uchar serNumA[5];
© Addicore LLC 2015 v1.2
uchar fifobytes;
uchar fifoValue;
AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module
/////////////////////////////////////////////////////////////////////
//set the pins
/////////////////////////////////////////////////////////////////////
const int chipSelectPin = 10;
const int NRSTPD = 5;
//Maximum length of the array
#define MAX_LEN 16
void setup() {
Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 9600bps
// start the SPI library:
SPI.begin();
pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE
pin
digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
pinMode(NRSTPD,OUTPUT); // Set digital pin 10 , Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);
myRFID.AddicoreRFID_Init();
}
void loop()
{
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr; //Selection operation block address 0 to 63
String mynum = "";
str[1] = 0x4400;
//Find tags, return tag type
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
Serial.println("RFID tag detected");
Serial.print(str[0],BIN);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.println(" ");
}
© Addicore LLC 2015 v1.2
//Anti-collision, return tag serial number 4 bytes
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
{
checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
Serial.println("The tag's number is : ");
//Serial.print(2);
Serial.print(str[0]);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.print(" , ");
Serial.print(str[2],BIN);
Serial.print(" , ");
Serial.print(str[3],BIN);
Serial.print(" , ");
Serial.print(str[4],BIN);
Serial.print(" , ");
Serial.println(checksum1,BIN);
// Should really check all pairs, but for now we'll just use the first
if(str[0] == 156) //You can change this to the first byte of your tag by finding the card's ID
through the Serial Monitor
{
Serial.print("Hello Craig!\n");
} else if(str[0] == 244) { //You can change this to the first byte of your tag by finding the card's ID
through the Serial Monitor
Serial.print("Hello Erin!\n");
}
Serial.println();
delay(1000);
}
myRFID.AddicoreRFID_Halt(); //Command tag into hibernation
}
결국 PDF의 자료를 따라하고 위의 예제소스를 동작하다보면
MFRC522 Software Version: 0x92 = v2.0
Scan PICC to see UID, type, and data blocks...
Card UID: 04 EE D3 5A D4 48 80
PICC type: MIFARE Ultralight or Ultralight C
Page 0 1 2 3
0 04 EE D3 B1
1 5A D4 48 80
2 46 48 00 00
3 E1 10 12 00
4 01 03 A0 0C
5 34 03 00 FE
6 00 00 00 00
7 00 00 00 00
8 00 00 00 00
9 00 00 00 00
10 00 00 00 00
11 00 00 00 00
12 00 00 00 00
13 00 00 00 00
14 00 00 00 00
15 00 00 00 00
Card UID: 04 22 CE 5A D4 48 81
PICC type: MIFARE Ultralight or Ultralight C
Page 0 1 2 3
0 04 22 CE 60
1 5A D4 48 81
2 47 48 00 00
3 E1 10 12 00
4 01 03 A0 0C
5 34 03 00 FE
6 00 00 00 00
7 00 00 00 00
8 00 00 00 00
9 00 00 00 00
10 00 00 00 00
11 00 00 00 00
12 00 00 00 00
13 00 00 00 00
14 00 00 00 00
15 00 00 00 00
Card UID: 04 3E C9 5A D4 48 80
PICC type: MIFARE Ultralight or Ultralight C
Page 0 1 2 3
0 04 3E C9 7B
1 5A D4 48 80
2 46 48 00 00
3 E1 10 12 00
4 01 03 A0 0C
5 34 03 00 FE
6 00 00 00 00
7 00 00 00 00
8 00 00 00 00
9 00 00 00 00
10 00 00 00 00
11 00 00 00 00
12 00 00 00 00
13 00 00 00 00
14 00 00 00 00
15 00 00 00 00
처음에 소개한 NFC 전용 스티커로 인식하면 위와 같은 데이터가 들어옵니다.
저는 이때당시 모든 스티커를 읽어보고 NFC의 규칙을 찾아서 각각 번호를 부여 하려고 했었습니다.
어려운 모듈이나 모르는 모듈이 있다고 하더라도 제조업체에서 가이드 라인자료를 줄테니 걱정하지말고 도전을 해도됩니다.
그것을 하나하나 따라하다보면 이해가 될거에요.
오늘은 여기까지 다들 좋은 하루 되세요.
극한의 아두이노 DIY생활 - NFC RC카1
극한의 아두이노 DIY생활 - NFC RC카2
극한의 아두이노 DIY생활 - NFC RC카3
[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.