I am trying to get a LEDHead board by Rogue Robotics to read in from a software serial port (NewSoftSerial) with an RFID reader and place that serial data onto the first serial port of the LEDHead which has a Seeedstudio Bluetooth Bee hooked up. Unfortunately, while the RFID reader works for a straight to serial (Serial1 -> Serial) it seems not to be working under this new program. As a note, I want to use the second serial port (Serial1) for a Argent Radio Shield, so hooking the RFID reader to the second serial port is not an option.
The Bluetooth Bee will connect to both my Android phone and my Mac Mini, but no output from the RFID is seen on either device.
I'll let the code do the rest of the talking for me as I've hit a brick wall...!
//Arduino RFID Bluetooth Modem Code v4.01
//By Shane Morris, Gothuro Morris Rail Industries
//4th August 2011
//Happy Birthday Grace <3
#include <NewSoftSerial.h> //Software Serial Port
#define RxD 5
#define TxD 4
#define DEBUG_ENABLED 1
NewSoftSerial rfidSerial(RxD,TxD);
byte data[5]; //For holding the ID we receive
int val = 0;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
// Start serial port 19200 bps
//Serial1.begin(4800);
rfidSerial.begin(19200);
// Setting Auto Read Mode - EM4102 Decoded Mode - No password
// command: FF 01 09 87 01 03 02 00 10 20 30 40 37
rfidSerial.print(0xFF,BYTE); //Header
rfidSerial.print(0x01,BYTE); //Reserved
rfidSerial.print(0x09,BYTE); //Length (Command + Data)
rfidSerial.print(0x87,BYTE); //Command (0x87 sets auto mode behavior
rfidSerial.print(0x01,BYTE); //Data 1: Enable Auto-Read
rfidSerial.print(0x03,BYTE); //Data 2: Mode – Parity decoded – Manchester RF/64
rfidSerial.print(0x02,BYTE); //Data 3: Total number of block to be read (2)
rfidSerial.print(0x00,BYTE); //Data 4: No password expected
rfidSerial.print(0x10,BYTE); //Data 5: Password byte 1
rfidSerial.print(0x20,BYTE); //Data 6: Password byte 2
rfidSerial.print(0x30,BYTE); //Data 7: Password byte 3
rfidSerial.print(0x40,BYTE); //Data 8: Password byte 4
rfidSerial.print(0x37,BYTE); //Checksum
delay(500);
rfidSerial.flush();
/*Serial.flush();
Serial.println();
Serial.println("RFID module started in Auto Read Mode, Waiting for Card...");
*/
}
void loop()
{
val = rfidSerial.read();
while (val != 0xff)
{ //On Successful read, first byte will always be 0xFF
val = rfidSerial.read();
delay(1000);
}
//we already read the header (0xff)
rfidSerial.read(); // reserved
rfidSerial.read(); // length
rfidSerial.read(); // command (indicates tag data)
data[0] = rfidSerial.read(); // we read data 1
data[1] = rfidSerial.read(); // we read data 2
data[2] = rfidSerial.read(); // we read data 3
data[3] = rfidSerial.read(); // we read data 4
data[4] = rfidSerial.read(); // we read data 5
rfidSerial.read(); // checksum
// Indentify RFID Card
/*
boolean j_card = true;
boolean d_card = true;
*/
Serial.println("\r\n");
Serial.println("Card found - Code: ");
for (int i=0; i<5; i++)
{
if (data[i] < 16) Serial.println("0");
Serial.print(data[i], HEX);
Serial.print(0x00, HEX);
/*
//cross-check
if (data[i] != jeremy[i]) j_card = false;
if (data[i] != david[i]) d_card = false;
*/
}
//Serial.println();
}
void setupBlueToothConnection()
{
Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
delay(1000);
Serial.print("\r\n+STWMOD=0\r\n");
Serial.print("\r\n+STNA=SeeeduinoBluetooth\r\n");
Serial.print("\r\n+STAUTO=0\r\n");
Serial.print("\r\n+STOAUT=1\r\n");
Serial.print("\r\n+STPIN=0000\r\n");
delay(2000); // This delay is required.
Serial.print("\r\n+INQ=1\r\n");
delay(2000); // This delay is required.
}
As you can see, I've kludged together some example code where necessary, and adapted it to work, but this whole problem is a little vexing as I'm not sure where the problem lies...!
Thanks in advance for any help you can give.
Boris.