Pages: [1]   Go Down
Author Topic: RFID Reader Code Question  (Read 218 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

Hi there,
I have the book from Tom Igoe "RFID For Beginners" and am having trouble trying to get the code to read my RFID tag. When I pass the tag over the reader, I get some strange symbols rather than the code. The symbols are different depending on what tag I use, so I think it's reading the tags but maybe not displaying them correctly. Attached is a screenshot of what my serial monitor looks like when I pass two different RFID tags over the reader--as you can see I get different kinds of jumbled signals. I have an Arduino Uno, Arduino 1.0.1, an ID-12 RFID reader, and the RFID breakout board from Sparkfun.

In terms of wiring it up I have followed his instructions from the book.
  • The 5V (pin 11) and RST (pin 2) pins are connected to power.
  • The GND (pin 1) and FS (pin 7) pins to the ground line.
  • And finally D0 (pin 9) is connected to Pin 6 on the Arduino since it's defined as the Rx pin.

Here's the code that I have. Originally in the book the startByte and endByte were 0x0A and 0x0D (for the Parallax reader), but in the book Programming for Interactivity, it says that the code for Parallax and ID-12 readers are similar except that ID-12 readers have start and stop values of 0x02 and 0x03, respectively. So I changed them.

Code:
/*
 RFID Reader
 */

#include <SoftwareSerial.h> // Bring in the software serial library
const int tagLength = 10;    // each tag ID contains 10 bytes
const int startByte = 0x02;  // Indicates start of a tag
const int endByte   = 0x03;  // Indicates end of a tag

char tagID[tagLength + 1];   // array to hold the tag you read

const int rxpin = 6; // Pin for receiving data from the RFID reader
const int txpin = 7; // Transmit pin; not used
SoftwareSerial rfidPort(rxpin, txpin); // create a Software Serial port
void setup() {
  // begin serial communication with the computer
  Serial.begin(9600);

  // begin serial communication with the RFID module
  rfidPort.begin(2400);
}

void loop() {
  // read in and parse serial data:
  if (rfidPort.available() > 0) { 
    if (readTag()) { 
  Serial.println("read tag!");
      Serial.println(tagID);
    }
  }
}

/*
 This method reads the tag, and puts its
 ID in the tagID
 */
boolean readTag() {
  char thisChar = rfidPort.read();
  if (thisChar == startByte) {   
    if (rfidPort.readBytesUntil(endByte, tagID, tagLength)) {     
      return true;
    }
  }
  return false;
}

Thanks in advance for any help you can give!

- Cilla


* serialmonitor.png (24.61 KB, 424x373 - viewed 10 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My RFID reader operates at 9600 baud. Are you sure yours is 2400?

Try some different speeds.
Logged

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

Good catch! I changed it from 2400 --> 9600 and it seemed to work! Thanks!


* serialmonitor2.png (25.6 KB, 432x382 - viewed 7 times.)
Logged

Pages: [1]   Go Up
Jump to: