Instructables

Interfacing the arduino with the parallax RFID reader?

I want to interface the parallax RFID reader with the arduino.  I have done some research and found some programs, but I can't quite understand what is going on it the programs. 

Here is one that I found on the arduino playground:
www.arduino.cc/playground/Learning/PRFID

I couldn't paste the code, because when I did it just went on one line, but the program I looked is the first one.

The questions I have are:
char code[10] ---- what does the 10 mean?
Also how does the program read each byte individually, and then combine them into the whole byte string for the rfid tag.

I am just learning about using serial with the arduino so not much in the program made sense to me and the programs didn't say how they worked.

Thanks in advance!




smitec084 years ago
the program reads one letter at a time and then atores them one after another liek this.

[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] imagine the array as 10 boxes

read letter one
[A][ ][ ][ ][ ][ ][ ][ ][ ][ ]

read letter two
[A][B][ ][ ][ ][ ][ ][ ][ ][ ]

etc

Here’s a psuedocode version of the code, if you need anything explained more feel free to ask. also this will be a lot easier to read in notepad or whatever as the indenting will make more sense:

Make an integer named val initially at zero
make an array of 10 characters called code
make an integer called bytesread

void setup() {
 start the serial at 2400bps
 set pin 2 to output
 write 0 to pin 2 (this activates the RFID reader)
}
 void loop() {
is there anything in serial waiting to be read? if there is{
  read one byte and store it in val, also if that value is 10{
  set bytesread to zero}
  while bytesread is less than 10 {
   check the serial, is there anything to read? if there is{
    read one byte from serial into val
    if val is 10 or 13 {
     break (stor reading the tag)
    } otherwise {
     put val in out array at the bytesread'th place        
     add one to bytesread
    }
   } otherwise {do nothing, so were stuck in this loop until we do get something to read}
  }
   
  if we got 10 bytes (i.e didn’t go to the break line) {
   print the tag number to the serial display
   bytesread = 0
   delay 0.5 seconds
  }
}
JaredsProjects (author)  smitec084 years ago
Thank you, I get everything now (the array really through me off), except this line:
 if((val = Serial.read()) == 10)  
To me it appears to just be taking a shortcut by setting val equal to Serial.read, and seeing if serial.read is equal to 10.  Instead of making to lines of code.

Thanks again!
AI
leeamsi972 years ago
in the original code, what exactly is val storing. Also, why does the program stop reading the tag after 10 or 13? and what does this line do:if(bytesread == 10)? i didnt quite understand it from the first response.

Thanks
gmxx4 years ago
 as i understand the code, it eventually represents the 10 digit code representing the rfid tag.

to read the bytes, it looks at the incoming serial data from the rfid reader. it appends the data to the char code variable, and a valid rfid read has 10 digits.
gmxx gmxx4 years ago
 in more detail, it represents a 10 character array