The microreader is wired in permanent read mode, which means the built-in serial ports will not be able to accept programming commands from the PC. To combat this, the microreader data is input on Pin 3 of the Arduino using NewSoftSerial.
The LCD shield is from eBay, from eKitsZone in Hong Kong. The shield was £12.50, as was the Duemilanove from the same source.
Here's the breadboarded circuit from the underside:
The code below works fine. The bit that identifies the transponders is crude, due to the limited selection of tags I have. But this is only a proof of concept, so there's no real problem. PCB shield to follow.
TI page on MicroReader: http://www.ti.com/rfid/shtml/prod-readers-RI-STU-MRD1.shtml
Here's the code. Blogger has removed all the indents, but Arduino's auto format function will repair that.
/*
Serial test program 3 - works with TI Series 2000 reader
This version uses the newsoftserial library as the native serial port is disrupted by
the reader's constant output.
*/
#include
#include
int inByte = 0; // incoming serial byte
int iMsgPtr = 0; // position in reader message
boolean bMsgOn = false; // true when message being processed
boolean bNextID = false; // indicates next byte IDs the transponder (utter bodge!)
NewSoftSerial tiReader(3,2); // define pin 3 as RX, 2 as TX
LCD4Bit_mod lcd = LCD4Bit_mod(2); // define LCD, 2 line display
void setup()
{
// start serial port for input from TI reader at 9600 bps:
tiReader.begin(9600);
// start serial port fordebug output to PC serial monitor at 9600 bps:
Serial.begin(9600);
// initialise the display, clear it and put up a message
lcd.init();
lcd.clear();
lcd.printIn("Transponder ID");
}
void loop()
{
if (tiReader.available() > 0)
{
// get incoming byte from serial port:
inByte = tiReader.read();
// if start of message byte detected declare new message
if ((inByte==1) && (bMsgOn == false))
{
bMsgOn = true; // message being processed
iMsgPtr = -1; // initialise message pointer
}
else
// if processing a message...
if (bMsgOn == true)
{
// if this is the message length byte
if (iMsgPtr == -1)
{
iMsgPtr = inByte + 1; // add a byte to accommodate the error check
bNextID = true; // next btye is start of transponder ID
}
else
{
// decrement message pointer, check for end of message
iMsgPtr--;
if (iMsgPtr == 0)
{
// end of message
bMsgOn = false;
}
// This is the bodged bit. All the tags we have use different first bytes, allowing them to
// be ID'd straight away. The code should really build up an 8-byte ID, checking when complete.
if (bNextID = true)
{
bNextID = false;
switch (inByte){
case 0x61: outputData("Keyring 1");
break;
case 0x63: outputData("Trainer tag");
break;
case 0xCD: outputData("Stick");
break;
case 0xE4: outputData("Keyring 2");
break;
case 0xF5: outputData("Disc");
break;
}
}
}
}
}
}
void outputData(char value[])
{
// output data to LCD, copying to the PC serial for debugging
Serial.println(value);
lcd.cursorTo(2, 0); //line=2, x=0
lcd.printIn(" ");
lcd.cursorTo(2, 0); //line=2, x=0
lcd.printIn(value);
}