Difficulty with serial transmit and receive

Hello

I am working on the project in which serial communication has to be done with two arduino boards. One board has to input analog signals from multiple sensors and send it to other arduino board and display it on tft screen. Circuit works fine if i send only one analog signal with the command of SerialParseInt. But how to send and receive all the analog signals over serial port. By serialParseInt only one analog signal is received over other arduino board. There are at least 5 sensors whose data has to be sent and received serially.

The first obvious step is to read each of the sensors and save the values. An array would be useful to store them. Having stored them then you can send them to the second Arduino via Serial but it helps if you send them in a structured message that makes decoding them on the Rx side easier.

Take a look at Serial input basics - updated to see some advice and techniques

@OP

The following sketches handle only one analog channel (A0). Check if you can expand it to accommodate Ch-1, …, Ch-5.

Sender Codes:

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
int x0, x1, x2, x3, x4;   //variables to hoold analog signals
//char myData[20] = "";

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

void loop()
{
  SUART.print('<');  //Start Mark of Message
  //-----------------
  readAndTransmit(14);   //Ch-A0, DPin-15 = A1 and so on..
  //-----------------
  SUART.print('>');   //End mark of Message
  //------------------
  delay(1000);
}

void readAndTransmit(int ch)
{
  int x = analogRead(ch); //x = 0x0000 - 0x03FF
  SUART.print(x);
  Serial.println(x);
}

Receiver Codes:

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
int x0;//variables to hoold analog signals
char myData[20] = "";
bool flag1 = false;

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

void loop()
{
  byte n = SUART.available();  //check buffer
  if (n != 0)
  {
    if (flag1 == false)
    {
      char ch = SUART.read();
      if (ch == '<')
      {
        flag1 = true;
      }
    }
    else
    {
      SUART.readBytesUntil('>', myData, 20);
      int x0 = atoi(myData);
      Serial.println(x0);
      flag1 = false;
      char myData[20] = "";
    }
  }
}
    else
    {
      SUART.readBytesUntil('>', myData, 20);  //<<<< which of the two different variables named myData will this use ?
      int x0 = atoi(myData);
      Serial.println(x0);
      flag1 = false;
      char myData[20] = "";
    }

See the question in the commented code

UKHeliBob:

    else

{
      SUART.readBytesUntil(’>’, myData, 20);  //<<<< which of the two different variables named myData will this use ?
      int x0 = atoi(myData);
      Serial.println(x0);
      flag1 = false;
      char myData[20] = “”;
    }



See the question in the commented code

I have not understood the question. The .readBytesUntil() method will store all incoming charcaters in the array named ‘char myData[20];’ except < and >. (The < has already been filtered out; > is the terminating symbol.)

I have not understood the question.

There are two different arrays named myData in the program. Which one will be used by

SUART.readBytesUntil('>', myData, 20);