O2/pH/TDS sensors softserial multi port problem

I'm trying to read three sensors using softserial. If I try to listen to more than one port It doesn't read any of the sensors. If I only try to read one it works fine.

#include <SoftwareSerial.h>      //we have to include the SoftwareSerial library, or else we can't use it.  
SoftwareSerial myserial1(2, 3); //define how the soft serial port is going to work. 
SoftwareSerial myserial2(4, 5); //define how the soft serial port is going to work. 
SoftwareSerial myserial3(6, 7); //define how the soft serial port is going to work. 
char tds_data[20];                  //we make a 20 byte character array to hold incoming data from the tds.    
char o2_data[20];                  //we make a 20 byte character array to hold incoming data from the o2.                
char ph_data[20];                  //we make a 20 byte character array to hold incoming data from the pH.   
byte received_from_sensor=0;       //we need to know how many characters have been received.
float o2=0;                        //used to hold a floating point number that is the o2. 
float ph=0;                        //used to hold a floating point number that is the pH. 
float tds=0;                        //used to hold a floating point number that is the tds. 
byte string_received=0;            //used to identify when we have received a string from the pH circuit.

int Data1,Data2,Data3,Data4,Data5,Data6,Data7;

unsigned long startMillis = 0;

String parseIt = 0;
int curPos = 3;
boolean isComma = false;
String tmpWholeStr = 0;
String tmpStr = 0;

void setup(){
     Serial.begin(9600);         //enable the hardware serial port
     myserial1.begin(38400);       //enable the software serial port
     myserial2.begin(38400);       //enable the software serial port
     myserial3.begin(38400);       //enable the software serial port
      }      
void loop(){    
    Serial.println("Looping...");
    
  myserial1.listen();
  
  if(myserial1.available() > 0){        //if we see that the o2 Circuit has sent a character.
     received_from_sensor=myserial1.readBytesUntil(13,o2_data,20); //we read the data sent from o2 Circuit until we see a <CR>. We also count how many character have been received.  
     o2_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the o2 Circuit to let us know that a complete string has been received.
     }
   myserial1.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the o2 Circuit?
     o2=atof(o2_data);                //many people ask us "how do I convert a sting into a float?" This is how...
  int o21 = (int)o2; //Read Altitude digits on the left of the decimal place
  int o22 = (int)((o2 - o21) * 100.0); //Read Altitude digits on the right of the decimal place
    Serial.print("O2 ");
    Serial.print(o21);
    Serial.print(".");
    Serial.println(o22);
    string_received=0;}             //reset the string received flag. 
    
 //    myserial2.listen();
     
  if(myserial2.available() > 0){        //if we see that the pH Circuit has sent a character.
     received_from_sensor=myserial2.readBytesUntil(13,ph_data,20); //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have been received.  
     ph_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
     }
   myserial2.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the ph Circuit?
     ph=atof(ph_data);                //many people ask us "how do I convert a sting into a float?" This is how...
  int ph1 = (int)ph; //Read Altitude digits on the left of the decimal place
  int ph2 = (int)((ph - ph1) * 100.0); //Read Altitude digits on the right of the decimal place
    Serial.print("PH ");
    Serial.print(ph1);
    Serial.print(".");
    Serial.println(ph2);
    string_received=0;}             //reset the string received flag. 
    
//     myserial3.listen();
 
  if(myserial3.available() > 0){        //if we see that the tds Circuit has sent a character.
     received_from_sensor=myserial3.readBytesUntil(13,tds_data,20); //we read the data sent from tds Circuit until we see a <CR>. We also count how many character have been received.  
     tds_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the tds Circuit to let us know that a complete string has been received.
     }
   myserial3.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the tds Circuit?
     tds=atof(tds_data);                //many people ask us "how do I convert a sting into a float?" This is how...
    Serial.print("TDS ");
    Serial.println(tds_data);
    
    {
          parseIt = tds_data;
          curPos = 0;
          isComma = false;
          String tmpWholeStr = 0;
          tmpStr = 0;
          //Sensor01           
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data1 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
//    break;       
          }

          //Serial.println("Sensor03: " + tmpWholeStr);

          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;
          //Sensor03 First Value

          //Sensor03 Second Value            
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data2 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
//    break;       
          }
          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;
          //Sensor03 First Value

          //Sensor03 Second Value            
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data3 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
    break;       
          }


          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;

  }
  Serial.println("TDS: " + String(Data1 + String(',') + Data2 + String(',')+ Data3)); 
    string_received=0;}             //reset the string received flag. 


 delay(800);                         //we will take a reading ever 800ms. You can make this much longer or shorter if you like.     
}

I Fixed the comments, added spacing, and finished the string I'm trying to print at the end. It still has the same problem tho... :frowning:

#include <SoftwareSerial.h>      //we have to include the SoftwareSerial library, or else we can't use it.

SoftwareSerial myserial1(2, 3); //define how the soft serial port is going to work. 
SoftwareSerial myserial2(4, 5); //define how the soft serial port is going to work. 
SoftwareSerial myserial3(6, 7); //define how the soft serial port is going to work. 

char o2_data[20];                  //we make a 20 byte character array to hold incoming data from the o2.                
char ph_data[20];                  //we make a 20 byte character array to hold incoming data from the pH.   
char tds_data[20];                  //we make a 20 byte character array to hold incoming data from the tds.    

byte received_from_o2sensor=0;       //we need to know how many characters have been received.
byte received_from_phsensor=0;       //we need to know how many characters have been received.
byte received_from_tdssensor=0;       //we need to know how many characters have been received.

float o2=0;                        //used to hold a floating point number that is the o2. 
float ph=0;                        //used to hold a floating point number that is the pH. 
float tds=0;                        //used to hold a floating point number that is the tds. 

byte string_received=0;            //used to identify when we have received a string from the pH circuit.

int Data1,Data2,Data3,Data4,Data5,Data6,Data7;

unsigned long startMillis = 0;

String parseIt = 0;
int curPos = 3;
boolean isComma = false;
String tmpWholeStr = 0;
String tmpStr = 0;

void setup(){
     Serial.begin(9600);         //enable the hardware serial port
     myserial1.begin(38400);       //enable the software serial port
     myserial2.begin(38400);       //enable the software serial port
     myserial3.begin(38400);       //enable the software serial port
      }      
void loop(){    
    Serial.println("Looping...");
    
  myserial1.listen();
  
  if(myserial1.available() > 0){        //if we see that the o2 Circuit has sent a character.
     received_from_o2sensor=myserial1.readBytesUntil(13,o2_data,20); //we read the data sent from o2 Circuit until we see a <CR>. We also count how many character have been received.  
     o2_data[received_from_o2sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the o2 Circuit to let us know that a complete string has been received.
     }
   myserial1.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the o2 Circuit?
     o2=atof(o2_data);                //many people ask us "how do I convert a sting into a float?" This is how...
  int o21 = (int)o2;                 //Read o2 digits on the left of the decimal place
  int o22 = (int)((o2 - o21) * 100.0); //Read o2 digits on the right of the decimal place
  
    Data1=o21;
    Data2=o22;
    
    Serial.print("O2 ");
    Serial.print(o21);
    Serial.print(".");
    Serial.println(o22);
    string_received=0;}             //reset the string received flag. 
    
//     myserial2.listen();
     
  if(myserial2.available() > 0){        //if we see that the pH Circuit has sent a character.
     received_from_phsensor=myserial2.readBytesUntil(13,ph_data,20); //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have been received.  
     ph_data[received_from_phsensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
     }
   myserial2.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the ph Circuit?
     ph=atof(ph_data);                //many people ask us "how do I convert a sting into a float?" This is how...
  int ph1 = (int)ph;                    //Read pH digits on the left of the decimal place
  int ph2 = (int)((ph - ph1) * 100.0); //Read pH digits on the right of the decimal place
  
    Data3=ph1;
    Data4=ph2;
    
    Serial.print("PH ");
    Serial.print(ph1);
    Serial.print(".");
    Serial.println(ph2);
    string_received=0;}             //reset the string received flag. 
    
//     myserial3.listen();
 
  if(myserial3.available() > 0){        //if we see that the tds Circuit has sent a character.
     received_from_tdssensor=myserial3.readBytesUntil(13,tds_data,20); //we read the data sent from tds Circuit until we see a <CR>. We also count how many character have been received.  
     tds_data[received_from_tdssensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
     string_received=1;                //a flag used when the Arduino is controlling the tds Circuit to let us know that a complete string has been received.
     }
   myserial3.print("R\r");             //send it the command to take a single reading.
   if(string_received==1){            //did we get data back from the tds Circuit?
     tds=atof(tds_data);                //many people ask us "how do I convert a sting into a float?" This is how...
    Serial.print("TDS ");
    Serial.println(tds_data);
    
    {
          parseIt = tds_data;
          curPos = 0;
          isComma = false;
          String tmpWholeStr = 0;
          tmpStr = 0;
       
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data5 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
 
          }
          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;
         
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data6 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
  
          }
          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;
          
          while(!isComma) {

            tmpStr = String(parseIt.charAt(curPos));

            if (tmpStr == String(',')) {
              Data7 = tmpWholeStr.toInt();
              curPos++; 
              isComma = true;
              continue;
            }

            tmpWholeStr += tmpStr;               
            curPos++;
    break;       
          }


          isComma = false;
          tmpWholeStr = 0;
          tmpStr = 0;

  }
 
    string_received=0;}             //reset the string received flag.
    
 Serial.println("O2/pH/TDS: " + String(Data1 + String(',') + Data2 + String(',')+ Data3 + String(',') + Data4 + String(',')+ Data5 + String(',') + Data6 + String(',')+ Data7)); 

 delay(800);                         //we will take a reading ever 800ms. You can make this much longer or shorter if you like.  
 
}

SoftSerial can only do one thing at a time. It can't even send and receive at the same time.

Can you organize things so that devices can be read one at a time?

If not, one solution would be to use an Arduino Mega which has 4 hardware serial ports.

...R

Basically if I do this.....

  myserial1.listen();
//  myserial2.listen();
//  myserial3.listen();

This...

//  myserial1.listen();
  myserial2.listen();
//  myserial3.listen();

or this...

//  myserial1.listen();
//  myserial2.listen();
  myserial3.listen();

It works fine. But if I do this..

  myserial1.listen();
  myserial2.listen();
//  myserial3.listen();

or this...

  myserial1.listen();
  myserial2.listen();
  myserial3.listen();

It only prints the "looping" and the string at the end with all zeros

I started with this example from here

This is the most complicated sketch ive attempted so far btw. Thanks for any help.

/*
  Software serial multple serial test
 
 Receives from the two software serial ports, 
 sends to the hardware serial port. 
 
 In order to listen on a software port, you call port.listen(). 
 When using two software serial ports, you have to switch ports
 by listen()ing on each one in turn. Pick a logical time to switch
 ports, like the end of an expected transmission, or when the 
 buffer is empty. This example switches ports when there is nothing
 more to read from a port
 
 The circuit: 
 Two devices which communicate serially are needed.
 * First serial device's TX attached to digital pin 2, RX to pin 3
 * Second serial device's TX attached to digital pin 4, RX to pin 5
 
 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts, 
 so only the following can be used for RX: 
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
 
 Not all pins on the Leonardo support change interrupts, 
 so only the following can be used for RX: 
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
 
 created 18 Apr. 2011
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's twoPortRXExample
 
 This example code is in the public domain.
 
 */

#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10,11);

// software serial #2: TX = digital pin 8, RX = digital pin 9
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
SoftwareSerial portTwo(8,9);

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // Start each software serial port
  portOne.begin(9600);
  portTwo.begin(9600);
}

void loop()
{
  // By default, the last intialized port is listening.
  // when you want to listen on a port, explicitly select it:
  portOne.listen();
  Serial.println("Data from port one:");
  // while there is data coming in, read it
  // and send to the hardware serial port:
  while (portOne.available() > 0) {
    char inByte = portOne.read();
    Serial.write(inByte);
  }

  // blank line to separate data from the two ports:
  Serial.println();

  // Now listen on the second port
  portTwo.listen();
  // while there is data coming in, read it
  // and send to the hardware serial port:
  Serial.println("Data from port two:");
  while (portTwo.available() > 0) {
    char inByte = portTwo.read();
    Serial.write(inByte);
  }

  // blank line to separate data from the two ports:
  Serial.println();
}

Is it because im trying to write to the port to get a read but im only able to read?

Robin2:
SoftSerial can only do one thing at a time. It can't even send and receive at the same time.

Can you organize things so that devices can be read one at a time?

If not, one solution would be to use an Arduino Mega which has 4 hardware serial ports.

...R

I actually Started with a mega which worked great but I now need it for another project.
There has to be a way to make this work. I tried using a counter with a switch/case but ran into the same problem.

I tried adding this to setup

void setup(){
  Serial.begin(9600);         //enable the hardware serial port

  myserial1.begin(38400);       //enable the software serial port

  myserial1.print ("\r");
  delay(1);
  myserial1.print ("C\r");      

  myserial2.begin(38400);       //enable the software serial port
 
  myserial2.print ("\r");
  delay(1);
  myserial2.print ("C\r");      

  myserial3.begin(38400);       //enable the software serial port

  myserial3.print ("\r");
  delay(1);
  myserial3.print ("C\r");   
}

And commented out these lines

      myserial1.print("R\r");             //send it the command to take a single reading.
      myserial2.print("R\r");             //send it the command to take a single reading.
      myserial3.print("R\r");             //send it the command to take a single reading.

But it does the exact same thing.....

Well I got it to work by moving some stuff around and commenting out a few things :slight_smile:

#include <SoftwareSerial.h>      //we have to include the SoftwareSerial library, or else we can't use it.  

SoftwareSerial myserial1(2, 3); //define how the soft serial port is going to work. 
SoftwareSerial myserial2(4, 5); //define how the soft serial port is going to work. 
SoftwareSerial myserial3(6, 7); //define how the soft serial port is going to work. 

char tds_data[20];                  //we make a 20 byte character array to hold incoming data from the tds.    
char o2_data[20];                  //we make a 20 byte character array to hold incoming data from the o2.                
char ph_data[20];                  //we make a 20 byte character array to hold incoming data from the pH.   

byte received_from_sensor=0;       //we need to know how many characters have been received.

float o2=0;                        //used to hold a floating point number that is the o2. 
float ph=0;                        //used to hold a floating point number that is the pH. 
float tds=0;                        //used to hold a floating point number that is the tds. 

byte string_received=0;            //used to identify when we have received a string from the pH circuit.

int Data1,Data2,Data3,Data4,Data5,Data6,Data7;

unsigned long startMillis = 0;

String parseIt = 0;
int curPos = 3;
boolean isComma = false;
String tmpWholeStr = 0;
String tmpStr = 0;
uint8_t counter=0;

void setup(){
  Serial.begin(9600);         //enable the hardware serial port
  myserial1.begin(38400);       //enable the software serial port
  myserial2.begin(38400);       //enable the software serial port
  myserial3.begin(38400);       //enable the software serial port
}      
void loop(){    

  switch (counter){  
  case 0:

    myserial1.listen();
    myserial1.print("R\r");             //send it the command to take a single reading.  
 
    //  if(myserial1.available() > 0){        //if we see that the o2 Circuit has sent a character.
 
    received_from_sensor=myserial1.readBytesUntil(13,o2_data,20); //we read the data sent from o2 Circuit until we see a <CR>. We also count how many character have been received.  
    o2_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the o2 Circuit to let us know that a complete string has been received.
 
    //     }

//    myserial1.print("R\r");             //send it the command to take a single reading.  
    
    if(string_received==1){            //did we get data back from the o2 Circuit?
      o2=atof(o2_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      int o21 = (int)o2;                   //Read o2 digits on the left of the decimal place
      int o22 = (int)((o2 - o21) * 100.0); //Read o2 digits on the right of the decimal place
      Serial.print("O2 ");
      Serial.print(o21);
      Serial.print(".");
      Serial.println(o22);
      Data1 = o21;
      Data2 = o22;
      string_received=0;       //reset the string received flag. 
    }            

    break;   

  case 1:
 
    myserial2.listen();
    myserial2.print("R\r");             //send it the command to take a single reading.     
 
    //  if(myserial2.available() > 0){        //if we see that the pH Circuit has sent a character.
 
    received_from_sensor=myserial2.readBytesUntil(13,ph_data,20); //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have been received.  
    ph_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
 
    //     }

//    myserial2.print("R\r");             //send it the command to take a single reading.     

    if(string_received==1){            //did we get data back from the ph Circuit?
      ph=atof(ph_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      int ph1 = (int)ph;                   //Read ph digits on the left of the decimal place
      int ph2 = (int)((ph - ph1) * 100.0); //Read ph digits on the right of the decimal place
      Serial.print("PH ");
      Serial.print(ph1);
      Serial.print(".");
      Serial.println(ph2);
      Data3 = ph1;
      Data4 = ph2;
      string_received=0;
    }             //reset the string received flag. 

    break;

  case 2: 
    myserial3.listen();
    myserial3.print("R\r");             //send it the command to take a single reading.

    //  if(myserial3.available() > 0){        //if we see that the tds Circuit has sent a character.
 
    received_from_sensor=myserial3.readBytesUntil(13,tds_data,20); //we read the data sent from tds Circuit until we see a <CR>. We also count how many character have been received.  
    tds_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the tds Circuit to let us know that a complete string has been received.
 
    //     }
 
    //   myserial3.print("R\r");             //send it the command to take a single reading.
 
    if(string_received==1){            //did we get data back from the tds Circuit?
      tds=atof(tds_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      Serial.print("TDS ");
      Serial.println(tds_data);

      {
        parseIt = tds_data;
        curPos = 0;
        isComma = false;
        String tmpWholeStr = 0;
        tmpStr = 0;

        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data5 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
    
        }

        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
          
        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data6 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
  
        }
 
        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
         
        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data7 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
          break;       
        }
        
        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
 
        break;  
 
      }
 
      string_received=0;      //reset the string received flag. 

    }             

  }
//  Serial.println(counter);
//  Serial.println(millis());
  if ((unsigned long)(millis() - startMillis >= 10000)) {
    Serial.println("O2/pH/Cond/TDS/Sal: " + String(Data1 + String(',') + Data2 + String(',')+ Data3 + String(',') + Data4 + String(',')+ Data5 + String(',') + Data6 + String(',')+ Data7)); 
    startMillis = millis();
 
  }

  counter++;

  if ( counter > 2 ) counter = 0;

  delay(1200);                         //we will take a reading ever 1200ms. You can make this much longer or shorter if you like.     
}

Added a water temp sensor and used it for temp compensation on sensors. :slight_smile:

#include <SoftwareSerial.h>      //we have to include the SoftwareSerial library, or else we can't use it.  
#include <OneWire.h>
#include <DallasTemperature.h>

SoftwareSerial myserial1(2, 3); //define how the soft serial port is going to work. 
SoftwareSerial myserial2(4, 5); //define how the soft serial port is going to work. 
SoftwareSerial myserial3(6, 7); //define how the soft serial port is going to work. 

char tds_data[20];                  //we make a 20 byte character array to hold incoming data from the tds.    
char o2_data[20];                  //we make a 20 byte character array to hold incoming data from the o2.                
char ph_data[20];                  //we make a 20 byte character array to hold incoming data from the pH.   

byte received_from_sensor=0;       //we need to know how many characters have been received.

float o2=0;                        //used to hold a floating point number that is the o2. 
float ph=0;                        //used to hold a floating point number that is the pH. 
float tds=0;                        //used to hold a floating point number that is the tds. 

byte string_received=0;            //used to identify when we have received a string from the pH circuit.

int Data1,Data2,Data3,Data4,Data5,Data6,Data7,Data8,Data9;
int wtemp1 = 0;
unsigned long startMillis = 0;

String parseIt = 0;
int curPos = 3;
boolean isComma = false;
String tmpWholeStr = 0;
String tmpStr = 0;
uint8_t counter=0;

#define ONE_WIRE_BUS A1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Thermometer1 = {0x28, 0x50, 0x6B, 0xB3, 0x05, 0x00, 0x00, 0x7D };

void setup(){
  Serial.begin(9600);         //enable the hardware serial port
  myserial1.begin(38400);       //enable the software serial port
  myserial2.begin(38400);       //enable the software serial port
  myserial3.begin(38400);       //enable the software serial port

  sensors.begin();
  sensors.setResolution(Thermometer1, 10);
  
}      
void loop(){    
  Data8=(sensors.getTempC(Thermometer1));
//  Serial.println(counter);
//  Serial.println(millis());  
  switch (counter)
  {
 

//  Serial.print("\n\r\n\r");

  
    
    case 0:

    myserial1.listen();
    myserial1.print(Data8);             //send it the command to take a single reading.     
    myserial1.print("\r");             //send it the command to take a single reading.  
 
    //  if(myserial1.available() > 0){        //if we see that the o2 Circuit has sent a character.
 
    received_from_sensor=myserial1.readBytesUntil(13,o2_data,20); //we read the data sent from o2 Circuit until we see a <CR>. We also count how many character have been received.  
    o2_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the o2 Circuit to let us know that a complete string has been received.
 
    //     }

//    myserial1.print("R\r");             //send it the command to take a single reading.  
    
    if(string_received==1){            //did we get data back from the o2 Circuit?
      o2=atof(o2_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      int o21 = (int)o2;                   //Read o2 digits on the left of the decimal place
      int o22 = (int)((o2 - o21) * 100.0); //Read o2 digits on the right of the decimal place
      Serial.print("O2 ");
      Serial.print(o21);
      Serial.print(".");
      Serial.println(o22);
      Data1 = o21;
      Data2 = o22;
      string_received=0;       //reset the string received flag. 
    }            

    break;   

  case 1:
 
    myserial2.listen();
    myserial2.print(Data8);             //send it the command to take a single reading.   
    myserial2.print("\r");             //send it the command to take a single reading.     
 
    //  if(myserial2.available() > 0){        //if we see that the pH Circuit has sent a character.
 
    received_from_sensor=myserial2.readBytesUntil(13,ph_data,20); //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have been received.  
    ph_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
 
    //     }

//    myserial2.print("R\r");             //send it the command to take a single reading.     

    if(string_received==1){            //did we get data back from the ph Circuit?
      ph=atof(ph_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      int ph1 = (int)ph;                   //Read ph digits on the left of the decimal place
      int ph2 = (int)((ph - ph1) * 100.0); //Read ph digits on the right of the decimal place
      Serial.print("PH ");
      Serial.print(ph1);
      Serial.print(".");
      Serial.println(ph2);
      Data3 = ph1;
      Data4 = ph2;
      string_received=0;
    }             //reset the string received flag. 

    break;

  case 2: 
    myserial3.listen();
    myserial3.print(Data8);             //send it the command to take a single reading.   
    myserial3.print("\r");             //send it the command to take a single reading.

    //  if(myserial3.available() > 0){        //if we see that the tds Circuit has sent a character.
 
    received_from_sensor=myserial3.readBytesUntil(13,tds_data,20); //we read the data sent from tds Circuit until we see a <CR>. We also count how many character have been received.  
    tds_data[received_from_sensor]=0;  //we add a 0 to the spot in the array just after the last character we received. This will stop us from transmitting incorrect data that may have been left in the buffer. 
    string_received=1;                //a flag used when the Arduino is controlling the tds Circuit to let us know that a complete string has been received.
 
    //     }
 
    //   myserial3.print("R\r");             //send it the command to take a single reading.
 
    if(string_received==1){            //did we get data back from the tds Circuit?
      tds=atof(tds_data);                //many people ask us "how do I convert a sting into a float?" This is how...
      Serial.print("TDS ");
      Serial.println(tds_data);

      {
        parseIt = tds_data;
        curPos = 0;
        isComma = false;
        String tmpWholeStr = 0;
        tmpStr = 0;

        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data5 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
    
        }

        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
          
        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data6 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
  
        }
 
        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
         
        while(!isComma) {

          tmpStr = String(parseIt.charAt(curPos));

          if (tmpStr == String(',')) {
            Data7 = tmpWholeStr.toInt();
            curPos++; 
            isComma = true;
            continue;
          }

          tmpWholeStr += tmpStr;               
          curPos++;
          break;       
        }
        
        isComma = false;
        tmpWholeStr = 0;
        tmpStr = 0;
 
        break;  
 
      }
 
      string_received=0;      //reset the string received flag. 

    }             
    case 3:
     //    {
    sensors.requestTemperatures();  
    Data9 = (DallasTemperature::toFahrenheit(Data8));
  Serial.print("WTmp ");
  Serial.print(Data9);
//  Serial.println(sensors.getTempCByIndex(0)); 
  Serial.println(" F");  
  }

//  Serial.println(counter);
//  Serial.println(millis());  

  if ((unsigned long)(millis() - startMillis >= 10000)) {
    Serial.println("O2/pH/Cond/TDS/Sal/WtmpC/WtmpF: " + String(Data1 + String(',') + Data2 + String(',')+ Data3 + String(',') + Data4 + String(',')+ Data5 + String(',') + Data6 + String(',')+ Data7 + String(',')+ Data8 + String(',')+ Data9)); 
    startMillis = millis();
 
  }

  counter++;

  if ( counter > 3 ) counter = 0;

  delay(1200);                         //we will take a reading ever 1200ms. You can make this much longer or shorter if you like.     
}

larold01:
Basically if I do this.....

  myserial1.listen();

//  myserial2.listen();
//  myserial3.listen();

You have been writing a lot. But the post I have quoted suggests that you have not read my earlier Post.

Lets us know when you have.

...R

SoftwareSerial myserial1(2, 3); //define how the soft serial port is going to work. 
SoftwareSerial myserial2(4, 5); //define how the soft serial port is going to work. 
SoftwareSerial myserial3(6, 7); //define how the soft serial port is going to work.

Seriously, what is a mySerial? You have some REAL device connected to those pins. The instance name should reflect what that real device is, whether it's a GPS, a modem, a pH sensor, or your Uncle Bob.

I predict that you will finding programming a lot easier when you use names that make sense.

Hi larold,

Please send me wiring of your project.