Softwareserial

Modified the code a bit and came up with this for the Parallax RFID reader.

// RFID reader for Arduino
// Wiring version by BARRAGAN http://people.interaction-ivrea.it/h.barragan
// Modified for Arudino by djmatic
// And pieces from Arduino Playground http://www.arduino.cc/playground/Learning/PRFID
// And then modified again by thekidd

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
#define ledPin 13

// set up a soft serial port
SoftwareSerial mySerial(rxPin, txPin);

int val = 0;
char code[10];
int bytesread = 0;

void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT); // Set rxPin as INPUT to accept SOUT from RFID pin
pinMode(txPin, OUTPUT); // Set txPin as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(ledPin, OUTPUT); // Let the user know whats up

// set the data rate for the serial ports
mySerial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
Serial.begin(9600); // Serial feedback for debugging in Wiring

// say something
Serial.println("Hello World!");
}

void loop() {
digitalWrite(txPin, LOW); // Activate the RFID reader
digitalWrite(ledPin, LOW); // Turn off debug LED

if((val = mySerial.read()) == 10) { // check for header
bytesread = 0;

while(bytesread<10) { // read 10 digit code
val = mySerial.read();

if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}

code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}

if(bytesread == 10) { // If 10 digit read is complete
digitalWrite(txPin, HIGH); // deactivate RFID reader
digitalWrite(ledPin, HIGH); // activate LED to show an RFID card was read
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}

bytesread = 0;
delay(2000); // wait for a second to read next tag
}
}

Now I want to integrate this with a Purdy LCD, a Parallax GPS, and Xbee! I'll post what I find out for those interested.

Glad I found this post to integrate SoftwareSerial. I thought I was running out of Serial pins. Kudos to whoever wrote the SoftwareSerial library.

Also posted at: http://www.tekcrack.com/interfacing-arduino-with-parallax-rfid-reader-using-softwareserial.html

--thekidd

Software serial hangs your loop until a TAG is received.

So for example:-

void loop() {
blinkLED();
upDateLED();
readRFID();
getGPS();
}

As soon as the loop gets to readRFID(); it "hangs" so other functions in the loop, like reading gps updates every second, and displaying them on an LCD, won't resume until a TAG is scanned.

If no TAG is presented, then the loop hangs until one does.

Do a search for SoftwareSerial2, I think there's a interrupt hack in it that provides a "way out".