Go Down

Topic: RW-210 13.56Mhz Rfid Reader/Writer (Read 5159 times) previous topic - next topic

Loic

#15
Aug 06, 2007, 04:21 pm Last Edit: Aug 06, 2007, 04:22 pm by Loic Reason: 1
I'm on OS X, I tryed the test application under Parallels, but I can't get the serial port to work in parallels (but that's an other issue). The fact that I got sort of a reply in Zterm makes me believe that there's no hardware error.

Thanx anyway Daniel  :)

Grtz, Loïc

kg4wsv

Quote
I've tryed a number combinations in your format via the atmega168 but its not responding   In the Serial monitor I get the corresponding decimal numbers 250, 253, 252 etc...


If you mean the arduino serial monitor, if you print 0xFA and see the characters "250", then something is wrong.  Hmm, I gave you the wrong function call;  I should have said serial.print(0xfa, BYTE); (I left out  ", BYTE").  Sorry about that.

You mention monitoring the communication between the Arduino and the RFID with the arduino serial monitor.  What is the hardware configuration there?

You cannot drive rs232 signals from multiple sources, so if you are using the Arduino NG you must disconnect power to the FTDI chip so that the RFID is the only thing driving the arduino's RXD, and vice versa for the RFID's RXD.

If you simply hook the RFID to pins 0 and 1 while the USB chip is still active, you will have unreliable or nonexistant communications.

-j

Loic

SUCCES! SUCCES! SUCCES!   ;D
Thank you sooo much kg4wsv. After uploading this
Code: [Select]
void setup() {
 Serial.begin(19200);
}

void loop() {
Serial.print(0xfd, BYTE);
delay(50);
Serial.print(0xfc, BYTE);
delay(50);
}

the red led flashes real fast so at last communication has been established. Now I'll try to read the rfid tags. I'll post every progress.

Euforic regards, Loïc

Daniel

#18
Aug 06, 2007, 09:59 pm Last Edit: Aug 06, 2007, 09:59 pm by Daniel Reason: 1
Quote
I'll post every progress.


hey, you know we have an unwritten rule that if you get more than ten responses, you have to write the results up in a tutorial for the Playground?  ;D

D

Loic


Loic

Hi everybody,

I've made some good progress:

If I want to print tag codes to my computer I knew that I needed to use the SoftwareSerial lib to communicate to the Rfid reader. I've succeeded in this:
Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 9
#define txPin 8

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

void setup()  {
 // define pin modes for tx, rx, led pins:
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 // set the data rate for the SoftwareSerial port
 mySerial.begin(19200);
}

void loop() {
 
 mySerial.print(0xfd, BYTE);
 delay(500);
 mySerial.print(0xfc, BYTE);
 delay(500);
}


To test the tag reading functionality I connected the the tx pin of the reader to the tx of the arduino instead of pin 9. This way when I send 0xfa via softwareSerial I got perfect rfid tag readouts in the SerialMonitor  ;D. So now I wanted to do it the clean way, by sending the command via SoftwareSerial, receiving it back via SoftwareSerial and printing it to the computer via traditional Serial.print.
This is what I got so far:
Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 7
#define txPin 6

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte incomingByte = 0;      // for incoming serial data

void setup()  {
 // define pin modes for tx, rx, led pins:
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 mySerial.begin(19200); // set the data rate for the SoftwareSerial port
 Serial.begin(19200);      // opens serial port, sets data rate to 19200 bps
}

void loop() {
 mySerial.print(0xfa, BYTE);
 incomingByte = mySerial.read();
 Serial.print(incomingByte, BYTE);
 delay(500);
}


In the serial monitor I get a "?" as long as I hold a tag above the reader. Can someone help me a bit further?

kg4wsv

Quote
mySerial.begin(19200); // set the data rate for the SoftwareSerial port

Is SoftwareSerial rated for 19200?  I thought it was 4800 or 9600, but I don't have an arduino install handy to check.

-j

Loic

#22
Aug 10, 2007, 01:35 am Last Edit: Aug 10, 2007, 01:37 am by Loic Reason: 1
I was also wondering if it was rated for 19200 but sending the commands works, so I can't see why reading shouldn't work. But it's always possible. An other way of doing things could be by just using software serial for sending the commands and reading back with the standard hardware serial rx. This way the Serial.available command could be used wich isn't possible with software serial. I've tried this by modifying the P*r*lax rfid code, but I it's other hardware so I probably made some errors:
Code: [Select]
//
#include <SoftwareSerial.h>

#define rxPin 7
#define txPin 6

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin); //Only tx is used
byte  val = 0;
char code[12];
int bytesread = 0;

void setup() {

Serial.begin(19200); // RFID reader SOUT pin connected to Serial RX pin at 19200
pinMode(rxPin, INPUT); //Only tx is used, the standard hardware rx pin is used for receiving the tag code
pinMode(txPin, OUTPUT);
mySerial.begin(19200);

}  void loop() {
 mySerial.print(0xfa, BYTE); //request tag code with the FA command
 if(Serial.available() > 0) {          // if data available from reader
   if((val = Serial.read()) == 12) {   // check for header
     bytesread = 0;
     while(bytesread<10) {              // read 12 digit code
       if( Serial.available() > 0) {
         val = Serial.read();
         if((val == 12)||(val == 15)) { // if header or stop bytes before the 12 digit reading
           break;                       // stop reading
         }
         code[bytesread] = val;         // add the digit          
         bytesread++;                   // ready to read next digit  
       }
     }
     if(bytesread == 12) {              // if 12 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
   }
 }
}


Could someone give me a hand with getting the output wright? Mayby by getting some inspiration from the working Basic Stamp code at DigitalDawgpound http://www.digitaldawgpound.org/wp-content/uploads/2007/03/rw210_rfid_reader.bse
I really appreciate your help.
Regards, Loïc

kg4wsv

I am apparently wrong about software serial - it will attempt pretty much any baud rate.  The faster the baud rate the poorer it will do, though.

Good idea to try and use the real serial port on the RFID reader.

On the version of the code the printed ? on the serial monitor, try to change the serial.print(incomingByte, BYTE); to serial.print(incomingByte, HEX);  Looking at the data sheet, it appears the vales returned by the RFID reader are in binary (makes sense, given the large number of tags you would want to make available).

-j

Loic

#24
Aug 22, 2007, 02:23 pm Last Edit: Aug 22, 2007, 02:24 pm by Loic Reason: 1
Big progress!!! The following code reads the Tag and prints it back to the computer:

Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 7
#define txPin 2

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte incomingByte;      // for incoming serial data
int serIn;             // var that will hold the bytes-in read from the serialBuffer
char serInString[12]; // array that will hold the different bytes  100=100characters;
                      // -> you must state how long the array will be else it won't work.
int serInIndx  = 0;    // index of serInString[] in which to inser the next incoming byte
int serOutIndx = 0;    // index of the outgoing serInString[] array;


void setup()  {
 // define pin modes for tx, rx, led pins:
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 mySerial.begin(19200); // set the data rate for the SoftwareSerial port
 Serial.begin(19200);      // opens serial port, sets data rate to 19200 bps
}


void loop () {
 //simple feedback from Arduino
 mySerial.print(0xfa, BYTE);
 
 // only if there are bytes in the serial buffer execute the following code
 if(serialAvailable()) {    
   
   //keep reading from serial untill there are bytes in the serial buffer
    while (serialAvailable()){        
       serIn = serialRead();              //read Serial        
       serInString[serInIndx] = serIn; //insert the byte you just read into the array at the specified index
       serInIndx++;                    //update the new index
    }
   
    //feedback that something was received
    Serial.println ("Processing Tag");
 }
 
 //do somenthing else perhaps wait for other data.
 Serial.println ("NO TAG ");
 
 //print out later in the loop the sentence only if it has actually been collected;
 if( serInIndx > 0) {
     Serial.print("Tag ID= ");      
     
     //loop through all bytes in the array and print them out
     for(serOutIndx=0; serOutIndx < serInIndx; serOutIndx++) {
         Serial.print( (serInString[serOutIndx]), HEX );    //print out the byte at the specified index
         //serInString[serOutIndx] = "";            //optional: flush out the content
     }
       
     //reset all the functions to be able to fill the string back with content
     serOutIndx = 0;
     serInIndx = 0;
 }
   
 //slows down the visualization in the terminal
 Serial.println();
 delay(200);
}


Next thing I want to achieve is to compare the Tag to a list (maybe an array) of known Tags and then do something (blink a led for example). Does someone have an idea how to achieve this?


Kind Regards, Loïc

Loic

I've moved the discussion to the software department of the forum because it's not a hardware issue any more, the communication is established between the rfid reader and arduino. My next try is to compare the Tag code to a list of known codes. Continue reading here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1188236776/0

Loic

Everything works, including checking the tag to an array of known tags (see: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1188236776/0).
A Playground tutorial will follow soon.

morbid81

I have been having similar trouble, trying to use the miFare RFID reader. What I think is that we have to try and use UART to communicate with it, not serial. When using Serial.print, it is actually printing to the USB port, not to the RFID reader, thus rendering it unresponsive.

Loic

This is actually the reason why I use Software Serial on an other port for sending the "request tag code" command. I'm not having a single problem with this setup, the code and the hardware work perfectly...

Regards, Loïc

morbid81

I think mine is not responding because the "request tag" command seems a bit confusing. It is supposed to send 0x41  with 2 parameters in it I think.

Go Up