====== CAP635 ======
**Module RFID RC522 (compatible Arduino)** \\
Le module permet de lire les codes d'identification ou la totalité des données des puces RFID. La modification (écriture) des données et aussi possible)
{{ :rfid_brochage.jpg?400|Cliquer pour agrandir}}
===Composition du kit :===
* 1 module RFID - RC522
* 1 carte standard S50
* 1 porte clé S50
===Caractéristiques :===
* consommation : 13 - 26 mA / 3.3 VDC
* Fréquence : 13.56 MHz
===Liens utiles :===
* [[https://fr.wikipedia.org/wiki/Radio-identification|Présentation du RFID sur Wikipédia]]
* [[https://github.com/miguelbalboa/rfid|Bibliothèque RFID]]
* {{ ::rfid-rc522.pdf |Documentation du module}}
=====Programmation=====
Lecture complète du tag
#include
#include
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
Fonction pour récupérer l'UID du tag.
String uid; // Variable contenant l'UID au retour sinon rien
bool lit_UID (String &uid) {
char b[2];
// Retourne faux si pas de nouvelle carte ou défaut de lecture
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return false;
}
// Lit l'UID
uid = "";
for (byte i = 0; i < uid.size; i++) {
itoa(mfrc522.uid.uidByte[i], b, 16);
if (mfrc522.uid.uidByte[i] < 0x10)
uid = uid + " 0" + b;
else
uid = uid + " " + b;
}
uid.toUpperCase();
return true;
}