I've been trying to connect my RedBee RFID reader to my Arduino for quite some time now and have been tearing my hair out trying to get them to play nice together. I could really use some help on this one.
I have an XBee module on my RedBee RFID reader, and the jumpers set to send all serial data over Xbee. Then, on my Arduino I have an XBee Shield, again with the module connected and all jumpers set to send/receive serial data via XBee.
What I want to do is control an RGB lamp (that I've already built) based on the RFID tag passed over my RFID reader. So I actually saved all the tags I own locally on my RFID reader so I get a consistent packet structure into my Arduino.
My major problems are:
- Because I'm using XBee for communication, I cannot send serial data to my PC for debugging, so I'm totally blind when testing the system, save from changing the state of my LED on pin 13.
- I'm really confused about when to use int, char and String.
Here is my code so far:
const int NUM_TAGS = 8;
int incomingByte = 0;
boolean valid;
String tag;
String tags[NUM_TAGS] = {"1080949666", "228015620207", "108020618361", "228015621675", "108015819165", "2280288799", "108020624739", "24804625544"};
int colors[NUM_TAGS][3] = {{100,0,0}, {0,100,0}, {0,0,100}, {100,0,100}, {100,100,0}, {0,100,100}, {50,80,15}, {60,10,80}};
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if(Serial.available() > 0) {
// Valid tag packet will follow this structure:
// T:ACK XXX XXX XXX XXX XXX\r\n>
incomingByte = Serial.read();
if( incomingByte == 'T' ) {
Serial.read(); // ':'
// Read the header
incomingByte = Serial.read();
if( incomingByte == 'N' ) {
for(int i=0; i<4; i++)
Serial.read(); // 'ACK '
} else {
for(int i=0; i<3; i++)
Serial.read(); // 'CK '
}
// Read the tag itself
incomingByte = Serial.read();
tag = "";
while( (incomingByte != 13) ) {
if( incomingByte == 32 ) continue;
tag += incomingByte;
incomingByte = Serial.read();
}
Serial.read(); // '\n'
Serial.read(); // '>'
}
} else {
//fadeTo(red);
}
// Look up the tag
int index = -1;
for(int i=0; i<NUM_TAGS; i++) {
if( tag.equals(tag[i]) ) {
index = i;
break;
}
}
if(index>-1) analogWrite(13,255);
}
Result: The LED on pin 13 never turns on.
I've been working on this problem for a few weeks, so any help is really appreciated!