Since this is my first post, and being rather "new" on Arduino, I thought lets make it a contributing first post
I have read through tens of posts in various fora to find a way to get the PH value, spitted out by the serial PH stamp, into a float for further manipulation. Most important for me was to get it simply to an LCD.
Info on the PH stamp you can find http://atlas-scientific.com/product_pages/embedded/ph.html
All related posts use some sort of string etc, a lot of code which in my case either didn't work (my inexperience) or was way too complex and memory hogging. Trying all sorts of code, and digging in the Arduino reference pages I stumbled upon a function that did exactly what I needed: simply transferring the ASCII characters into a float value.... serial.parseFloat()
Take a look at the code below (just a piece out of my total code for a Reef Controller).
What I only needed was the value itself.
Tested it, and works so far without visible side effects afaik
// -------------------------------------------------------------------------------
//
// Simple way to get Atlas Scientific serial PH stamp value to LCD or PC
// Author: Eric van Riet - The Netherlands
//
// ONLY THE PART FOR PH IS LISTED!**
// ASSUMED THAT OTHER LIBRARIES FOR LCD ETC ARE IN YOUR OWN CODE!!// -------------------------Set measurement interval------------------------------
long phReadInterval = 1000;
long previousMillisPH = 0;
int PHState = HIGH;
// -------------------------------------------------------------------------------// ---------------Variable to hold PH value---------------------------------------
float PH_Val;
// -------------------------------------------------------------------------------void setup()
{
Serial.begin(38400); // Set baudrate for hardware serial port 0 (PC)
Serial1.begin(38400); // Set baudrate serial port 1 to 38400 (PH)
lcd.begin (20,4); // initialize the lcd// -------------Get PH value from Atlas Scientific PH serial stamp----------------
void getPHvalue() { //get PH every interval (1000 ms)
unsigned long currentMillisPH = millis();if(currentMillisPH - previousMillisPH > phReadInterval) {
previousMillisPH = currentMillisPH;
if (PHState == HIGH) {
PHState = LOW;
}
else {
PHState = HIGH;
Serial1.print("r\r");
while (Serial1.available() > 0) {
// Serial1.parseFloat looks for the next valid float number
// in the serial stream. In this case on hardware serial 1
PH_Val = Serial1.parseFloat();
// look for the carriage return. That's the end of your sentence:
if (Serial1.read() == '\r') {
Serial.println(PH_Val); // can be used for debug, pc display etc.
}
}
}
}
}
// -------------------------------------------------------------------------------void loop()
{
getPHvalue();lcd.setCursor(0,1);
lcd.print("PH value: ");
lcd.print(PH_Val);}
I trust somebody else can find use for this.