Serial To Serial Comunications Errors

Hello,

I am relatively new to Arduino coding and have undertaken the task of sending data via Serial ports to two different Arduino boards. I am using an Arduino Mega for the Master and a Arduino Uno for the slave. They are connected in the following manner:

(RX1) on the mega to (TX0) on the uno

(TX1) on the mega to (RX0) on the uno

(GND) on the mega to (GND) on the uno

The serial comm works fine and I can use the Serial.print() function on the mega to send data to the uno while using the Serial.readString() fuction on the uno to read the data string in. The problem that I am having is that when I reset the mega, the uno’s program runs the start up function but will not run the loop function until the serials are disconnected. Then when I plug the serial link back in the program freezes once again. It should be noted that on initial start up everything runs correctly in regard to the serial communication. It is only after reset of one or both of the boards that the problem occurs.

I should mention that I am looking at the Uno’s serial through a USB connection when this happens. Could this have something to do with it?

Additionally I am using a RockBlock Sat Comm setup through soft serial to send the data received from the mega, as well as a 4D Systems resistive touch screen on the Mega as a timer display and control (which is attached to Serial 0 of the mega).

The reason for the reset is so that the timer runs correctly. For some reason on startup the timer counts one second for approximately every five seconds or so of real time. After a reset on the board the timer works fine but then the serial communications do not. This a lot to take in so I am posting the entire uno code and parts of the mega code. If Additional information is required please feel free to ask.

Please if anyone can help it would be greatly appreciated. Thank you well in advance to any and all how can help.

Uno Code:

#include <IridiumSBD.h>
#include <SoftwareSerial.h>

//Global Time Constaint
const int Time_Displacment = 5;

// Mega Variables to bring in.
String Message;

// Data string and text message variables
String Comp_Msg;
char Text [100];

// Message timer
unsigned int Send_Timer = 0;
int Run_Time_Min = 0;
int Run_Time_Sec = 0;

//NOTE: Serial Comm is wire as follows:
//Mega (RX1) to Uno (TX)
//Mega (TX1) to Uno (RX)
//Mega (GND) to Uno (GND)

// Sat Comm Variables
SoftwareSerial nss(11, 12); // RXD to pin 11, TXD to pin 12
IridiumSBD isbd(nss, 8); // On/Off to pin 8, 5V in to 5Volt pin, GND to GND
static const int ledPin = 13;
int err;
int signalQuality = -1;


void setup()
{
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
  nss.begin(19200);

  isbd.attachConsole(Serial);
  isbd.setPowerProfile(1);
  isbd.begin();
  
}

void loop()
{
   digitalWrite(ledPin, HIGH);

  // Place call to Serial read function
  //    function should read from the mega/uno serial 
  //    and store the variables in there corrisponding palces.


  //sets up message
   Packer();
  
  // timer for the sat comm send interval
  if (millis()- Send_Timer >= 1000)
   {
      //delay(1000);
      Run_Time_Sec++;
      Send_Timer = millis(); 
 
      Serial.print("Time is: ");
      Serial.print(Run_Time_Min);
      Serial.print("Min and ");
      Serial.print(Run_Time_Sec);
      Serial.println("Sec");
   }
   
   if (Run_Time_Sec == 60)
   {
      Run_Time_Min++;
      Run_Time_Sec = 0;  
     
      err = isbd.getSignalQuality(signalQuality);

      if (err != 0)
      {
         Serial.print("SignalQuality failed: error ");
         Serial.println(err);
         return;
      }
      
      Serial.print("Signal quality is ");
      Serial.println(signalQuality);
   }
   
  
   
   if (Run_Time_Min == Time_Displacment)
   {  
      //Data_Sender();
      Run_Time_Sec = 0;
      Run_Time_Min = 0;
   }
   
}

bool ISBDCallback()
{
   digitalWrite(ledPin, (millis() / 1000) % 2 == 1 ? HIGH : LOW);
   return true;
}

void Data_Sender()
{
  err = isbd.sendSBDText(Text);
  Serial.println("Data sent");
  
  if (err != 0)
  {
    Serial.print("sendSBDText failed: error ");
    Serial.println(err);
    return;
  }

  Serial.println("Hey, it worked!");
  Serial.print("Messages left: ");
  Serial.println(isbd.getWaitingMessageCount());
}

void Packer()
{

  if (Serial.available() > 0)
  {
    Message = Serial.readString();
    Message.toCharArray(Text, sizeof(Text));
  }
    Serial.println(Message);
    Serial.println("");
    Serial.println(Text);
    
    Serial.println("");
}

Mega Timer Code:

void Lap_Timer (void)
{


// once button is pressed set the starting point to the new controller run time.
  if (Screen_Input == 1)
  {
    Timer_Start_Stop = true;
  }
  if (Screen_Input == 0)
  {
    Timer_Start_Stop = false;
  }

// If the timer start/stop button is set to on then run the clock.
  if (Timer_Start_Stop == true)
  {
      if (millis ()- start_point >= 1000)
      {
        Seconds++; 
        start_point = millis ();
      }
      
      if (Seconds == 60)
      {
        Minutes ++; 
        Seconds = 0;
      }
  }    

  // update the screen.
  genie.WriteObject (GENIE_OBJ_LED_DIGITS, 0, Seconds);
  genie.WriteObject (GENIE_OBJ_LED_DIGITS, 1, Minutes);
  genie.WriteObject (GENIE_OBJ_LED_DIGITS, 2, N_Laps);

}// End Lap_Timer function.

Mega 4D Systems Screen Event Handler Code:

// Function handels all touch screen events.
void myGenieEventHandler(void)
{
  genieFrame Event; // gets the event from the frame

  genie.DequeueEvent(&Event); // Remove this event from the queue


    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)  // If this event is from a Slider
    {
      // if an event happens with an object index of two change the value of Screen_Input.
      if (Event.reportObject.index == 2)
      {
        Screen_Input = genie.GetEventData(&Event);  //Toggle Button
      }

      // if an event happens with an object index of four, perfrom the following actions:
      // reset start point, increment the lap number, reset seconds, and reset minutes.
      if (Event.reportObject.index == 4)
      {
        Reset = genie.GetEventData(&Event);  //Reset Button;
        start_point = millis();
        N_Laps++;
        Seconds = 0;
        Minutes = 0;
      }  
    }//end event if.
  
}// end myGenieEventHandler

Hello Again,

I have continued to work on the problem since my first post and have determined that it is not a problem with the Serial Communications. After running some simple test code in the two boards, using the same connections as mentioned in my first post, I was able to reset either board and still have the Uno continually execute its code with no interference. Since the only other piece of hardware connected to the Arduino is the RockBlock Sat Comm. It is safe, in my estimation, to say that it is a problem with the RockBlock Library.

Before anyone asks, yes I have read the information posted on the RockBlock Library (Which can be found at this link: http://arduiniana.org/libraries/iridiumsbd/ ). Unfortunately I am having a hard time understanding everything posted here as the page, in my opinion, does not list all the relevant information in a clear manner. If there is someone out there that has used the RockBlock with Arduino before and has a better understanding please offer your help. It is greatly appreciated. Also please take a look at the code posted in my previous post under Uno Code as this contains the problem area.

As a help to anyone reading this post and for those who are gracious enough to help solve this problem I am posting the code I used to to test the serial comms for this post. Thank you to everyone who posts suggestions, comments, and/or questions that my bring about a solution. Full solutions are also excepted and you will have my thanks.

Mega (Master) Code: (NOTE: change Serial1 to Serial and this should run on an Uno board)

int Number_Test = 45;
double Double_Test = 45.67;
String Msg = "Message Sent, Numbers are: ";




void setup() {
  // put your setup code here, to run once:

  Serial1.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial1.write("Serial write function: Number is: ");
  delay(1000);
  Serial1.write(Number_Test);
  delay(1000);
//  Serial1.write(Double_Test);
//  delay(1000);
//  Serial1.write(Msg);
//  delay(2000);
  Serial1.print("Serial Print Function: Number is: ");
  delay(1000);
  Serial1.print(Number_Test);
  delay(1000);
  Serial1.print("Double Value is: ");
  delay(1000);
  Serial1.print(Double_Test);
  delay(1000);
  Serial.print("String Value is: ");
  delay(1000);
  Serial1.print(Msg);
  delay(1000);
  Msg.concat(Number_Test);
  Msg.concat(", ");
  Msg.concat(Double_Test);
  Double_Test+=4.25;
  Number_Test++;
  delay(2000);
}

Uno (Slave) Code:

String Message;
char Text_Array[1000];
String Comp_Msg = "";


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

  if (Serial.available() > 0)
  {
    Message = Serial.readString();  
    Comp_Msg.concat(Message);
    Message = "";
    Comp_Msg.toCharArray(Text_Array, sizeof(Text_Array));  
    
    Serial.println(Comp_Msg);
    Serial.println(Text_Array);
  }
}