Problem when serial port disconnected


I have 2x Mega2560p’s talking to each other over a serial link.
All runs fine.

But, there is a possibility that one of the two Mega’s will be powered off at some point, without the first Mega knowing that.

This causes the second Mega to freeze when it checks for serial data.

Would this possibly be noise on the RX/TX lines making the Mega possibly think it’s still there?
The connecting serial lead is 400mm (screened). I will shorten that in the future to<100mm.

Is there any way to pull up/down the serial link to ensure it stays ‘clean’ when there is no connection?

We probably need to see your code.

OK. I also just noticed that the data that is arriving is ignoring the decimal point?
I am reading the incoming data in a loop, and allocating it to variable, but does it not read the incoming decimal point?

For instance:

If the incoming data is: 60.00

The array search loop runs along the incoming data and only finds 4x 'targets'. It seems to ignore the decimal point.

Still no code. How are we to troubleshoot your code when you refuse to post it? Have you read the how to use this forum stickies?

Yea, but I am not in front of my home laptop with the code, I am at work.
I am looking at my project running on the desk in front of me with the OLED screen. I can't lift the code back off the Mega, so it will have to wait until I am home.

Surely it is entirely possible to answer 'SOME' Arduino programming questions without the usual 'no code, no help' affair.

Don't worry, I will sort it out myself

The code gives us a clue as to how the two Megas are connected. If it is not the code then it is a hardware problem and we know nothing about your hardware except that there are 2 Megas connected by long wires.

So we are supposed to list, for you, all possible reasons why the code or hardware are failing? If we can see the code and how the hardware is set up we can give informed help instead of "shotgun" help.

I wired up two Mega boards using Serial1 to connect them (RX-TX, TX-RX). Neither of the boards freeze when the other board is powered off or if the serial link is severed.

Here is the code that I used to make the test. Thanks to Robin2 for the serial input code from his serial input basics tutorial.

const byte numChars = 16;
char receivedChars[numChars];
boolean newData = false;

void setup()
   Serial.println("begin test");

void loop()
      Serial.print("incoming mills  ");
      newData = false;
  static unsigned long timer = 0;
  unsigned long interval = 1000;
  if(millis() - timer >= interval)
   timer = millis();
   Serial.println("          sending millis \n");

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
    while (Serial1.available() > 0 && newData == false) {
        rc =;

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            if (ndx >= numChars) {
                ndx = numChars - 1;
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;

"Surely it is entirely possible to answer 'SOME' Arduino programming questions without the usual 'no code, no help' affair."

The crystal ball is fuzzy, kind of like something in your code, somewhere between "This causes the second Mega to freeze" and "is ignoring the decimal point". A chicken sacrifice might be in order, preferably an extra crispy 10 piece bucket.