Create Rx Tx

Hello! I created a TX and an RX with SoftwareSerial. Now I explain my project a little bit. It consists of a pH meter and a thermocouple. The thermocouple is type K and is connected to an Adafruit MAX 31856 plate, which in turn goes to the Arduino NANO to ports 13,12,11,10. Until there everything is correct and reads without problem. Now the story comes. The pH meter is connected to an EZO board (it is the brand) and has an RX and TX output, which goes to the Arduino to its respective RX TX. The story is that I have created the Rx Tx and I have assigned it the D6 and D7. I have called it Serial3, and I want it to read and send what it has read through that port and show it to me on the screen. And when I simulate I can not read the value well. I leave the code to see if you can help me out. Thank you very much to everyone in advance.

#include <Adafruit_MAX31856.h>
#include <SoftwareSerial.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
String termoparstring_A = "";
String sensorstring = "";
String inputstring = "";   
#define rxPin 7
#define txPin 6
SoftwareSerial Serial3 (rxPin,txPin);         
boolean input_string_complete = false;                
boolean sensor_string_complete = false;  
                                                       
void setup() {                                        
  Serial.begin(9600);     
                              
          pinMode(rxPin,INPUT);
          pinMode(txPin,OUTPUT);
         
         Serial3.begin(9600);
        inputstring.reserve(30);                            
        sensorstring.reserve(60); 
        max_A.begin();
        max_A.setThermocoupleType(MAX31856_TCTYPE_K);

}   
void serialEvent() {                                  
  inputstring = Serial.readStringUntil(13);          
  input_string_complete = true;                             
                                                    
}
void serialEvent3(){
  Serial3.listen();  
   while (Serial3.available() > 0) {
    char sensorstring = Serial3.read();
    sensor_string_complete = true; 
  }

}       
void loop() {                                         
termoparstring_A =(max_A.readThermocoupleTemperature());
sensorstring = Serial3.read();                                      
           
    Serial.println(termoparstring_A);
    Serial.println(sensorstring);
    delay(500); 
                                                                              
  sensorstring = "";                          
  sensor_string_complete = false;

}

Please provide a link to the EZO. If it uses RS232 signal levels, you need something like a MAX232.

Is 9600 the correct baudrate for the EZO?

Software serial and serial event do not work together. Serial event is just for the hardware Serial (pins 0 and 1). Just use Serial3.available() in loop. See this post.. Or this post.

sterretje:
Please provide a link to the EZO. If it uses RS232 signal levels, you need something like a MAX232.

Is 9600 the correct baudrate for the EZO?

groundFungus:
Software serial and serial event do not work together. Serial event is just for the hardware Serial (pins 0 and 1). Just use Serial3.available() in loop. See this post.. Or this post.

I have modified the code so and now the temperature value appears on the screen, and in the pH it gives -1.

#include <Adafruit_MAX31856.h>
#include <SoftwareSerial.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
String termoparstring_A = "";
String sensorstring = "";
String inputstring = "";   
#define rxPin 7
#define txPin 6
SoftwareSerial Serial3 (rxPin,txPin);         
boolean input_string_complete = false;                
boolean sensor_string_complete = false;  
                                                       
void setup() {                                        
  Serial.begin(9600);     
                              
          pinMode(rxPin,INPUT);
          pinMode(txPin,OUTPUT);
         
         Serial3.begin(9600);
        inputstring.reserve(30);                            
        sensorstring.reserve(60); 
        max_A.begin();
        max_A.setThermocoupleType(MAX31856_TCTYPE_K);

}   

void loop() {                                         
termoparstring_A =(max_A.readThermocoupleTemperature());
Serial3.listen();  
   while (Serial3.available() > 0) {
    char sensorstring = Serial3.read();
   }
    sensor_string_complete = true; 
    sensorstring = Serial3.read();                                      
           
    Serial.println(termoparstring_A);
    Serial.println(sensorstring);
    delay(500); 
                                                                              
  sensorstring = "";                          
  sensor_string_complete = false;

}
char sensorstring = Serial3.read();

The read function returns 1 character, not a whole String. Since you are using String (objects) the readString() or readStringUntil() functions would be better.

Better yet, don't use Strings. Strings can lead to memory problems if misused. The serial input basics thread shows how to read data from a serial port using null terminated character arrays and is non blocking.

I think that you are trying to adapt the sample code from this page. Is that correct?

With the change now I get blank when I have to show the pH value. The temperature shows it.
How would it be like you say? Sorry but I’m a novice in the Arduino world.
Yes, I’m trying to adapt. With an Arduino Mega for example it does work (several Serial ports) but I need to do it with an Arduino Nano and that is where I am finding all these problems.

#include <Adafruit_MAX31856.h>
#include <SoftwareSerial.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
String termoparstring_A = "";
String sensorstring = "";
String inputstring = "";   
#define rxPin 7
#define txPin 6
SoftwareSerial Serial3 (rxPin,txPin);         
boolean input_string_complete = false;                
boolean sensor_string_complete = false;  
                                                       
void setup() {                                        
  Serial.begin(9600);     
                              
          pinMode(rxPin,INPUT);
          pinMode(txPin,OUTPUT);
         
         Serial3.begin(9600);
        inputstring.reserve(30);                            
        sensorstring.reserve(60); 
        max_A.begin();
        max_A.setThermocoupleType(MAX31856_TCTYPE_K);

}   

void loop() {                                         
termoparstring_A =(max_A.readThermocoupleTemperature());
Serial3.available(); 
Serial3.listen();  
   while (Serial3.available() > 0) {
   sensorstring = Serial3.readStringUntil(13);
   }
    sensor_string_complete = true; 
                                      
    Serial.println(termoparstring_A);
    Serial.println(sensorstring);
    delay(500); 
                                                                              
  sensorstring = "";                          
  sensor_string_complete = false;

}

Have you tried the PH example code (below) by itself and unmodified (except RX & TX pins)? Does it work?
Note that I change the RX and TX pins to the ones in your code (RX=7, TX=6).

//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the pH circuit.
//This code was written in the Arduino 1.8.3 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 6/2017


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 7                                          //define what pin rx is going to be
#define tx 6                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //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
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
float pH;                                             //used to hold a floating point number that is the pH



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
  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
}


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);                     //send that string to the PC's serial monitor
    /*                                                //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
      }
    }
    */
    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
  }
}

groundFungus:
Have you tried the PH example code (below) by itself and unmodified (except RX & TX pins)? Does it work?
Note that I change the RX and TX pins to the ones in your code (RX=7, TX=6).

//This code was written to be easy to understand.

//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the pH circuit.
//This code was written in the Arduino 1.8.3 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 6/2017

#include <SoftwareSerial.h>                          //we have to include the SoftwareSerial library, or else we can’t use it
#define rx 7                                          //define what pin rx is going to be
#define tx 6                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //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
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
float pH;                                            //used to hold a floating point number that is the pH

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
  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
}

void serialEvent() {                                  //if the hardware serial port_0 receives a char
  inputstring = Serial.readStringUntil(13);          //read the string until we see a
  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 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
      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);                    //send that string to the PC’s serial monitor
    /*                                                //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
      }
    }
    */
    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
  }
}

I tried it, but it doesn´t work

The example says it was tested, successfully, on an Uno so should work on a Nano.

Do you get anything on get serial monitor?

Are you sure of your wiring? Module RX to pin 6, module TX to pin 7?
Can you post a clear photo showing the wiring? How to post an image.

LOL,I changed the pins by 3.2 and it works!!!
Now I need to add another pH meter. Any advice?

#include <Adafruit_MAX31856.h>
#include <SoftwareSerial.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
String termoparstring_A = "";
String sensorstring = "";
String inputstring = "";   
#define rxPin 3
#define txPin 2
SoftwareSerial Serial3 (rxPin,txPin);         
boolean input_string_complete = false;                
boolean sensor_string_complete = false;  
                                                       
void setup() {                                        
  Serial.begin(9600);     
                              
          pinMode(rxPin,INPUT);
          pinMode(txPin,OUTPUT);
         
         Serial3.begin(9600);
        inputstring.reserve(30);                            
        sensorstring.reserve(60); 
        max_A.begin();
        max_A.setThermocoupleType(MAX31856_TCTYPE_K);

}   

void loop() {                                         
termoparstring_A =(max_A.readThermocoupleTemperature());
Serial3.available(); 
Serial3.listen();  
   while (Serial3.available() > 0) {
   sensorstring = Serial3.readStringUntil(13);
   }
    sensor_string_complete = true; 
                                      
    Serial.println(termoparstring_A);
    Serial.println(sensorstring);
    delay(500); 
                                                                              
  sensorstring = "";                          
  sensor_string_complete = false;

}

Miniunder:
LOL,I changed the pins by 3.2 and it works!!!!!
Now I need to add another pH meter. Any advice?

you can add a 2nd sensor using the I2C mode.

Can I use the serial port that comes with Arduino Nano to connect one of the pH meters? RX0 TX1 ??

connect one of the pH meters? RX0 TX1 ??

Not and have the use of the serial monitor and easy code upload. I would put both on the I2C bus. You asked, originally, about the serial port so I didn't consider I2C. The addresses are settable so you can give each a different address. There is an I2C example on the Atlas site. Page 58 of the data sheet shows how to set the address. Learning how to use I2C is not as easy as serial, but so many things use I2C it really is worth the effort.