I’m porting a PH sensor over from the Arduino, to the Sparkcore, and having some issues - the Sparkcore isn’t reading any data from the PH sensor over the serial port (I’ve tried monitoring it via USB and via the web app).
My code is as follows;
char ph_data; //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 ph=0; //used to hold a floating point number that is the pH.
float i = 1;
Spark.variable("ph", &ph, INT); Spark.variable("i", &i, INT); Serial.begin(38400); //enable the hardware serial port delay(50); Serial.print("c\r"); //turn the pH Circuit into continues mode. delay(50); //on start up sometimes the first command is missed. Serial.print("c\r"); //so, let’s send it twice. delay(50); //a short delay after the pH Circuit was taken out of continues mode is used to make sure we don’t over load it with commands.
received_from_sensor=Serial.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. Serial.println(ph_data); //transmit that data received from the pH Circuit to the serial monitor. ph=atof(ph_data); // convert a sting into a float i = i + 1; //access this via the web app to test the value is changing delay(380);
Can anyone spot any obvious problems? The PH sensor I’m using is this one - https://www.atlas-scientific.com/product_pages/embedded/ph.html