Atlas Scientific pH Stamp Issue

Hello:
I got into Arduino programming about 5 months ago for undergrad research. I recently bought an Atlas Scientific pH Stamp for my project. I am using a Seeeduino Stalker v2.1 board. I have spent the past couple of weeks trying to solve a problem with my readings but have yet to succeed.

My connections are as follows:
Board ------> Stamp
pin 2 -----> TX
pin 3 ------> RX
GND ------> GND
USB5V -----> VCC

I have written the following code to take readings and have added some lines to figure out the problem.

#include <SoftwareSerial.h>            

SoftwareSerial pH =  SoftwareSerial(2, 3);  //setup and rename soft uart.
//                                  RX|TX
char stamp_data[15];      //reserve 15 bytes
byte holding;             //define holding
byte i;                    //define for loop
float ph_out = 0.00;          //set float

void setup(){
pH.begin(38400);        //open pH comms
Serial.begin(38400);    //open serial comms
}

void loop() {
  
pH.print("r");          //tell stamp to take single reading
pH.print((char)13);      //end in <CR>
delay(1000);

pH.listen();                    //listen to pH port
while(pH.available() > 3) {    // wait until greater than 3 bytes
holding=pH.available();      //hold pH stamp info
  
  for(i=0; i <= holding;i++){  //assemble stamp data
    stamp_data[i]= pH.read();
  }
}
stamp_data[holding]='\0';
Serial.print("stamp_data: ");   //print data type (added line)
Serial.println(stamp_data);    //print stamp data (added line)

ph_out=atof(stamp_data);
Serial.print("ph_out: ");  //print data type
Serial.println(ph_out);    //print ph float
delay(5000);
}

From the above code I get the following on the serial monitor. As you can see the issue is this random appearance of a letter in the tenths or hundredths place. The correct reading should be 3.39 as it reads when using terminal.

stamp_data: 3.3y
ph_out: 3.30
stamp_data: 3.3y
ph_out: 3.30
stamp_data: 3.c9
ph_out: 3.00
stamp_data: 3.3y
ph_out: 3.30
stamp_data: 3.c9
ph_out: 3.00
stamp_data: 3.3y
ph_out: 3.30
stamp_data: 3.3y
ph_out: 3.30
stamp_data: 3.c9
ph_out: 3.00

I sat down with my professor for a lengthy time to try and solve this. We wrote the following simple code to see what was going on and found it is not a for loop error.

#include <SoftwareSerial.h>            

SoftwareSerial pH =  SoftwareSerial(2, 3);  //setup and rename soft uart.
//                                  RX|TX


void setup(){
pH.begin(38400);        //open pH comms
Serial.begin(38400);    //open serial comms
}

void loop() {
  
pH.print("r");          //tell stamp to take single reading
pH.print((char)13);      //end in <CR>
delay(1000);

int inByte = 0;

if(pH.available() > 3) {    // if greater than 3 bytes execute
    Serial.print("pH_available: ");
    Serial.println(pH.available());
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
}
pH.flush();
delay(5000);
}

The above code shows the following on the serial monitor. It is printing char in decimal form and you can see that random letter still appears.
pH_available: 5
51 <------- number
46 <------- decimal point
51 <------- number
121 <------- letter
13 <-------
pH_available: 5
51
46
99
57
13
pH_available: 5
51
46
99
57
13

I got in touch with Atlas Scientific as I thought something was wrong with the stamp. I was told to run this very simple code with the serial monitor set as and 38400 baud rate. I was able to give the probe command and receive data correctly. They told me the stamp is functioning and to seek help here.

void setup(){
}
void loop(){
}

With this code I hook up RX0 (board) to RX(stamp) and TX0 (board) to TX (stamp). Of course connecting VCC and GND also.

Links:
pH stamp data sheet: http://atlas-scientific.com/_files/pH_Circuit_3.0.pdf
Seeeduino Stalker v2.1: http://seeedstudio.com/wiki/Seeeduino_Stalker_v2.1

I would appreciate any help.

Thanks
Brett

Is software serial rated to 38.4k?

Is software serial rated to 38.4k?

I'm pretty sure it is, from Arduino library reference:

It is possible to have multiple software serial ports with speeds up to 115200 bps.

#include <SoftwareSerial.h>            

SoftwareSerial pH =  SoftwareSerial(2, 3);  //setup and rename soft uart.
//                                  RX|TX


void setup(){
pH.begin(38400);        //open pH comms
Serial.begin(38400);    //open serial comms
}

void loop() {
  
pH.print("c");
pH.print("s");
pH.print((char)13);
delay(1000);
  
char inByte = '0';

while(pH.available() > 0)
{
    Serial.print("pH_available: ");
    Serial.println(pH.available());
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
}
}

I got it to work with this code, the random numbers its pulling are referring to ASCII dec. I'm way noob though, so I don't know exactly why you have it reading each byte like that. I feel like something else might be better there... but like I said I'm very noob.

I also changed the If{} to a while{} which from my understanding is a newer way of doing this supported by v1.0. I'm here to learn too :slight_smile:

Also this is what its giving me, I'm not sure what the 10 that comes out of the results every 3-4 readings. I'd like to know what that is.

pH_available: 5
6
.
5
8

pH_available: 5
6
.
5
8

pH_available: 10
6
.
5
8

while(pH.available() > 0)
{
    Serial.print("pH_available: ");
    Serial.println(pH.available());
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);
    inByte = pH.read();
    Serial.println(inByte);

Here, you check to see if there is at least one character to read, then you go ahead and read five of them.
The only thing that is allowing this to work is the delay introduced by the intervening "println"s.
I suggest either checking "available" before every "read", or checking to see if "available" = >= the number of characters you expect.

Thanks for the reply and some clarification as to what is going on AWOL, are you aware of any articles or what subject matter I should be looking at to make all this make more sense to me?

What I vaguely think I should do is check for the amount of Bytes and then use a counter to process all of them and combine them into 1 variable so I can output the pH to an LCD or serial monitor... I can't stress how new all of this is to me. This is a long stride from making a LED blink. :smiley:

i got it running
#include <SoftwareSerial.h>

SoftwareSerial pH = SoftwareSerial(2, 3); //setup and rename soft uart.
// RX|TX
char stamp_data[15]; //reserve 15 bytes
byte holding; //define holding
byte i; //define for loop
float ph_out = 0.00; //set float

void setup(){
pH.begin(38400); //open pH comms
Serial.begin(38400); //open serial comms
}

void loop() {

pH.print("r"); //tell stamp to take single reading
pH.print((char)13); //end in
delay(1000);

pH.listen(); //listen to pH port
while(pH.available() > 3) { // wait until greater than 3 bytes
holding=pH.available(); //hold pH stamp info

for(i=0; i <= holding;i++){ //assemble stamp data
stamp_data*= pH.read();*

  • }*
    }
    stamp_data[holding]='\0';
    Serial.print("stamp_data: "); //print data type (added line)
    Serial.println(stamp_data); //print stamp data (added line)
    ph_out=atof(stamp_data);
    Serial.print("ph_out: "); //print data type
    Serial.println(ph_out); //print ph float
    delay(5000);
    }
    but how do i display the pH values on LCD?

You haven't defined an LCD object.

Please use code tags when posting code - I don't imagine your source had italics in it.

The code tags are done with the # button just above the smileys ...

but how do i display the pH values on LCD?

There is an example here - LiquidCrystal - Arduino Reference - it is not difficult to merge with your sketch.

You might need one of the other functions of the LCD lib - LiquidCrystal - Arduino Reference -