Hi,
I am a noob at all things Arduino, and have seen several projects where a Parallax RFID reader is hooked up to an Arduino and is printing the code or a message to the LCD.
Does any one have this code ready to upload?
Im just lookin for something to get started with and mess around with.
Thanx for all your help!
My code, adapted from this very helpful tutorial: http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/
#include <NewSoftSerial.h>
#define CODE_LEN 10 //Max length of RFID code
#define START_BYTE 0x0A //decimal 10 or LINE-FEED
#define STOP_BYTE 0x0D //decimal 13 or CARRIAGE-RETURN
String tag; //this is the character where we store the tag
NewSoftSerial RFSerial(6, 2);
/**
* Blocking function, waits for and gets the RFID tag.
*/
void setup(){
pinMode(7, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(7,LOW);
digitalWrite(5,LOW);
Serial.begin(2400);
RFSerial.begin(2400);
}
void loop(){
getRFIDTag();
sendCode()
delay(3000); //wait 3 seconds
RFSerial.flush();
Serial.flush();
clearCode();
}
void clearCode() {
tag = "";
}
void sendCode() {
Serial.print("TAG: ");
Serial.print(tag);
}
void getRFIDTag() {
byte next_byte;
while(RFSerial.available() <= 0) {}
if((next_byte = RFSerial.read()) == START_BYTE) {
byte bytes_read = 0;
while(bytes_read < CODE_LEN) {
if(RFSerial.available() > 0) { //wait for the next byte
if((next_byte= RFSerial.read()) == STOP_BYTE) break;
tag += next_byte;
}
}
}
}
This will output the tag code to the serial terminal on the computer. Connect SOUT to arduino pin 6 and the rest of the pins accordingly.
Awesome,
Thnx for the help
will this code also print to a serial lcd, like the ones from spark fun?
Those accept ascii right? If so, then yes, but you will need to plug the lcd into the arduino hardware tx and rx, and change the hardware (not the softserial) serial Serial.begin call to 9600bps as I believe this is the default.
Hey Bilbo,
I tried the sketch you posted, and i get an error that states "NewSoftSerial does not name a type" I have tried multiple strings and trying to load different sketches that include "NewSoftSerial" and the all come back with the same error. I have upgraded to the latest Arduino IDE and still the same problem.
Am i doing something wrong or have i missed a portion in my sketch?
Thanx for your help!
did you install the newsoftserial library? A google search for newsoftserial yields the library download page and instructions on how to install it.
good luck!
Bilbo,
Thanx for your help, i got the NewSoft library working and loaded. However when i go to scan a card i get nothing in my serial monitor. The light in the RFID reader is green, shouldnt it be red?
Any clue on what could be missing?
Thanx Again!!
did you remember the enable pin on the reader?