Seemingly no response from RFID reader?

Hi all,

I have an ID-12 RFID reader, the output of which I am trying to display on an LCD screen. Both LCD screen and RFID reader are currently in situ on my model railroad.

When I tested the RFID reader with the Arduino, it was able to read tags using the code below, although the range was shorter than anticipated (as I was using the USB for power):

#include <SoftwareSerial.h>

SoftwareSerial rfidSerial(6, 7); // RX, TX
char val = 0;

void setup() {
  // put your setup code here, to run once:
  rfidSerial.begin(9600);
  Serial.begin(9600);
}

void loop () {
  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(Serial.available() > 0) {
    if((val = Serial.read()) == 2) {                  // check for header 
      bytesread = 0; 
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if(Serial.available() > 0) { 
          val = Serial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading 
            break;                                    // stop reading
          }

          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }

          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        } 
      } 

      // Output to Serial:

      if (bytesread == 12) {                          // if 12 digit read is complete
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();

        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();
      }

      bytesread = 0;
    }
  }
}

Now, however, all that’s changed is that the output is to an LCD rather than a serial output, as per below:

#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

SoftwareSerial rfidSerial(9, 7); // RX, TX
char val = 0;
LiquidCrystal_I2C lcdScreen(0x27,2,1,0,4,5,6,7); //LCD Display

void setup() {
  // put your setup code here, to run once:
  rfidSerial.begin(9600);
  Serial.begin(9600);
}

void loop () {
  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(Serial.available() > 0) {
    if((val = Serial.read()) == 2) {                  // check for header 
      bytesread = 0; 
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if(Serial.available() > 0) { 
          val = Serial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading 
            break;                                    // stop reading
          }

          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }

          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        } 
      } 

      // Output to LCD:

      if (bytesread == 12) {                          // if 12 digit read is complete
        lcdScreen.clear();
        lcdScreen.home();
        lcdScreen.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) lcdScreen.print("0");
          lcdScreen.print(code[i], HEX);
          lcdScreen.print(" ");
        }
        lcdScreen.println();

        lcdScreen.print("Checksum: ");
        lcdScreen.print(code[5], HEX);
        lcdScreen.println(code[5] == checksum ? " -- passed." : " -- error.");
        lcdScreen.println();
      }

      bytesread = 0;
    }
  }
}

The ID-12 is running from the Arduino’s 5V output, and the serial output of it is connected to pin 9. Pin 7 is not connected at all. However, when I pass an RFID tag under the reader, I get no output on the LCD.

I can confirm the LCD display is working, as I’ve tested that separately. I’m not sure if the problem is with the way I’ve written the code, or the way the ID-12 is set up. The three connections are exactly as they were for the test (aside from the RX pin being 9 instead of 6), and the power connections are also the same. So too is the code.

Any help would be greatly appreciated, as this whole system relies on having the information from the RFID reader to function.

Cheers,
Tbdanny

Hi all,

I've done a bit of poking around, by changing the code for displaying on the LCD to the following:

      // Output to LCD:

      if (bytesread == 12) {                          // if 12 digit read is complete
        lcdScreen.println("RFID Tag Read");
        delay(5000);
      }

      bytesread = 0;

This still did not yield any results when I passed the RFID tag under it, and I tried it with a couple of other tags as well, still with no results. I have a feeling I'm just missing something small, and I would appreciate any help in this regard.

Cheers,
Tbdanny

If it worked before, go back to serial to confirm it still works. Something else may have changed. You need to start again from a known working point.

You should still have the working code as it is good practice to keep previous versions once that part is working. Then start a new sketch (Save As progName ver2 etc) and add next stage.

Weedpharma

Hi Weedpharma,

I've just tried that, with my laptop in the garage on the model railroad. No luck. I passed a spare RFID tag under the reader several times, and got nothing.

I also tried powering the ID-12 from its own 4.5v DC power supply, in case the Arduino wasn't providing enough current for the RFID reader. There is a common ground connection between the power supply to the RFID reader and the Arduino. Again, this yielded no results.

The only other difference is that during the original testing, I used pin 6 as the RX and 7 as the TX on the Arduino, whereas in this implementation, I'm currently using pin 9 as the RX and 7 as the TX. In both cases, pin 7 was disconnected. Given that I'm using softwareserial, I didn't think this would make a difference. Would it?

Cheers,
Tbdanny

The only way to test it is put it all back to how it originally worked. If ok then, it is a problem with your new connections/program.

If it works with original connections, move it to the new pins and modify program to suit. Get it working at this point before moving on to next step.

Weedpharma

Hi Weedpharma,

Thank-you for your help & advice.

I just tried testing with the original pins, and no luck :-(.

I'm baffled as to what could have caused this. I mean, even the wires coming off the RFID reader are the same ones I was using for the testing. I just extended them with some extra wire (soldered joint, isolated with heatshrink) to the Arduino.

I've also done some testing with my multimeter. There is virtually no resistance (~1.2 ohms) along the length of the wire between the D0 connection of the ID-12 and the Arduino. I also checked the input voltage, and I can confirm that the ID-12 reader is getting the 4.63v from the voltage regulator.

As such, I suspect that the ID-12 may have been damaged during installation. I've been putting a bit of thought about this, and I've realised that I may be able to get it working via another means.

I don’t know how you have it wired but the Datasheet circuit indicates that you can get some info without the Arduino connected. Read 10.2 to see how to get an LED to light for a read of a card.

[http://cdn.sparkfun.com/datasheets/Sensors/ID/ID-2LA,%20ID-12LA,%20ID-20LA2013-4-10.pdf](http://“http://cdn.sparkfun.com/datasheets/Sensors/ID/ID-2LA, ID-12LA, ID-20LA2013-4-10.pdf”)

Weedpharma