Outils pour utilisateurs

Outils du site


id-12la

Ceci est une ancienne révision du document ! —-

RFID

ID-12LA fonctionne jusqu'à environ 2.5 cm de distance

Liens :

http://bildr.org/2011/02/rfid-arduino/ https://hcgilje.wordpress.com/resources/rfid_id12_tagreader/

Datasheet :

http://cdn.sparkfun.com/datasheets/Sensors/ID/ID-2LA,%20ID-12LA,%20ID-20LA2013-4-10.pdf

 
#include <SoftwareSerial.h> 

const int RFIDResetPin = 13; 
// software serial #2: RX = digital pin 8, TX = digital pin 9 
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega 
SoftwareSerial portId12LA(8, 9); 

void setup(){ 
  Serial.begin(9600); 

  portId12LA.begin(9600); 

  pinMode(RFIDResetPin, OUTPUT); 
  digitalWrite(RFIDResetPin, HIGH); 
} 

void loop(){ 

  char tagString[13]; 
  int index = 0; 
  boolean reading = false; 

  portId12LA.listen(); 
  while(portId12LA.available()){ 

    int readByte = portId12LA.read(); //read next available byte 

    if(readByte == 2) reading = true; //begining of tag 
    if(readByte == 3) reading = false; //end of tag 

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){ 
      //store the tag 
      tagString[index] = readByte; 
      index ++; 
    } 
  } 

  checkTag(tagString); //Check if it is a match 
  clearTag(tagString); //Clear the char of all value 
  resetReader(); //eset the RFID reader 
} 

void checkTag(char tag[]){ 
/////////////////////////////////// 
//Check the read tag against known tags 
/////////////////////////////////// 

  if(strlen(tag) == 0) return; //empty, no need to contunue 
   Serial.println(tag); //read out any unknown tag 
} 

void lightLED(int pin){ 
/////////////////////////////////// 
//Turn on LED on pin "pin" for 250ms 
/////////////////////////////////// 
  Serial.println(pin); 

  digitalWrite(pin, HIGH); 
  delay(250); 
  digitalWrite(pin, LOW); 
} 

void resetReader(){ 
/////////////////////////////////// 
//Reset the RFID reader to read again. 
/////////////////////////////////// 
  digitalWrite(RFIDResetPin, LOW); 
  digitalWrite(RFIDResetPin, HIGH); 
  delay(150); 
} 

void clearTag(char one[]){ 
/////////////////////////////////// 
//clear the char array by filling with null - ASCII 0 
//Will think same tag has been read otherwise 
/////////////////////////////////// 
  for(int i = 0; i < strlen(one); i++){ 
    one[i] = 0; 
  } 
} 

id-12la.1464010071.txt.gz · Dernière modification: 2016/05/23 15:27 par colin