Hi there,
Im doing the exact same thing as aekhalil using both the same sensors with the provided code as aelkhalil posted but I too am having issues converting the strings into floats which I can use to compare against a set value.
For the pH sensor I understand I need to use the atof function however I get the error : cannot convert 'String' to 'const char*' for argument '1' to 'double atof(const char*)' if I simply add:
if (sensorPH_stringcomplete) //if a string from the Atlas Scientific product has been received in its entirety
{
Serial.println(sensorstringPH); //use the hardware serial port to send that data to the PC
sensorstringPH = ""; //clear the string: //show this
sensorPH_stringcomplete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
pH_reading = atof(sensorstringPH);
Serial.println(pH_reading);
}
}
For the EC probe the output is a string consisting of three comma seperated values (5000, 32800, 32.7). I only want use the first value in this instance and realise I need to split the string using strtok? This is the code I am using for a basis and it does as I wish:
#include <string.h>
char sz[] = "Here; is some; sample;100;data;1.414;1020";
void setup()
{
char *p = sz;
char *str;
Serial.begin(9600);
while ((str = strtok_r(p, ";", &p)) != NULL) // delimiter is the semicolon
Serial.println(str);
}
void loop(){}
I have inserted into this part of my EC code which is similar to posted above:
if (sensorEC_stringcomplete) //if a string from the Atlas Scientific product has been received in its entirety
{
// Serial.println(sensorstringEC); //use the hardware serial port to send that data to the PC
char *str;
while ((str = strtok_r(sensorstringEC, ",", &sensorstringEC)) != NULL) // delimiter is the semicolon
Serial.println(str);
sensorstringEC = ""; //clear the string: //show this
sensorEC_stringcomplete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
}
but retrieve the error: 'String' to 'char*' for argument '1' to 'char* strtok_r(char*, const char*, char**)'
I haven't done anything like this in coding before, could someone please clarify whats going on.
Thanks