interfacing with RFID

Hi,

I have an RFID reader from Wavetrend that works at a baud rate of 57600. There is only one pin (data out) other than power and ground, and that pin has to connect to the serial pin on the arduino because the digital pins can only be read with speeds of up to 9600 (I got this from the software serial library). Each byte has a start bit, a stop bit and no parity. I haven't been able to confirm how the serial port reads data; does it look for a start bit, stop bit and parity? I am able to read some data that corresponds to what I expect, but it seems that some bytes are lost. I am suspecting that arduino doesn't use start/stop bits on the serial port, or that the start/stop bit is different, and so some of the start and stop bits are read as data. Is there a way I can modify the Serial.read() function? Is there a way I can read bit by bit at a baud rate of 57600?

Another solution that came to mind is reading this data using a different processor altogether and then passing that to the arduino board. any suggestions?

Thanks

This will sound cruel... I know HOW cruel, 'cause I had to take my own advice...

Maybe rather than fighting with the RFID reader you have, consider what YOUR TIME is worth, and buy a new reader... one that is known to work well with Arduinos, e.g. the ones from Sparkfun?

(You can always sell the one you have for SOMETHING on eBay...)

The ones from sparkfun are passive and have a range of less than 10 cm. For my application, I need over 2m, so I got an active one. The manufacturer has ones that work at 9600 baud rate but it will take over a month to ship because the default they have at stock is the 57600 type; I don't have that much time left for this project. I found some people talking about the same reader on the arduino forums, but it was in french... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275310692

Are there any small RFID readers with over 2m range that are known to work well with arduino?

I am suspecting that arduino doesn't use start/stop bits on the serial port, or that the start/stop bit is different,

No the arduino uses start and stop bits in the standard way.

Each byte has a start bit, a stop bit and no parity.

Assuming that is accompanied by 8 data bits this is a prefect match to the arduino.

Is there a way I can read bit by bit at a baud rate of 57600?

I am not sure from you post if you are using the software serial or not. I suspect this would be too fast for the software serial library but you should be able to read a byte in at this speed one bit at a time.

Have you connected the ground of the arduino and reader? Is the reader outputting TTL levels or RS232 levels. If it is outputting RS232 levels you need a level converter, like a MAX 202 or something similar.

because the digital pins can only be read with speeds of up to 9600 (I got this from the software serial library).

SoftwareSerial is obsolete. I do wish that it could be removed.

NewSoftSerial is a much better software serial implementation. It provides an available() method, like the hardware class, AND operates up to 57600 baud rates.

Hurrah for the previous post! Delighted that NewSoftSerial is fast enough. Rest of "problem" is now (almost) no problem!

Guidance on using NewSoftSerial, and the levels issue (RS-232 not same as "serial") to be found in...

Sorry the information isn't better organized... but what you need IS there, or in a linked page! :slight_smile:

Once you get "things" working, please post short guide to the "gotchas" at.....

http://www.arduino.cc/playground/Main/InterfacingWithHardware#rfid

Thanks a lot! This helps. I now read all the 38 bytes that I'm expecting. However, there is an issue. Some bytes get an extra 1. For example, I'm expecting 42 (0010 1010) but instead I get 170 (1010 1010). The worst is when I'm expecting a 0 and I get 128. This doesn't happen all the time, but very often (not just 1 out of 10 times that I can ignore it, but more than half the time).

Here's the code for reference:

void loop()
{
  if (RFIDSerial.available()>0) {
    serial_byte=RFIDSerial.read();
    if(serial_byte == 85) { //check for header
      bytesread = 0;
      code[bytesread] = serial_byte;
      bytesread++;
      while (bytesread<38) {
        if (RFIDSerial.available()>0) {
          serial_byte=RFIDSerial.read();
          }
          if (serial_byte == 85) //if header
            break;
          else {
            code[bytesread] = serial_byte;
            bytesread++;
          }
      }
      if (bytesread == 38) {
        Serial.print("\ncomplete data:");
        for (int i =0; i<38; i++) {
          Serial.print("\t");
          Serial.print(code[i], DEC);
        }
        bytesread = 0;
      }
    }
  }
}

What I expect:

complete data: 85 32 80 1 2 33 42 42 32 1 40 66 67 146 0 146 81 45 30 172 172 0 143 39 77 51 80 227 111 32 80 80 0 0 40 10 13 61

What I actually get:

complete data: 85 32 80 1 2 33 170 42 32 1 40 66 67 146 128 146 81 45 158 172 172 128 143 39 77 51 80 227 111 32 80 80 128 128 168 138 141 61

Ideas? Is that a bug with the NewSoftSerial library? Or perhaps the RFID reader is transmitting at a slightly different rate than is in the datasheet? How can I tweak the baud rate for anything else around but not exacty 57600?

The serial protocol transmits the least significant bit first. Since your error always consists of an incorrect '1' in the most significant bit there appears to be a timing error at one or both ends. This is occasionally causing the stop bit to be read instead of the most significant bit.

Don

Yea I figured that out, that's why I was asking if I could tweak the baud rate for something different from 57600, but I'm not even sure if that's the appropriate solution. I suspect that NewSoftSerial reads the start bit twice for some bytes.

I didn't mention that the RFID reader uses an RS232 interface. Because the power supply is 5V, the output is +/- 5V with inverted logic. So far, the arduino doesn't seem to have a problem reading the -5V as 0V (and thus a digital 1). I could go out and buy a MAX232 chip, but this seems so close without it, and I am concerned that the problem will still remain.

I could go out and buy a MAX232 chip, but this seems so close without it, and I am concerned that the problem will still remain.

Isn't it worth $2 to find out?

Oh... £$%£.

Sorry. For a time early on 7 Jan 2011, New York City time, there was bad info here.

This post is now "fixed"....

A nice "answer" to the MAX232 issue (level shifting between Arduino and RS-232) is the nice, neat little board "P4B"... $6.50+p&p for unassembled kit... for RS-232 to TTL level shifting (Arduino likes "TTL"). (Also available assembled and tested. If you are new to serial work, buy assembled and tested... serial "stuff" is tiresome enough without having ANOTHER element in the mix which might be "the problem".)

http://shop.moderndevice.com/products/p4

It is also available from Wulfden, if you prefer that supplier, or see other "goodies" there that you want. His mini breadboards are all I want for Christmas. By the dozen, preferably.

http://wulfden.org/TheShoppe/pa/index.shtml#P4

(I have no "relationship" with either store, other than "happy customer". If you haven't visited both sites... and not maxed out your credit card over Christmas... give them visits!)

The bad information pointed you at programming adapters for USB-less Arduino clones... not really relevant to this thread, but I hate to "throw" anything "away".... :slight_smile:

$14+ p&p

Modern Device "BUB" from....

http://wulfden.org/TheShoppe/pa/index.shtml

(or, of course!, from ModernDevice.com... I'm not sure why my archive has the wulfden link, when I also like ModernDevice!...

http://shop.moderndevice.com/products/usb-bub

Where ever you buy the USB-to-serial adapter, it has a shunt to switch the logic levels from 5 to 3.3 volts, so you are "future proofed" if you are still working at 5v.