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