Hi all,
I’m having a bit of an issue with an ID-12 RFID reader not working, and I was wondering if I could possibly get some assistance?
As part of an automatic train detection system on my model railroad, I’ve got an ID-12 RFID reader mounted above the tracks, hooked back to an Arduino Duemilanove (via a Sparkfun breakout board) as per the diagram in step 2 of this tutorial: http://www.instructables.com/id/Reading … /?ALLSTEPS. D0 goes back to pin 9 of the Duemilanove, which is configured in the software (below) as the RX pin of a SoftwareSerial object. (The hardware serial will be used for an XBee module for communication to another system). The other pin of the SoftwareSerial, Pin 7, is not connected to anything at all.
Below is the code for the test program:
#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;
}
}
}
I had previously tested the ID-12 with the above code, but with the output to the serial port instead (i.e. replace ‘lcdScreen’ with ‘Serial’ in the body of the program) and it was able to read the RFID tags. However, when I tried it on the model railroad, there was no response, even when I touched the RFID tag right on top of the reader. I also tried adapting the above code to just show a line saying ‘RFID Tag Read’, also with no luck.
One thing that’s just struck me, as I write this, is that the Duemilanove is powering quite a few other sensors from it’s 5V output as well:
-
3 light dependant-resistors
-
2 HR-S04 ultrasonic modules
As such, would providing the ID-12 with its own 5V power supply (with a common ground to the Arduino) possibly fix this issue?
Cheers,
Tbdanny