hI !
I'm trying to make my project work but i'm a noob with arduino. I search on the forum the solution but i can't find my solution
I used the code described here
http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/NO problem with that but now i want to test if the tag match with the autorized tag.. i use strcmp but when i'm trying i doesn't work
/**
* author Benjamin Eckel
*
* Adaptation pour integration validation badge et ouverture serrure
*/
#define RFID_ENABLE 2 //to RFID ENABLE
#define CODE_LEN 10 //Max length of RFID tag
#define VALIDATE_TAG 1 //should we validate tag?
#define VALIDATE_LENGTH 200 //maximum reads b/w tag read and validate
#define ITERATION_LENGTH 2000 //time, in ms, given to the user to move hand away
#define START_BYTE 0x0A
#define STOP_BYTE 0x0D
#define GACHE 13 // Commande de la gâche électrique sur pin13 => led
#define unlockSeconds 2 // Durée de la commande de la gâche
char tag[CODE_LEN];
char* BadgesAutorises[] = { // Définition de la liste des tags autorisés
"0000C153EC", // tag 1
"0000CAAAAA", // tag 2
"0001111A1A", // tag 3
};
char* TagNom[] = {
"Eleve 1", // tag 1
"Eleve 2", // tag 2
"Eleve 3", // tag 3
};
int NombreDeBadges=sizeof(BadgesAutorises)/sizeof(BadgesAutorises[0]);
void setup() {
Serial.begin(2400);
pinMode(RFID_ENABLE,OUTPUT);
Serial.print(NombreDeBadges);
}
void loop() {
char tagValue[11]; // declaration pour stockage des infos du badge
enableRFID();
getRFIDTag();
if(isCodeValid()) {
disableRFID();
comparaison(); // Comparaison du tag lu et des tags references
sendCode();
delay(ITERATION_LENGTH);
} else {
disableRFID();
Serial.println("Got some noise");
}
Serial.flush();
clearCode();
}
/**
* Clears out the memory space for the tag to 0s.
*/
void clearCode() {
for(int i=0; i<CODE_LEN; i++) {
tag[i] = 0;
}
}
/**
* Sends the tag to the computer.
*/
void sendCode() {
Serial.print("TAG:");
//Serial.println(tag);
for(int i=0; i<CODE_LEN; i++) {
Serial.print(tag[i]);
}
}
/**************************************************************/
/******************** RFID Functions ***********************/
/**************************************************************/
void enableRFID() {
digitalWrite(RFID_ENABLE, LOW);
}
void disableRFID() {
digitalWrite(RFID_ENABLE, HIGH);
}
/**
* Blocking function, waits for and gets the RFID tag.
*/
void getRFIDTag() {
byte next_byte;
while(Serial.available() <= 0) {}
if((next_byte = Serial.read()) == START_BYTE) {
byte bytesread = 0;
while(bytesread < CODE_LEN) {
if(Serial.available() > 0) { //wait for the next byte
if((next_byte = Serial.read()) == STOP_BYTE) break;
tag[bytesread++] = next_byte;
}
}
}
}
/**
* Waits for the next incoming tag to see if it matches
* the current tag.
*/
boolean isCodeValid() {
byte next_byte;
int count = 0;
while (Serial.available() < 2) { //there is already a STOP_BYTE in buffer
delay(1); //probably not a very pure millisecond
if(count++ > VALIDATE_LENGTH) return false;
}
Serial.read(); //throw away extra STOP_BYTE
if ((next_byte = Serial.read()) == START_BYTE) {
byte bytes_read = 0;
while (bytes_read < CODE_LEN) {
if (Serial.available() > 0) { //wait for the next byte
if ((next_byte = Serial.read()) == STOP_BYTE) break;
if (tag[bytes_read++] != next_byte) return false;
}
}
}
return true;
}
void comparaison()
{int tagId = findTag(tag);
if (tagId>0)
{Serial.print("Acces autorise");
Serial.print(tagId);
Serial.print(": Acces pour ");
Serial.println(TagNom[tagId-1]);
unlock();
}
else
{
Serial.println("Badge non autorise");
}
}
void unlock()
{
digitalWrite(GACHE, HIGH);
delay(unlockSeconds*1000);
digitalWrite(GACHE, LOW);
}
int findTag(char tag[10])
{
for (int thisCard = 0; thisCard < NombreDeBadges; thisCard++)
{ if(strcmp(tag, BadgesAutorises[thisCard]) ==0)
{return(thisCard+1);
}
}
return(0);
}
Can someone help me and tell me what's wrong with this code ? I searched but didn't find so your help is welcomed. Sorry for my english.
Thanks for your help.
I use arduino 1.0 and i work on seven 64bits with an arduino uno.