Problema Com Sketch - Aplicação Arduino Uno e Leitor de TAG

Boa Noite, Pessoal. Estou encontrando problemas na sketch que um amigo do fórum ajudou a desenvolver.  Liguei o Arduino  com o Leitor de TAG, ao passar a TAG no leitor, os dados dela são enviados pro Arduíno que contém uma Sketch que iria exibir a mensagem "Liberado" ou "Não liberada" dependendo do ID de cada tag.  Meu Sketch tem uns problemas por não entrar em nenhuma estrutura de condição "IF's" então creio que seja algum problema e lógica, se alguem puder me ajudar eu agradeço. Segue minha Sketch e as Fotos dos componentes que tenho.

Segue a Sketch e a foto dos componentes que uso nessa aplicação
-Arduino Uno
-Leitor de TAG
-2 Tags


Sketch Anexada:


-----------

#include <SoftwareSerial.h>
     

//#define PINRX  2
//#define PINTX  3

String TagA = String("7100252B601F");
String TagB = String("7100252B601A");


SoftwareSerial rfidReader(2, 3);

String str;


void setup()
{
    Serial.begin(9600);
    Serial.println("Testando");
    rfidReader.begin(9600);
}
     


void loop ()
{
    char c = 0;

    while (rfidReader.available() > 0) {

        c = rfidReader.read();
        Serial.println(c);

        str.concat(String(c));
   
        if(str.length() == 12){
            if (str.equals(TagA)){
                Serial.println("TagA");
            }
            else{
                if(str.equals(TagB)){
                Serial.println("TagB");
                }
                else{
                    Serial.print("Tag Lido: ");
                    Serial.println(str);
                }

              str = String("");
                str = "";
            }
        }
    }
}

---------------------

Exibições: 554

Anexos

Responder esta

Respostas a este tópico

Sim, tenho sim. Só a placa que vai a abaixo dele e mais simples. A minha é essa mesmo. ID12-LA. A do tutorial está escrito só ID12. Sem o LA . Isso difere em alguma coisa ?

ali na página da sparkfun fala que ambas são essencialmente iguais

A diferença é que essa ID-12LA suporta um range de tensão de entrada entre 2.8~5V e a ID-12 suporta apenas 5V. 

link ID-12: https://www.sparkfun.com/products/retired/8419

link ID-12LA: https://www.sparkfun.com/products/11827

Vou esperar chegar e fazer uns testes, depois te conto o fim que a aplicação levou.

Cara, tive um problema com a Sketch do site, ao compilar diz que o arduino 1.0 não suporta o comando "BYTE" mais.


char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port
}

void loop () {
// read the serial port
if(Serial.available() > 0) {
val = Serial.read();
Serial.print(val, BYTE); //O BYTE nesta linha
}
}

Alguma dica de como arrumar ?

Vlw

tenta esse 

int RFIDResetPin = 13;

//Register your RFID tags here
char tag1[13] = "1E009A4067A3";
char tag2[13] = "010230F28243";
char tag3[13] = "01023C013A04";
char tag4[13] = "01023101093A";
char tag5[13] = "01023C0A4376";
char tag6[13] = "01023C000E31";
char tag7[13] = "01023C0A3207";
char tag8[13] = "1A004116317C";
char tag9[13] = "1E009A81F9FC";
char tag10[13] = "1A004162261F";

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

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

//ONLY NEEDED IF CONTROLING THESE PINS - EG. LEDs
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}

void loop(){

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

while(Serial.available()){

int readByte = Serial.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

if(compareTag(tag, tag1)){ // if matched tag1, do this
lightLED(2);

}else if(compareTag(tag, tag2)){ //if matched tag2, do this
lightLED(3);

}else if(compareTag(tag, tag3)){
lightLED(4);

}else if(compareTag(tag, tag4)){
lightLED(5);

}else if(compareTag(tag, tag5)){
lightLED(6);

}else if(compareTag(tag, tag6)){
lightLED(7);

}else if(compareTag(tag, tag7)){
lightLED(8);

}else if(compareTag(tag, tag8)){
lightLED(9);

}else if(compareTag(tag, tag9)){
lightLED(10);

}else if(compareTag(tag, tag10)){
lightLED(11);

}else{
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;
}
}

boolean compareTag(char one[], char two[]){
///////////////////////////////////
//compare two value to see if same,
//strcmp not working 100% so we do this
///////////////////////////////////

if(strlen(one) == 0) return false; //empty

for(int i = 0; i < 12; i++){
if(one[i] != two[i]) return false;
}

return true; //no mismatches
}

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço