Friday, November 4, 2011

Teensy 2.0 + Parallax RFID reader



Alright when I first started trying to use these together I could not get them to work so here is how for others with the same issue.

This is the Parallax RFID reader that I used.

You have 4 pins,
VCC  - 5volts in
/ENABLE  - tells the reader to search for a tag
SOUT  - sends the tag data on serial out at 2400 buad
GND   - ground..

Alright so directly attaching the sout to the rx on the teensy seems to not work.... no idea why but its doesn't. So if you use a software serial it does, so sout goes to your pin 1 (the tx data in the code isn't important just set it to a pin your not going to use). Then your /ENABLE  goes to pin 2. Then your ground, and power which I hope you know how to deal with them.

So now you need to edit and upload the code below... THE END... happy hacking people.. Stay tuned for my coming up project involving this thing. :)

Sources: arduino.cc

#include <SoftwareSerial.h>

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

#define rxPin 1
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin1

void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps

pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}


void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);

if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.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
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(500); // wait for a second
}
}

1 comment:

  1. Hey,

    Great site. Do you have an email I can catch you on? I have a few questions to ask. Please contact me on rgibson(a)farnell(dot)com

    Thanks

    Ryan

    ReplyDelete