Sending sensor data over serial bus (Nano to Nano)

@bluemanron
1. Connect NANO and mEGA as per following diagram of Fig-1.

uartNanoMega
Figure-1:

2. Upload the following sketch (your sketch of Post-1 with slight modification) in NANO.

#include<SoftwareSerial.h>
SoftwareSerial SUART(4, 5);  //SRX=DPin-4, STX=DPin-5

int rowStatus1 = 0;   // Sensor status, with test values
int rowStatus2 = 4;    // Sensor status, with test values
int rowStatus3 = 16;  // Sensor status, with test values
int rowStatus4 = 0;    // Sensor status, with test values
int rowStatus5 = 4;    // Sensor status, with test values
int rowStatus6 = 16;  // Sensor status, with test values
int rowStatus7 = 0;    // Sensor status, with test values
int rowStatus8 = 4;    // Sensor status, with test values

void setup()
{
  Serial.begin(9600);     // Open serial comms to arduino Nano
  SUART.begin(9600);
}

void loop() // run over and over
{
  SUART.print(rowStatus1);  SUART.print (',');//comma seperated data
  SUART.print(rowStatus2);  SUART.print (',');
  SUART.print(rowStatus3);  SUART.print (',');
  SUART.print(rowStatus4);  SUART.print (',');
  SUART.print(rowStatus5);  SUART.print (',');
  SUART.print(rowStatus6);  SUART.print (',');
  SUART.print(rowStatus7);  SUART.print (',');
  SUART.print(rowStatus8);  SUART.print (',');
  SUART.print ('\n');
  delay (5000);   //test interval
}

3. Upload the following sketch in MEGA.

char myData[50];
char *temPtr;

void setup()
{
  Serial.begin(9600);
  Serial3.begin(9600);
}

void loop()
{
  byte n = Serial3.available();
  if (n != 0)
  {
    byte m = Serial3.readBytesUntil('\n', myData, 50);
    myData[m] = '\0';  //null-byte
    // Serial.println(myData);
    //------------------------------
    unsigned int s1 = strtoul(myData, &temPtr, 10);
    unsigned int s2 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s3 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s4 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s5 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s6 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s7 = strtoul(temPtr + 1, &temPtr, 10);
    unsigned int s8 = strtoul(temPtr + 1, &temPtr, 10);
    //----------------------------------------------
    Serial. println(s1, DEC); Serial. println(s2, DEC);
    Serial. println(s3, DEC); Serial. println(s4, DEC);
    Serial. println(s5, DEC); Serial. println(s6, DEC);
    Serial. println(s7, DEC); Serial. println(s8, DEC);
    Serial.println("=========================");
  }
}

4. Check that the Serial Monitor of MEGA shows the received status values correctly.

4
=========================
0
4
16
0
4
16
0
4
=========================
0
4
16
0
4

5. Working Principle of strtoul() Function:
The function parses (reads a character from a character type array and checks if it is a decimal or hexadecimal digit) a string (array of characters) and stops at the non-digit character. The ASCII codes of the digits which have been parsed so far are converted into a numerical number and are saved in a variable. For example:

char myArray[] = “1234, 56, 78”;
char *temPtr;r
unsigned int x1 = strtoul(myArray, &temPtr, 10);   // x1 = 0x04D2
Serial.println(x1, DEC);  //shows: 1234

The arg3 (= 10) says that the function looks for decimal digits in the array. The parsing stops at the first comma (,); there remains the sub-array/sub-string (, 56, 78) which will be parsed next time to extract 56. Now, we need a pointer variable (*temPtr) to point the beginning of the sub-array. The arg2 (= &temPtr) passes to the pointer variable the address of the character at which parsing had stopped and thus offers a way to the strtoul() function to locate the beginning of the sub-array.