Thanks Graynomad,
I'm managed to get it working using Software serial.
You're right I am only wanting to send the RFID information and receive the information from the Mac, so I'll look into that.
Heres the current code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define rxPin 8
#define txPin 9
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
int RFIDResetPin = 13;
//Register your RFID tags here
char tag1[13] = "4500B8A5025A";
char tag2[13] = "4500B8C30F31";
char tag3[13] = "4500B8A4C49D";
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
//ONLY NEEDED IF CONTROLING THESE PINS - EG. LEDs
pinMode(6, OUTPUT);
lcd.begin(16, 2);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop(){
char tagString[13];
int index = 0;
boolean reading = false;
//RFID TRYING TO READ
// Read all serial data available, as fast as possible
while(mySerial.available() > 0)
{
int readByte = mySerial.read(); //read next available byte
if(readByte == 2) reading = true; //begining of tag
if(readByte == 3) reading = false; //end of tag
if(reading && readByte != 2 && readByte != 10 && readByte != 13){
//store the tag
tagString[index] = readByte;
index ++;
}
}
while(Serial.available()){
//TRYING TO READ AppleScript STRING
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
Serial.println(inData);
lcd.setCursor(0, 0);
lcd.print(inData);
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
checkTag(tagString); //Check if it is a match
clearTag(tagString); //Clear the char of all value
resetReader(); //reset the RFID reader
}
void checkTag(char tag[]){
///////////////////////////////////
//Check the read tag against known tags
///////////////////////////////////
if(strlen(tag) == 0) return; //empty, no need to contunue
if(compareTag(tag, tag1)){ // if matched tag1, do this
lightLED(2);
Serial.println("a");
}else if(compareTag(tag, tag2)){ //if matched tag2, do this
lightLED(2);
Serial.println("b");
}else if(compareTag(tag, tag3)){
lightLED(2);
Serial.println("c");
}else{
Serial.println(tag); //read out any unknown tag
}
}
void lightLED(int pin){
///////////////////////////////////
//Turn on LED on pin "pin" for 250ms
///////////////////////////////////
digitalWrite(pin, HIGH);
delay(250);
digitalWrite(pin, LOW);
}
void resetReader(){
///////////////////////////////////
//Reset the RFID reader to read again.
///////////////////////////////////
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
delay(150);
}
void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
for(int i = 0; i < strlen(one); i++){
one[i] = 0;
}
}
boolean compareTag(char one[], char two[]){
///////////////////////////////////
//compare two value to see if same,
//strcmp not working 100% so we do this
///////////////////////////////////
if(strlen(one) == 0) return false; //empty
for(int i = 0; i < 12; i++){
if(one[i] != two[i]) return false;
}
return true; //no mismatches
}