Multiplexing Atlas Scientific pH and temperature sensors

Hello,

I have an Arduino Uno and two Atlas Scientific sensors (pH and temperature). I am attempting to display pH and temperature readings on the serial monitor of the Arduino from the same Arduino code. I have successfully printed data from the pH and temperature sensors independently of one another, but for some reason when I tried to combine the codes only pH data outputs upon the serial monitor. I am new to Arduino and Atlas Scientific products. Any advice would be much appreciated!

Test.ino (7.77 KB)

#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2                                          //define what pin rx is going to be
#define tx 3                                          //define what pin tx is going to be
#define rx1 8
#define tx1 9

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work
SoftwareSerial myserial1(rx1, tx1);                      //define how the soft serial port is going to work


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
String sensorstring1 = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product
boolean sensor_string_complete1 = false;               //have we received all the data from the Atlas Scientific product
float temperature;                                    //used to hold a floating point number that is the RTD temperature
float pH;

//long period = 120000;
//long period = 1800000;
//long period = 2700000;                                                                                                                                                                                                                                                                                                                            
//long period = 3600000;
//unsigned long time_now = 0; 
//unsigned long time_now1 = 60000;



void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  myserial1.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
  sensorstring1.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 receives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC
}


void loop() {                                         //here we go...

  if (input_string_complete) {                        //if a string from the PC has been received in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just received
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {                 //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println(sensorstring);
    //if(millis() > time_now + period){
      //time_now = millis();
      //Serial.println(sensorstring);
    //}
//    Serial.println(sensorstring);                       //send that string to the PC's serial monitor
//    if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit
//      temperature = sensorstring.toFloat();           //convert the string to a floating point number so it can be evaluated by the Arduino
//      if (temperature >= 25.0) {                      //if the RTD temperature is greater than or equal to 25 C
//        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the RTD temperature as a number and not as a string
//      }
//      if (temperature <= 24.999) {                    //if the RTD temperature is less than or equal to 24.999 C
//        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the RTD temperature as a number and not as a string
//      }
//    }
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }

  if (myserial1.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar1 = (char)myserial1.read();              //get the char we just received
    sensorstring1 += inchar1;                           //add the char to the var called sensorstring
    if (inchar1 == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete1 = true;                  //set the flag
    }
  }


  if (sensor_string_complete1 == true) {               //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println(sensorstring1);                     //send that string to the PC's serial monitor
    //if(millis() > time_now1+ period){
      //time_now1 = millis();
      //Serial.println(sensorstring1);
    //}
    /*                                                //uncomment this section to see how to convert the pH reading from a string to a float 
    if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit
      pH = sensorstring.toFloat();                    //convert the string to a floating point number so it can be evaluated by the Arduino
      if (pH >= 7.0) {                                //if the pH is greater than or equal to 7.0
        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
      }
      if (pH <= 6.999) {                              //if the pH is less than or equal to 6.999
        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
      }
    }
    */
    sensorstring1 = "";                                //clear the string
    sensor_string_complete1 = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }
}

Hi @Delta_G,

the parts of the code relating to temperature that are commented out just prevent the printing of "high" or "low" if the temperature is above or below a certain threshold.

I was hoping to see both temperature and pH values output upon the serial monitor. From my research I believe this is possible, although I am not sure how to go about doing so in the Arduino code.