RFID reader not responding to cards

I’m back with more noob questions about RFID! I’m using an Arduino Duemilanove with an ID-20 reader and trying to use a simple program to just confirm that it’s picking up a card. All I get in the Serial Monitor is a bunch of squares, whether a card is present or not. Here is the code:

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
  char someChar = mySerial.read();
  Serial.print(someChar);
}

It’s slightly modified from this example .

It’s connected like so, after reading the datasheet and looking at examples:
Arduino 5V (under Power) ------> 11 (5V), 2 (RST)
Arduino GND (under Power) ----> 1 (GND), 7 (FS)
Arduino 2 (under Digital)--------> 9 (DO)

I also tried the following code, switching 9 (DO) on the reader to 1 (RX) on the Arduino. In that case, all I get is ÿ each time it loops.

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

void loop () {
   Serial.print((char)Serial.read());
}

I thought the output would be in ASCII since I set the Format Select to GND, which the datasheet says will make it ASCII. But neither the square nor the ÿ exists on the ASCII table, so I have no idea where this is coming from.

I wanted to make sure, so I tried changing it to:

void loop () {

  if (Serial.read() != 'ÿ') {
   Serial.print((char)Serial.read());
}

…but it printed out a lot of ÿÿÿÿÿÿÿÿÿÿÿ anyway.

SO. Can anyone please shed some insight on what all these squares and ÿ mean?

For starters, you are reading the serial port when there isn't necessarily any data in the serial buffer, so you are getting the value -1 back.

Try:

if(mySerial.available() > 0) {
byte val = mySerial.read();
Serial.print(val, BYTE);
}

Also you can connect a LED (with a 1k resistor in series) to pin 10. It will light up if the reader senses a card, regardless of what's going on with the serial port.

Ooops, the output will be more readable if you use:

if(mySerial.available() > 0) {
byte val = mySerial.read();
Serial.print(val, HEX);
Serial.print(" ");
}

Thank you for responding. I don't think I can do quite what you're saying because the SoftwareSerial page says that there is no available() method, but the read() method waits for a bit to come in anyway, so I think the available() is sort of built into the read() already? I tried your code just in case and it gave me the error message "error: 'class SoftwareSerial' has no member named 'available."

I did however follow your advice to try this code, with the reader's 9(D0) connected to Arduino's 0(RX):

void loop () {

  if (Serial.available() > 0) {
   Serial.print("I'm here! ");
   Serial.print((byte)Serial.read(), HEX);
  }
  
  else
       Serial.print("nope ");
       
  delay(1000);
}

The output is just "nope nope nope nope nope." I can't understand why it's not picking anything up. :-[

Also, may be a stupid question, but since I don't have an LED, can I attach the 10 (BZ) to the digital pin 13 on the Arduino to use the onboard LED?

I took some pictures of the connection. Unfortunately, I only have a mobile phone that takes grainy pictures as a camera, so you won't be able to see a detailed view. But if I'm lucky, you can spot a huge, glaring mistake.

So, if anyone would take a look here and tell me what looks completely wrong, I would be grateful.



I'm sorry for repeated posts. I'm trying to add any useful information I can, so I hope it's not annoying. I've been experimenting, trying to get something to happen, and I discovered something odd. When I pull the wire out of the 5V pin on the Arduino and put it back in again, the Arduino turns off. The LED marked PWR turns off and I hear the "ding dong" that Windows chimes when a USB device turns off or gets unplugged. I have to take out the USB, wait a while, and then put it back in to get it to work again.

Is that normal? Is there any chance at all that this is my lucky day and that was the vital clue to understand why this isn't working?

I can help you on this...