pH/ORP stamp Atlas scientific

Whenever I see code like this, I cringe. If you know how much data you are expecting to send or receive, use a fixed size char array, not the overhead of a String.

so do you mean I should do something more like this code?

}
void loop(void)
{

char inData_ORP[12];
char string_ORP[8];

this snippet comes from this code I found online:

#include <NewSoftSerial.h>

NewSoftSerial LCD(2, 3); // LCD
NewSoftSerial ORP(4, 5); // ORP stamp
NewSoftSerial pH(6, 7);

int ORP_val = 0;
float pH_val = 0.0;

void setup()
{
Serial.begin(9600);
LCD.begin(9600); // LCD
ORP.begin(9600); // ORP stamp
pH.begin(9600); // pH stamp

LCD.print("?f");
LCD.print("?c0");

}

void loop(void)
{

char inData_ORP[12];
char string_ORP[8];

ORP.println("read()c");
delay(750);


if (ORP.available() > 0)
{
for (int i=0;i<13;i++) {
inData_ORP[i] = char(ORP.read());
}
}
sscanf(inData_ORP, "%*s %s ", string_ORP);
ORP.flush();
if (atoi(string_ORP) != 0) {
ORP_val = atoi(string_ORP);
}

Serial.print("Sensor output: [");
Serial.print(inData_ORP);
Serial.println("]");
LCD.print("?y2");
LCD.print("?x00");
LCD.print("ORP value: ");
LCD.println(ORP_val);

char inData_pH[12];
char string_pH[8];

pH.println("read(26.5)c");
delay(750);

if (pH.available() > 0)
{
for (int i=0;i<13;i++) {
inData_pH[i] = char(pH.read());
}
}
sscanf(inData_pH, "%*3c%s ", string_pH);
pH.flush();
if (atoi(string_pH) != 0) {
pH_val = atof(string_pH);
}

Serial.print("Sensor output: [");
Serial.print(inData_pH);
Serial.println("]");
LCD.print("?y0");
LCD.print("?x00");
LCD.print("pH value: ");
LCD.println(pH_val);

}

Unfortunately, this code prints out for the pH value something like this: [3.863.863.8] and spits out from time to time random characters during the readout on the serial monitor...

I don't see inch defined anywhere. It seems to be that you only want to convert the float to a value when the end of the string is encountered, not every time this function is called.

My bad, I pasted the wrong code... that was me trying to play around with atof (obvious failure there...)
here is the original code provided by Atlas Scientific

#include <SoftwareSerial.h>  //add the soft serial libray

#define rxpin 2 //set the RX pin to pin 2
#define txpin 3 //set the TX pin to pin 3


SoftwareSerial myserial (rxpin, txpin); //enable the soft serial port
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_stringcomplete = false; //have we received all the data from the PC
boolean sensor_stringcomplete = false; //have we received all the data from the Atlas Scientific 
//product

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

void serialEvent() { //if the hardware serial port receives a char
char inchar = (char)Serial.read(); //get the char we just received
inputstring += inchar; //add it to the inputString
if(inchar == '\r') {input_stringcomplete = true;} //if the incoming character is a <CR>, set the flag
}       

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

if (input_stringcomplete){ //if a string from the PC has been recived in its entiery
   myserial.print(inputstring); //send that string to the Atlas Scientific product
   inputstring = ""; //clear the string:
   input_stringcomplete = false; //reset the flage used to tell if we have recived a comp[lete string from the PC
}                 

while (myserial.available()) { //while a char is holding in the serial buffer
char inchar = (char)myserial.read(); //get the new char
sensorstring += inchar; //add it to the sensorstring
if (inchar == '\r') {sensor_stringcomplete = true;} //if the incoming character is a <CR>, set the flag

}
 if (sensor_stringcomplete){ //if a string from the Atlas Scientific product has been received in its entirety
   Serial.print(sensorstring); //use the hardware serial port to send that data to the PC
   sensorstring = ""; //clear the string:
   sensor_stringcomplete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product

   }

}

It is not clear what is sending data to the hardware serial port and what is sending data to the software serial port.

Honestly, I am completely lost... I have been reading books about arduino, but the ones at my level of understanding don't get even close to this kind of code...

I m just good at blinking LEDs in many ways :stuck_out_tongue: