Hello everybody,
After weeks of intense testing I succeeded in reading tag codes from the 13.56Mhz APSX RW-210 rfid reader! This is the code: http://www.technicum.net/rfid/rfid_read.pde
It sends the read command via software serial to the rfid reader. Next it reads in the Tag code via hardware serial. Finally it prints a nice tag code to the computer!
Now the problematic part;
As a next step I wanted to compare the tag code to a list of known tags and then do a certain action (for example blink a led). I've been struggling with this for a week now so I decided to ask for some help. This is one of my numerous attempts :-[
#include <SoftwareSerial.h>
#define rxPin 7
#define txPin 2
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
int serIn; // var that will hold the bytes-in read from the serialBuffer
byte serInString[12]; // array that will hold the different bytes
int serInIndx = 0; // index of serInString[] in which to inser the next incoming byte
int serOutIndx = 0; // index of the outgoing serInString[] array;
int ledPin = 13; // LED connected to digital pin 13
char Tag1[] = "001B4EC1D014E0D57B"; //known tag code, should become a list of 50+ tags
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
mySerial.begin(19200); // set the data rate for the SoftwareSerial port
Serial.begin(19200); // opens serial port, sets data rate to 19200 bps
}
void loop () {
mySerial.print(0xfa, BYTE); // request tag code
// only if there are bytes in the serial buffer execute the following code
if(serialAvailable()) {
//keep reading from serial untill there are bytes in the serial buffer
while (serialAvailable()){
serIn = serialRead(); //read Serial
serInString[serInIndx] = serIn; //insert the byte you just read into the array at the specified index
serInIndx++; //update the new index
}
//feedback that something was received
Serial.println ("Processing Tag");
}
//do somenthing else perhaps wait for other data.
Serial.println ("NO TAG ");
//print out later in the loop the sentence only if it has actually been collected;
if( serInIndx > 0) {
Serial.print("Tag ID=");
//loop through all bytes in the array and print them out
for(serOutIndx=0; serOutIndx < serInIndx; serOutIndx++) {
Serial.print((serInString[serOutIndx]), HEX ); //print out the byte at the specified index
if((serInString[12], HEX) == Tag1[19]) { //compare received tag code to known tag code
digitalWrite(ledPin, HIGH); // if true blink led
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
//serInString[serOutIndx] = ""; //optional: flush out the content
}
//reset all the functions to be able to fill the string back with content
Serial.flush(); //flush serial buffer
serOutIndx = 0;
serInIndx = 0;
}
//slows down the visualization in the terminal
Serial.println();
delay(200);
}
The tag code "001B4EC1D014E0D57B" is the code that I have copied from serial monitor after reading a tag. All my attempts won't make the led blink Can someone please help me, I would like to put 50+ tags in the memory that trigger a certain action.
Kind Regards,
Loïc