Outils pour utilisateurs

Outils du site


esp8266:rfid

Lecture RFID sur ESP8266

Connexion d'un grove de chez http://www.lextronic.fr/P28822-module-grove-rfid-125-khz.html

librairie EspSoftSerialRx : https://github.com/scottwday/EspSoftSerial

Résultat, sortir le no de la puce correspondante du tableau

esp8266_testrfid.ino

// serial
#include <EspSoftSerialRx.h>
EspSoftSerialRx rfid;
const int nbr_de_puces = 20;
int no_puce_actuelle;

// tableau des puces rfid 20x10
char *RFID[nbr_de_puces] = {
  "6D0070007964", // puce 0
  "0123456ab1",
  "0123456ab2",
  "0123456ab3",
  "0123456ab4",
  "0123456ab5",
  "0123456ab6",
  "0123456ab7",
  "0123456ab8",
  "0123456ab9",
  "1123456ab0",
  "1123456ab1",
  "1123456ab2",
  "1123456ab3",
  "1123456ab4",
  "1123456ab5",
  "1123456ab6",
  "1123456ab7",
  "1123456ab8",
  "1123456ab9",
};
int litrfid() {
  // mise en forme de la lecture rfid
  //retourne le no_puce
  int i = 0;
  unsigned char val;
  char tagValue[13];
  for (i = 0; i <= 11; i++) {
    if (rfid.read(val)) {
      tagValue[i] = '\0'; // Null
      // on saute avec le start 0x02 et stop bit 0x03
      if ((val == 0x0D) || (val == 0x0A) || (val == 0x03) || (val == 0x02)) {
        break;
      }
//      Serial.print(i);
//      Serial.print(" ");
//      Serial.print((char)val);
//      Serial.print(" ");
//      Serial.println(val, HEX );
      tagValue[i] = (char)val;

      if ((i == 11) ) { // 11 digit read is complete
        tagValue[12] = '\0'; // Null
//        Serial.print("Tag read: ");
//        Serial.println(tagValue);
        // Search the tag database for this particular tag
        int tagId = CherchePuce( tagValue );
        // Only fire the strike plate if this tag was found in the database
        if ( tagId != 99 )
        {
//          Serial.print("puce ");
          Serial.println(tagId);
        } else {
//          Serial.println("pas de puce");
        }
      }
    }
  }
}

int CherchePuce( char tag[10] ) {
  for (int puce = 0; puce < nbr_de_puces; puce++) {
    // Check if the tag value matches this row in the tag database
    if (strcmp(tag, RFID[puce]) == 0)
      return (puce);

  }
  // Si pas trouvé on retourne 99
  return (99);
}
void setup() {
  // put your setup code here, to run once:
  rfid.begin(9600, 2); // entree UEXT 10
  Serial.begin(115200);
  //setup ethernet part
  Serial.println();
  Serial.print("rfid ecoute ");
}

void loop() {
  // put your main code here, to run repeatedly:
  litrfid();
  delay(10);
}
esp8266/rfid.txt · Dernière modification : 2024/02/09 17:10 de 127.0.0.1