Loading...
Pages: [1]   Go Down
Author Topic: Parallax RFID Reader module not sending tag-id to Arduino  (Read 269 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Guys!

We are four guys working on a projekt with the RFID Reader ( Blue )  and Arduino ( Leonardo ) . But our problem is when the Reader is connected to the Arduino and the RFID reader shows the RED light( ready ) we get absolutly nothing on our Arduino monitor. There are also a little light on the Arduino ( RX ) who should, but not doing it,  light up when signal is received.


our code it :
Code:
const int startByte = 10;
const int endByte = 13;
const int tagLength = 10;
const int totalLength = tagLength + 2;
char tag[tagLength + 1];
long lastTagValue = 0;

int bytesread = 0;
void setup()
{
 Serial.begin(2400);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
}

void loop()
{
 if(Serial.available() >= totalLength)
{
 if(Serial.read() == startByte)
{
 bytesread = 0;
while(bytesread < tagLength)
{
  int val = Serial.read();
  if((val == startByte)||(val == endByte))
  break;
  tag[bytesread] = val;
  bytesread = bytesread + 1;
}
}
if( Serial.read() == endByte)
{
  tag[bytesread] = 0;
  long tagValue = atol(tag);
  Serial.print("RFID tag is: ");
  Serial.println(tag);
  lastTagValue = tagValue;
}
}
}


We hope someone can help see the problem


// Simon
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The USART (serial) interface of the Leonardo is available by the Serial1 object, the Serial object is for the connection to the PC (USB, debugging).
Logged

Offline Offline
God Member
*****
Karma: 9
Posts: 839
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apart from that problem,   you should never attempt to read more characters,  than the number which is available.

If you get one character arrive on the serial,   you then go and try to read a whole bunch of characters.  This won't work
reliably.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you should never attempt to read more characters,  than the number which is available.

The OP is not doing that (if(Serial.available() >= totalLength)). But he's waiting until the total number of characters arrived, which is never a good idea in a serial protocol (you might have missed one character).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Found solution!


Changede the RX-pin to another.
Logged

Pages: [1]   Go Up
Print
 
Jump to: