Affichage des articles dont le libellé est rfid. Afficher tous les articles
Affichage des articles dont le libellé est rfid. Afficher tous les articles

jeudi 3 janvier 2019

Arduino Episode 8 : RFID (RC522 + LCD)





Arduino nano et LCD et RFID

J'ai vu chez ma Veto un super truc pour lire la puce electronique de mon chat.
Je me suis dis je vais faire pareil, j'ai un écran LCD, un arduino et un lecteur RFID.
(Mauvaise fréquence pour le lecteur RFID mais c'est pas grave)
(Je voulais utiliser mon nouveau MAX7219, mais le lecteur RFID utilise les mêmes ports I2C donc il aurait fallu acheter une carte d'entrée sortie, donc je me suis rabatu sur l'écran LCD qui intégre un module arduino qui gère l'I2C(si j'ai bien compris) de plus, les pins sont différentes, et les alimentations également :D )

Branchements:

NANO / LCD
 GND sur GND
5V sur 5V
A4 sur SDA
A5 sur SCL

NANO / RFID-RC522
D10 sur SDA
D13 sur SCK
D11 sur MOSI
D12 sur MISO
ne pas brancher l'IRQ du RC522
GND<> GND
D9 sur RST
3.3V<> 3.3V

Code:
#include <LiquidCrystal_I2C.h>
#include <RCSwitch.h>
#include <SPI.h>
#include <MFRC522.h>


#define SS_PIN 10
#define RST_PIN 9
 
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

MFRC522::MIFARE_Key key; 

// Init array that will store new NUID 
byte nuidPICC[4];

//config ecran
RCSwitch mySwitch = RCSwitch();
LiquidCrystal_I2C lcd(0x27, 20, 4);


void setup() { 
  Serial.begin(9600);
  lcd.init();
  SPI.begin(); // Init SPI bus
  rfid.PCD_Init(); // Init MFRC522 

  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  Serial.println(F("This code scan the MIFARE Classsic NUID."));
  Serial.print(F("Using the following key:"));
  printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
}
 
void loop() {

lcd.backlight();




  // Look for new cards
  if ( ! rfid.PICC_IsNewCardPresent())
    return;

  // Verify if the NUID has been readed
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&  
    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  if (rfid.uid.uidByte[0] != nuidPICC[0] || 
    rfid.uid.uidByte[1] != nuidPICC[1] || 
    rfid.uid.uidByte[2] != nuidPICC[2] || 
    rfid.uid.uidByte[3] != nuidPICC[3] ) {
    Serial.println(F("A new card has been detected."));

    // Store NUID into nuidPICC array
    for (byte i = 0; i < 4; i++) {
      nuidPICC[i] = rfid.uid.uidByte[i];
    }
   
    Serial.println(F("The NUID tag is:"));
    Serial.print(F("In hex: "));
    printHex(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
    Serial.print(F("In dec: "));
    printDec(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
  }
  else Serial.println(F("Card read previously."));

  // Halt PICC
  rfid.PICC_HaltA();

  // Stop encryption on PCD
  rfid.PCD_StopCrypto1();
}


/**
 * Helper routine to dump a byte array as hex values to Serial. 
 */
void printHex(byte *buffer, byte bufferSize) {
  String cardID = "";
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
    cardID += String(buffer[i], HEX);

  }
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(cardID);
}

/**
 * Helper routine to dump a byte array as dec values to Serial.
 */
void printDec(byte *buffer, byte bufferSize) {
  
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], DEC);
    
  }
}

Un code plus simple que le mien:
https://www.hackster.io/ravee-tansangworn/reading-rfid-card-or-key-ring-and-display-on-lcd-b2f70d

#include "LiquidCrystal_I2C.h"
#include "RFID.h"

#define SS_PIN      A2
#define RST_PIN     D3

int led1 = D7;

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
LiquidCrystal_I2C lcd(0x27,20,4);

void setup()
{ 
  lcd.init();
  lcd.backlight();
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
 pinMode(led1, OUTPUT);
    mfrc522.PCD_Init();
}

void loop() {
    
    digitalWrite(led1, LOW);
    // Look for new cards, if nothing found, quit
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
     return;
    
    }
    
    // Select one of the cards, if nothing found, quit
    if ( ! mfrc522.PICC_ReadCardSerial()) {
     return;
    }
    
    String cardID = "";
    
    for (byte i = 0; i < mfrc522.uid.size; i++) {
        cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
        cardID += String(mfrc522.uid.uidByte[i], HEX);
    }
    digitalWrite(led1, HIGH);
    lcd.print(cardID);
    mfrc522.PICC_HaltA();
    delay(10000);
    lcd.clear();
}

dimanche 21 octobre 2018

5Guys RFID refill et boisson

J'ai appris que la chaine de restauration 5Guys utilisait une technologie RFID pour empêcher les personnes de se re-servir au distributeur de boissons. (depuis janvier 2017, il est interdit en france d'avoir des boissons à volonté)

A la défense, il y a justement un 5Guys.
j'y vais récupère des tags, et les tests.
Aucun ne marche sur mes lecteurs RFID/NFC

je regarde de plus prés le tag et obtiens les informations suivante:
eos 120-ec-w-001

On retrouve très vite le DataSheet

https://www.tageos.com/assets/Tageos-Datasheet-EOS-120-20160113.pdf
et les spécificités:
Frequency FCC 902–928 MHz / ETSI 865–868 MHz / ASIA 950–956 MHz
Protocol EPC Class 1 Gen 2

Bon, je n'ai aucun lecteur de ce type... peut être une future acquisition ?
 117€ chez AliExpress, c'est trop cher pour le nombre de boisson que je pourrai y gagner....

J'abandonne ce projet.

Sources:

 


 

https://www.latelierdugeek.fr/2015/07/17/dupliquer-contenu-puce-rfid-mifare-classic/