Pages: 1 [2]   Go Down
Author Topic: Atlas scientific ph/orp stamp RS232  (Read 6264 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50883
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
delay(1000);
  mySerial.print("l0");           //the command "c" will tell the stamp to take continues readings
  mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")
The delay is unnecessary. The probe has no way of knowing that you want to talk to it until you talk to it. So start talking right away.

It's nice that your comments match the code... Makes it real easy to understand what "l0" (or "r") does.

Code:
if(mySerial.available() > 0) {        //if we see the more than three bytes have been received by the Arduino
The code and comments again do not agree. You are doing something if 1 or more bytes of data are available to read, not 3.

Quote
    Serial.print(stamp_data);             //printing each byte we received  through the hardware UART
The Serial.print() method that takes a character array as an argument expects that the array will be NULL terminated. Yours is not, which explains the garbage that you are seeing.

Add a NULL after each valid character is added.
Quote
    for(i=1; i <= holding;i++)
    {
        stamp_data= mySerial.read();
        stamp_data[i+1] = '\0'; // <== add this line
    }

Code:
    mySerial.flush(); 
You asked the device for data, and you are randomly throwing away some of the data that it returns. OK. Works for me.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you soo much Paul

I am still getting junk, the thing is that is it always in the same spot i.e

on continuous mode (i.e 

Code:
mySerial.print("18");           //the command "c" will tell the stamp to take continues readings
 mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")

serial output:

7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.94   =====> hehehe strange! I got a nice reading here, it happends every 50 reeading or so, randomly
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4
7.y4

if i take probe out:

chÅck àroÂe
chÅck@proÂe
chÅck@prÏbe
chÅck àroÂe
chÅck àroÂe
chÅck àroÂe
chÅck@proÂe
chÅck@proÂe
chÅck@prßbe

My code is as per you suggestions

Code:
#include <NewSoftSerial.h>               //this will let the software take advantage of the "newsoftserial" library.                   

NewSoftSerial mySerial =  NewSoftSerial(6, 7);

char stamp_data[15];         
//this is where the data from the stamp is stored. The array is 15 char long because
//if no pH probe is connected, the message "check probe" is transmitted.
 //Having an array that is too small will cause data corruption and could cause the Arduino to crash.
byte holding;                       
//used to tell us the number of bytes that have been received by the Arduino and are
//holding in the buffer holding
byte i;                 


void setup()

{
  mySerial.begin(38400);   
  Serial.begin(57600); 
  delay(1000);
  mySerial.print("l0");           //the command "c" will tell the stamp to take continues readings
  mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")
 delay(1000);
  mySerial.print("c");           //the command "c" will tell the stamp to take continues readings
  mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")
 
}
         
void loop() {                                          //main loop

 if(mySerial.available() > 0) {                   //if we see the more than three bytes have been received by the Arduino

    holding=mySerial.available();              //lets read how many bytes have been received
    for(i=1; i <= holding;i++){                    //we make a loop that will read each byte we received
        stamp_data[i]= mySerial.read();     //and load that byte into the stamp_data array
        stamp_data[i+1] = '\0';                   // <== add this line
    }

    for(i=1; i <= holding;i++){                  //we now loop through the array       
    Serial.print(stamp_data[i]);             //printing each byte we received  through the hardware UART
       }

       Serial.println("");                         //once we finished, we print a null char with the <CR><LF> command.
    mySerial.flush(); 
    }
}


Any ideas Mate
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant

mySerial.print("c");

instead of

mySerial.print("18");
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50883
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    for(i=1; i <= holding;i++){                    //we make a loop that will read each byte we received
Array indexes start at 0. Why don't you?

Code:
    for(i=1; i <= holding;i++){                  //we now loop through the array       
    Serial.print(stamp_data[i]);             //printing each byte we received  through the hardware UART
       }

       Serial.println("")
If you started in position 0, you could replace all this with
Code:
Serial.println(stamp_data);

Code:
    mySerial.flush(); 
This was NOT per my suggestion. In fact I strongly encouraged you to get rid of it.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <NewSoftSerial.h>               //this will let the software take advantage of the "newsoftserial" library.                   

NewSoftSerial mySerial =  NewSoftSerial(6, 7);

char stamp_data[15];         
//this is where the data from the stamp is stored. The array is 15 char long because
//if no pH probe is connected, the message "check probe" is transmitted.
 //Having an array that is too small will cause data corruption and could cause the Arduino to crash.
byte holding;                       
//used to tell us the number of bytes that have been received by the Arduino and are
//holding in the buffer holding
byte i;                 


void setup()

{
  mySerial.begin(38400);   
  Serial.begin(57600); 
delay(1000);
  mySerial.print("l0");           //the command "c" will tell the stamp to take continues readings
  mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")
delay(1000);
  mySerial.print("c");           //the command "c" will tell the stamp to take continues readings
  mySerial.print(13,BYTE);       //ALWAYS end a command with <CR> (which is simply the number 13) or//(print("/r")
 
}

         
void loop() {                                       //main loop


 if(mySerial.available() > 0) {        //if we see the more than three bytes have been received by the Arduino

    holding=mySerial.available();      //lets read how many bytes have been received
   
   
    for(i=0; i <= holding;i++){       //we make a loop that will read each byte we received
        stamp_data[i]= mySerial.read();     //and load that byte into the stamp_data array
        stamp_data[i+1] = '\0'; // <== add this line
    }

    Serial.println(stamp_data);   



    }
}


With this code I still get garbage, why.? why are the others in this post not getting this?
I am using an Arduino fio 328 3.3v

output is

5.e45.e45.e4
5.u45.e45.e0
5.e05.u45.e4
5.e45.u45.e4
5.eÿ
5.e0ÿ
5.u0ÿ
5.e4ÿ
5.e0ÿ
5.e4ÿ




Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50883
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    for(i=0; i <= holding;i++){       //we make a loop that will read each byte we received
If you got 4 characters, holding will contain 4. You loop while i=0, i=1, i=2, i=3 and i=4, to read 5 of the available 4 characters.

The data sheet for the sensor says:
Quote
The output is (up to five) ASCII digits representing the PH and ending
with a carriage return (ASCII 13).
Example:
4.60<CR>
So, you should be reading data until the <CR> arrives, not just whatever happens to have arrived at any given moment.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I have just tested my code on Arduino UNO (supply of 5v)  as opposed to Arduino fio 328 (supply of 3.3v)
and it works like a charm, no garbage characters

I figured the serial out from the ph stamp is at a different level somehow to the arduino fio..

any help to get it to work with the fio

I have already tried the HEF4050 with both 3.3 and 5v as supply but still same garbage coming out...
Logged

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

First time on here and new to Arduino programming, hoping to get some help or advice.

It looks like Atlas Scientific has been changing the pH stamp commands with each new version.  I am using version 3.0, the latest version, in which the data sheet says the output can return up to 12 ASCII characters.   According the the sellers instructional video, the null command is used to make an LED blink on the pH stamp ( ), and from reading forums like this I have learned it is also needed to make an array (no idea why).  I finally have my Arduino Uno displaying readable text on the serial monitor using a slight variation from the sample code provided by Atlas (as it looks like you guys have been discussing on here).  The problem is that the data I am receiving does not appear to be pH readings, I get continous lines (in the serial monitor) of:

...
base:      0acid:    2012.91
base:      0acid:    2012.91
base:      0acid:    2012.91
base:      0acid:    2012.91
...

Here is the code I am using (not sure how to shrink it down like you guys are doing):

#include <NewSoftSerial.h>                      //this will let the software take advantage of the "newsoftserial" library.                     

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

void setup(){
  mySerial.begin(38400);                             
  Serial.begin(38400);                         
          }
                     
void loop() {                             

mySerial.print('r');                      //take a reading from the sensor, end with carriage return
mySerial.print(13,BYTE);                 
delay(5000);                              //delay to read serial monitor

int holding;
int i;                           
char stamp_data[25];     

 if(mySerial.available() > 3) {              //if we see the more then three bytes have been received by the Arduino
    holding=mySerial.available();            //lets read how many bytes have been received
   
    for(i=1; i <= holding;i++){             //we make a loop that will read each byte we received
        stamp_data= mySerial.read();     //and load that byte into the stamp_data array
    }
   
    for(i=1; i <= holding;i++){            //we now loop through the array         
        Serial.print(stamp_data);       //printing each byte we recived  through the hardware UART
       }
       Serial.println("");                //once we finished, we print a nul char with the <CR><LF> command.
     
  }
}

Any help?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50883
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Notice how half of your post is in italics? Modify your post, select your code, and press the # icon on the second row, and save.

Some questions. Why are you waiting specifically for 3 bytes to arrive, when clearly there are a lot more than 3 arriving? Where did you get the 12 character value from? What you show as your output has more than 12 characters.
Logged

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


I have just tested my code on Arduino UNO (supply of 5v)  as opposed to Arduino fio 328 (supply of 3.3v)
and it works like a charm, no garbage characters

I figured the serial out from the ph stamp is at a different level somehow to the arduino fio..

any help to get it to work with the fio

I have already tried the HEF4050 with both 3.3 and 5v as supply but still same garbage coming out...

ossama,

I am experiencing exactly the same problem as you (the garbage characters), same Arduino Fio 328p. Haven't tried on a 5v model yet(unfortunately I  made a Fio specific PCB).
Have you eventually found a workaround?

Thanks,
 
Logged

Pages: 1 [2]   Go Up
Jump to: