Pages: [1]   Go Down
Author Topic: pH monitoring with Atlas Scientific pH stamp  (Read 4096 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a hydroponic automation system and I am trying to tackle my first big milestone: reading the pH in the nutrient solution before being able to adjust it.

I am sort of stuck on the code and I know that the sensor data has to be a floating value, but I'm really not sure how to do this... (I also know it has something to do with atof?)

Here is my code so far... any help?

Code:
#include <SoftwareSerial.h>

#define rxph 2
#define txph 3
SoftwareSerial pH (rxph, txph);
float pH_val = 0.0;  // not sure about this
String inputstringPH = "";
String sensorstringPH = "";
boolean input_stringPHcomplete = false;
boolean sensor_stringPHcomplete = false;

void setup(){
Serial.begin(38400);
pH.begin(38400);
inputstringPH.reserve(5);
sensorstringPH.reserve(30);


void serialEvent() {
char incharPH = (char)pH.read();
inputstringPH += incharPH;
if(incharPH == '\r') {input_stringPHcomplete = true;}
}       

 void loop(){
if (input_stringPHcomplete){
   pH.println(inputstringPH);
   inputstringPH = "";
   input_stringPHcomplete = false;

}                 
while (pH.available()) {
char incharPH = (char)pH.read();
sensorstringPH += incharPH;
if (incharPH == '\r') {sensor_stringPHcomplete = true;}

}
 if (sensor_stringPHcomplete){
   Serial.println(sensorstringPH);
   sensorstringPH = "";
   sensor_stringPHcomplete = false;
   }
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14024
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

please post a link to the datasheet.

Do you have 2 sensors attached?

does this minimal sketch work?
Code:
#include <SoftwareSerial.h>

#define rxph 2
#define txph 3

SoftwareSerial pH (rxph, txph);

void setup()
{
  Serial.begin(38400);
  pH.begin(38400);


 void loop()
{
  if (pH.available() >0)
  {
    char incharPH = (char)pH.read();
    Serial.print(incharPH);
  }
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

here is the Datasheet: http://atlas-scientific.com/_files/pH_Circuit_3.0.pdf
yes this seems to work actually smiley-grin, but it is giving me a continuous reading:
3.763.523.493.523.523.583.603.563.583.603.603.583.583.563.523.583.60
I only have 1 sensor attached for now, later I'll be attaching an EC sensor http://atlas-scientific.com/_files/EC_Circuit_2.0.pdf and a temperature sensor to be able to take accurate pH and EC readings.

thanks a lot for the help  smiley-lol
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14024
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

a quick hacl to print one value per line
Code:
int count = 0;

void loop()
{
  if (pH.available() >0)
  {
    char incharPH = (char)pH.read();
    if (inchar =='.') count = 0;
    Serial.print(incharPH);
    count++;
    if (count==3) Serial.println();
  }
}

Give this version a try to see if there is a separator between the readings
Code:
int count = 0;

void loop()
{
  if (pH.available() >0)
  {
    char incharPH = (char)pH.read();
    Serial.print((int) incharPH, DEC);
    Serial.print("\t");
    Serial.println(incharPH);
  }
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

The first one works quite well now, but it continuously spits out the reading every few milliseconds:
6.29
6.59
6.64
6.66
6.66
...


The second one gives me this:
54   6
46   .
51   3
49   1
13   

54   6
46   .
...


I saw on the datasheet that the sensor could be calibrated using one of the various commands.
The solution I am testing the probe in is a pH 7.00 (@25C  +/- 0.02) and the readout I am getting is only 6.66 ( it goes up to 12 when I test with pH 10).
I tried using the serial monitor to input these commands, but nothing happened...

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14024
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The second one shows that you can synchronize on the char 13 (which is a newline)

now using double buffering -something like this. data is collected in val array and if full it is copied for use into buffer.
Code:
unsigned long lastTime = 0;

int count = 0;
char val[6];
char buffer[6];

void setup()
{
  Serial.begin(....);
  lastTime = millis();
}

void loop()
{
  if (pH.available() >0)
  {
    char incharPH = (char)pH.read();
    if (inharPH == 13)
    {
      val[count] = 0;
      count = 0;
      strcpy(buffer, val);
    }
    val[count] = inCharPH;
  }

  if (millis() -1000 > lastTime)
  {
    Serial.println(buffer);
    lastTime += 1000;
  }

   // rest of code
}

Quote
I saw on the datasheet that the sensor could be calibrated using one of the various commands.
No time to dive into that now, sorry ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No problem, this is already a lot of help. thanks so much smiley
I'm going to try to get the same logic to work on the EC stamp
Logged

Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This board has a continuous and on demand mode.  Send it an "E" command to terminate continuous. Send it a "C" command to get a value periodically say every 10 seconds. Calibration has to be performed with a 7 and 4 or 7 and 10 standard. Do the 7 first as this fixes the intercept then do 4 as this fixes the slope.

You may also want to consider using analog ports rather than serial when you have more than one sensor (pH and EC). These are some options.

http://webpages.charter.net/tdsmeter/

http://www.phidgets.com/products.php?category=6&product_id=1130_0

You could add a temp sensor on yet a another analog port but the accuracy required for hydro use may not justify it unless you will be controlling envrionmental equipment.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi pjsquared,

I moved the conversation to here:
http://arduino.cc/forum/index.php/topic,98850.0.html

Quote
This board has a continuous and on demand mode.  Send it an "E" command to terminate continuous. Send it a "C" command to get a value periodically say every 10 seconds. Calibration has to be performed with a 7 and 4 or 7 and 10 standard. Do the 7 first as this fixes the intercept then do 4 as this fixes the slope.

I have been trying to communicate with the board by typing the commands in the serial monitor but so far nothing...
I don't know how I did it, but a few days ago, I managed to switch off the LED (on datasheet is says to enter L0 to turn off the LEDs and L1 to turn them back on), but I still cannot manage to either turn the LED on, or reset the board.

the only way I can get a read is by resetting the arduino and unplugging/ replugging the GND on the stamp
Logged

Pages: [1]   Go Up
Jump to: