Arduino UNO Software Serial Two sources to Excel Datastreamer

Hello all,

I am working on a small project that should be straight forward but I am running into one small hurdle.

I have one arduino UNO, a weigh scale which outputs the weight via rs232 (then translated through a max3232) and a WL-134 RF tag reader specifically designed to read RF tags from animals.

The main objective is to read the animals weight from the weigh scale as well as the animals tag and then transfer the two pieces of data to excel via the excel data streamer.

I can read the weigh scale (mySerial) without issue and send the data to excel done with excel data streamer example code and software serial.

I can scan the animal tag(secondarySerial) and send the data to excel without issue using a mix of the RL-134 example code and excel data streamer example code.

What I'm having an issue with is getting both to send to excel together. I cannot seem to find the correct area to insert the print instruction for my weight to make it to excel data streamer along with the animal tag.

Could somebody please take a look at my sketch and suggest the best area to insert the print instruction ?

I will send my working sketch that is only sending animal tag data, as I am very unsure where to insert the myserial data from the weigh scale to print along with the animal tag.
ReadRfid_WL_134.ino (5.6 KB)

rather than providing a link upload you code using code tags </> - read how-to-get-the-best-out-of-this-forum
I assume with the UNO you will be using SoftwareSerial?
I would recommend you switch to a Mega and use hardware serial ports

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();    
}

the UNO is a basic low cost microcontroller and SoftwareSerial gives it a limited serial port for low speed applications. The problem is that once the serial Start bit is received the data bits are clocked out by the transmitter at fixed intervals and the higher the baudrate the more time critical the receiving of the data bits becomes.

That's the beauty of open source, isn't it. Someone probably wrote software serial for their own particular purpose, and then made it available to the rest of us, limitations and all. But (and here's the really cool part) you're welcome to grab the source and modify it to fix those limitations and then drop it back in the pool as "software serial rvk" thus helping the pool to evolve.

Google has nothing to say about secondarySerial, so what is it?

looks like another SoftwareSerial port

SoftwareSerial secondarySerial(5, 11)

Gawd... I hope he read reply #2

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.