RDM6300 (RDM 630) 125khz RFID reader
Pour lire des badges RFID au format EM4100
3 pins de la carte ont besoin d’être reliés à l’Arduino : Vcc au +5v ; GND à la masse ; TX pin à la broche en charge de la liaison RX. Il n’est pas nécessaire de relier la pin RX de la carte car nous ne devons rien envoyer à cette dernière. Enfin, ne pas oublier de relier l’antenne fournie aux broches ANT1 et ANT2 (le sens de branchement n’a pas d’importance).
Pour lire les badges utilisez cette librairie : https://github.com/arduino12/rdm6300
Le fil jaune sur le shéma est relié à la PIN 4 de la carte arduino NANO dans l’exemple ci-dessous.
Et le sketch est le suivant :
#include <Arduino.h>
#include <rdm6300.h>#define RDM6300_RX_PIN 4 // read the SoftwareSerial doc above! may need to change this pin to 10…
#define READ_LED_PIN 13Rdm6300 rdm6300;
void setup()
{
Serial.begin(115200);pinMode(READ_LED_PIN, OUTPUT);
digitalWrite(READ_LED_PIN, LOW);rdm6300.begin(RDM6300_RX_PIN);
Serial.println(« \nPlace RFID tag near the rdm6300… »);
}void loop()
{
/* get_new_tag_id returns the tag_id of a « new » near tag,
following calls will return 0 as long as the same tag is kept near. */
if (rdm6300.get_new_tag_id())
Serial.println(rdm6300.get_tag_id(), HEX);/* get_tag_id returns the tag_id as long as it is near, 0 otherwise. */
digitalWrite(READ_LED_PIN, rdm6300.get_tag_id());delay(10);
}
Lecture de badges 13.56MHZ :
C’est la technologie utilisée par les téléphones portables avec le protocole NFC.
Pour Android, il faut utiliser des puces NTAG 203(F) de type 2.
Les « transpondeurs » (cartes ou badges RFID) sont au protocole MIFARE.
Pour arduino, nous avons choisi d’utiliser la carte basée sur la puce MFRC522 connectée en mode SPI :
CARTE | ARDUINO |
VCC | +5v |
GND | Gnd |
MOSI | Pin 11 |
MISO | Pin 12 |
SCK | Pin 13 |
NSS | Pin 10 (Configurable) |
RST | Pin 9 (Configurable) |
Pour l’utiliser nous avons employé la librairie de Miguel Balboa : RFID
Un exemple de sketch pour la lecture de badge :
/*
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11
* MISO: Pin 12
* SCK: Pin 13
* SS: Pin 10
* RST: Pin 9
*
* Script is based on the script of Miguel Balboa.
* New cardnumber is printed when card has changed. Only a dot is printed
* if card is the same.
* If it's a known card, print the name of the owner !
*/
#include <SPI.h>
#include <RFID.h> //--Import it !
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN);
// Setup variables:
int serNum0;
int serNum1;
int serNum2;
int serNum3;
int serNum4;
void setup()
{
Serial.begin(9600);
SPI.begin();
rfid.init();
}
void loop()
{if (rfid.isCard()) {
if (rfid.readCardSerial()) {
if ( rfid.serNum[0] != serNum0
&& rfid.serNum[1] != serNum1
&& rfid.serNum[2] != serNum2
&& rfid.serNum[3] != serNum3
&& rfid.serNum[4] != serNum4)
{// With a new cardnumber, show it
Serial.println(" ");
Serial.println("Card found");
serNum0 = rfid.serNum[0];
serNum1 = rfid.serNum[1];
serNum2 = rfid.serNum[2];
serNum3 = rfid.serNum[3];
serNum4 = rfid.serNum[4];
// Test if it's a known card
if ( rfid.serNum[0] == 181
&& rfid.serNum[1] == 245
&& rfid.serNum[2] == 54
&& rfid.serNum[3] == 209
&& rfid.serNum[4] == 167)
{Serial.println("Hello Silvain !");
}
else
{Serial.println("Cardnumber:");
Serial.print("Dec: ");
Serial.print(rfid.serNum[0],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[1],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[2],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[3],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[4],DEC);
Serial.println(" ");
Serial.print("Hex: #");
Serial.print(rfid.serNum[0],HEX);
Serial.print(", #");
Serial.print(rfid.serNum[1],HEX);
Serial.print(", #");
Serial.print(rfid.serNum[2],HEX);
Serial.print(", #");
Serial.print(rfid.serNum[3],HEX);
Serial.print(", #");
Serial.print(rfid.serNum[4],HEX);
Serial.println(" ");}
}
else
{// If we have the same ID, just write a dot.
Serial.print(".");
}
}
}
rfid.halt();
}
Pour l’écriture :
Warning!!!
Don’t write address 0, 3, 7, 11, 15, … if you are not an advanced user!!! You could leave your tag unaccesable.
A Mifare® Classic 1k card has 1024 bytes of internal storage capacity, divided into 16 sectors. Each sector is composed of 4 blocks, and each block is composed of 16 bytes. That is to say, each card has 64 blocks, from number 0 to 63. Let’s describe the structure of a card:
1. In each sector, the last block (blocks number 3, 7, 11..) is called the sector trailer. This block stores the 2 keys or passwords and controls the access to the rest of the blocks in the sector (e.g. block number 7 controls block 4, 5 and 6). The first 6 bytes (0..5) are the key A, and the last 5 bytes (10..15) are the key B. As we will see, before reading or writing in any block, we must first authenticate us to that sector by providing one of the two keys (normaly the A key). The bytes number 6, 7 and 8 store the control bytes, which control the way the the blocks may be accessed (read/write). Byte number 9 is not defined in all sector trailers.
2. The very first block (number 0) is called the manufacturer block and has special characteristics. The first 4 bytes (0..3) are the unique identification (UID). The UID can be seen as the serial number of the card and identify the card in a univocal way (read more in the “Security with RFID/NFC at 13.56 MHz” chapter). The next byte (number 4) is the CRC check byte so it can be used to check the correct read; it is calculated with the XOR of the 4-byte UID. The rest of the bytes in the block number 0 (bytes 5..15) are the manufacturer data. This block 0 has read-only access for security reasons. We need to authenticate before reading the block number 0 but the UID can be obtained anyway, without the key.
3. The rest of the blocks (1 and 2; 4, 5 and 6; 8, 9 and 10; etc) are known as data blocks and they are available to read and write operations, after the needed authentication process.
To sum up, the Mifare® 1k cards have a net storage capacity of:
(16 sectors/card x 3 data blocks/sector X 16 bytes/block) – 16 bytes (first block) = 752 bytes/card
The cards have been tested to conserve data for 10 years and to have a write endurance of 100,000 cycles.
Références :
http://www.cooking-hacks.com/documentation/tutorials/rfid-13-56-mhz-nfc-module-for-arduino#step3
http://www.electrodragon.com/w/index.php?title=RFID_Card_Reader/Detector_Module#Pin_connection
http://www.grantgibson.co.uk/blog/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/
Communication via SPI : http://www.electrodragon.com/w/index.php?title=RFID_Card_Reader/Detector_Module
http://www.jeremyblum.com/2011/07/08/tutorial-12-for-arduino-rfid-card-reading/
http://www.elecfreaks.com/5418.html
http://learn.adafruit.com/adafruit-pn532-rfid-nfc/arduino-library
Votre commentaire