Shop OBEX P1 Docs P2 Docs Learn Events
RFID read/write module beginner help. Not reading anything. — Parallax Forums

RFID read/write module beginner help. Not reading anything.

johnonejohnone Posts: 9
edited 2014-04-26 14:00 in General Discussion
Hello :)...

I just bought this:
http://parallax.com/product/28440 - RFID Read/Write Module
http://parallax.com/product/32399 - RFID R/W 30 mm round tag

I'm trying to read the tags unique ID using this sample code:
//Code to read data from Parallax RFID reader/writer 28440 via Arduino//Program reads data from the old EM4100-based tags and prints their value in the serial monitor.


//Writen by vgrhcp, uberdude, sebflippers and sixeyes


#include <SoftwareSerial.h>
#define txPin 2
#define rxPin 5
#define RFID_LEGACY 0x0F




SoftwareSerial mySerial(rxPin, txPin);
int  val = 0; 
char code[11];     //Note this is 11 for the extra null char?
int bytesread = 0;


void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);


  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(txPin, OUTPUT);     //pin 2
  pinMode(rxPin, INPUT);      //pin 5


  Serial.println("RFID Read/Write Test");
}


void loop()
{
  mySerial.print("!RW");
  mySerial.write(byte(RFID_LEGACY));


  //mySerial.print(32, BYTE);


  if(mySerial.available() > 0) {          // if data available from reader 


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


      delay(500);                       // wait for a 1/2 second 
    } 
  } 
}



I've connected:
VCC to 5V
SIN to DIGITAL 2
SOUT to DIGITAL 5
GND to GND

1. What is:
pinMode(2, OUTPUT);pinMode(4, OUTPUT);
Used for?
2. Does this read the unique ID or the data I write to the tag? (and is there any data on it by default? Is that the reason it does not print any tag data?)
3. Why this no work :(((

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-25 10:05
    Try switching the rx and tx (SIN and SOUT) lines.

    One device's tx is the other devices rx.

    I'm guessing pin 4 is used as an indicator LED.

    Edit: Never mind. It looks like you have it correct.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-04-25 10:16
    1) I don't know why you've got the pinMode(2, OUTPUT) and pinMode(4, OUTPUT) there. The pinMode(txPin, OUTPUT) overrides the pinMode(2, OUTPUT) and you don't use pin 4.

    2) The RFID reader responds to commands sent, in your case, from your Arduino via pin 2 to SIN. The responses get sent from SOUT into pin 5. Read the documentation for the RFID reader/writer for details.

    3) The above sample program doesn't work with read/write tags. It only works with read-only tags. Again, read the documentation for details, but note that the above program commands the RFID reader/writer to read a "legacy" tag. You want to read a read/write tag. The documentation has a sample program for Parallax's Stamp. I don't know know where you could find a similar example for an Arduino. You might ask at the Arduino websites.

    Parallax is relatively new to the Arduino support business and they have Arduino sample programs for only a few of their sensors / devices. Check on their <learn.parallax.com> website. There's not an example yet for the RFID reader/writer, but there are some examples for the Board of Education Shield for robotics.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-25 10:45
    johnone wrote: »

    Is there a reason you changed the pin numbers?

    It seems like it would be a good idea to try the code as is without making changes.

    I found this quote:
    • Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
  • Mike GreenMike Green Posts: 23,101
    edited 2014-04-25 11:49
    Your first sample code (Post #4 at <playground.arduino.cc>) should work with the read-only tags and the other samples should work with the read/write tags. As Duane indicated, you might try the sample code without changing anything using the I/O pins provided in the posted code (6 and 8). Obviously change the wiring to what they describe. If that works, then you have the problem Duane found described.
  • johnonejohnone Posts: 9
    edited 2014-04-25 12:17
    I am using an arduino uno btw... not mega...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-25 12:27
    Can an Uno use a soft serial? I was playing around with my Uno (yes, I have one) and Pixy the other day and wanted to use it in UART mode but I read the Uno couldn't use the serial library needed to use UART mode. I'm not sure if this is a general limitation of the Uno or if it was just for the serial library the Pixy was using.

    While on the topic of Arduino, I recently worked with some Arduino code for the inexpensive MFRC522 readers. You might want to compare the 125 kHz device with the 13.56 MHz readers. I know the 13.56 MHz readers can be had for a few dollars (and a few weeks) from ebay. I posted a link to some Arduino code to use with these readers on Let's Make Robots recently. There's also a link to the Propeller version.

    While the MFRC522 readers can be interfaced via SPI or I2C. I've only seen SPI code for it.
  • johnonejohnone Posts: 9
    edited 2014-04-26 13:03
    I've succesfully read my tags with the second example:
    http://playground.arduino.cc/Learning/ParallaxRFIDreadwritemodule
    Works with an arbitrary DIGITAL pins on arduino.

    All i need now is adding my servo motor and im ready 4 googlesciencefair.

    Thanks 4 your help.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-04-26 14:00
    Great! Good luck with your science fair.
Sign In or Register to comment.