Go Down

Topic: Atlas Scientific pH Stamp Issue (Read 2 times) previous topic - next topic

Dreniann

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.

Code: [Select]
#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.

Code: [Select]
#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                <------- <CR>
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 <CR> 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.

Code: [Select]
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

AWOL

Is software serial rated to 38.4k?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dreniann

Quote
Is software serial rated to 38.4k?


I'm pretty sure it is, from Arduino library reference:
Quote
It is possible to have multiple software serial ports with speeds up to 115200 bps.

h4ckler

Code: [Select]


#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 :)

h4ckler

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

Go Up