Sorry about that, and yes trying to use software serial. You would think software serial would have a way of handling this issue somehow, otherwise its uses are very minimal. And I just purchased an ATMEGA 2560 R3, hopefully this is more versatile with it's designated serial pins.
Thanks for the help!
#include <SoftwareSerial.h>
#include <Rfid134.h>
//___________________________________________________________________________________________________________________________________________________________
// Program variables ----------------------------------------------------------
int exampleVariable = 0;
int sensorPin = A0;
char x;
char weight;
// Serial data variables ------------------------------------------------------
//Incoming Serial Data Array
const byte kNumberOfChannelsFromExcel = 6;
// Comma delimiter to separate consecutive data if using more than 1 sensor
const char kDelimiter = ',';
// Interval between serial writes
const int kSerialInterval = 550;
// Timestamp to track serial interval
unsigned long serialPreviousTime;
char* arr[kNumberOfChannelsFromExcel];
SoftwareSerial mySerial(9, 10); // RX, TX
//________________________________________________________________________________________________________________________________________________________________
// implement a notification class,
// its member methods will get called
//
class RfidNotify
{
public:
static void OnError(Rfid134_Error errorCode)
{
// see Rfid134_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPacketRead(const Rfid134Reading& reading)
{
char temp[8];
// since print doesn't support leading zero's, use sprintf
sprintf(temp, "%03u", reading.country);
Serial.print(temp);
Serial.print(" ");
// since print doesn't support leading zero's, use sprintf
// since sprintf with AVR doesn't support uint64_t (llu/lli), use /% trick to
// break it up into equal sized leading zero pieces
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id / 1000000));
Serial.print(temp);
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id % 1000000));
Serial.print(temp);
Serial.print(" ");
if (reading.isData)
{
Serial.print("data");
Serial.print(x);
}
if (reading.isAnimal)
{
}
Serial.println();
Serial.print(x);
Serial.print(kDelimiter);
}
// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
static void processOutgoingSerial(const Rfid134Reading& reading)
{
// Enter into this only when serial interval has elapsed
if((millis() - serialPreviousTime) > kSerialInterval)
{
// Reset serial interval timestamp
serialPreviousTime = millis();
{
char temp[8];
// since print doesn't support leading zero's, use sprintf
sprintf(temp, "%03u", reading.country);
Serial.print(temp);
Serial.print(" ");
// since print doesn't support leading zero's, use sprintf
// since sprintf with AVR doesn't support uint64_t (llu/lli), use /% trick to
// break it up into equal sized leading zero pieces
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id / 1000000));
Serial.print(temp);
sprintf(temp, "%06lu", static_cast<uint32_t>(reading.id % 1000000));
Serial.print(temp);
Serial.print(" ");
if (reading.isData)
{
Serial.print("data");
Serial.print(x);
}
if (reading.isAnimal)
{
}
Serial.println();
Serial.print(x);
Serial.print(kDelimiter);
}
}
}
// INCOMING SERIAL DATA PROCESSING CODE----------------------------------------
void processIncomingSerial()
{
if(Serial.available()){
parseData(GetSerialData());
}
}
// Gathers bytes from serial port to build inputString
char* GetSerialData()
{
static char inputString[64]; // Create a char array to store incoming data
memset(inputString, 0, sizeof(inputString)); // Clear the memory from a pervious reading
while (Serial.available()){
Serial.readBytesUntil('\n', inputString, 64); //Read every byte in Serial buffer until line end or 64 bytes
}
return inputString;
}
// Seperate the data at each delimeter
static void parseData(char data[])
{
char *token = strtok(data, ","); // Find the first delimeter and return the token before it
int index = 0; // Index to track storage in the array
while (token != NULL){ // Char* strings terminate w/ a Null character. We'll keep running the command until we hit it
arr[index] = token; // Assign the token to an array
token = strtok(NULL, ","); // Conintue to the next delimeter
index++; // incremenet index to store next value
}
}
//_____________________________________________________________________________________________________________________________________excel code
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
static void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* Helper routine to dump a byte array as dec values to Serial.
*/
static void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
}
};
SoftwareSerial secondarySerial(5, 11); // RX, TX
Rfid134<SoftwareSerial, RfidNotify> rfid(secondarySerial);
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
secondarySerial.begin(9600);
rfid.begin();
}
void loop()
{
rfid.loop();
}