Go Down

Topic: Serial communication problems with Atlas pH stamp (Read 418 times) previous topic - next topic

NStone

Can anyone give me insight into what I am doing wrong?  I have an Atlas Scientific pH stamphttps://www.sparkfun.com/products/10972 hooked up to pins 2&3 and the example sketch which comes from Atlas(which uses SoftwareSerial). Here is a linkhttps://www.atlas-scientific.com/_files/code/Arduino-sample-code-EZ-COM.pdf.

So when I send a command like "R"(take pH reading) I see the chip LED blink which acknowledges that it received my command, but it returns garbage characters.  Almost like it is using the wrong connection speed.

To troubleshoot the situation i hooked the ph sensor board directly to the rx/tx lines on the Arduino to bridge it directly to the stamps serial line.  Oddly enough, I get valid pH readings when bridging via the on board UART chip, but when going through a SoftwareSerial port I get garbage back.  Any ideas?  I used the example sketch directly, I know the serial com speed is correct, so why am I receiving garbage responses?

kautzz

Hey there,

I have the exact same problem. Did you find a way to solve it?
I must say, I am not using the Arduino IDE. I use avr-gcc and avrdude to compile and upload. Then I connect to the serial terminal via screen.


kautzz

#2
May 29, 2013, 02:54 pm Last Edit: May 29, 2013, 03:35 pm by kautzz Reason: 1
Here is the code mentioned by NStone. I changed it for readability reasons and added some debugging output.

Code: [Select]

/*
Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.
Remember, select carriage return from the drop down menu next to the baud rate selection; not "both NL & CR".
The data from the Atlas Scientific product will come out on the serial monitor.
Type in a command in the serial monitor and the Atlas Scientific product will respond.
*/


#include <SoftwareSerial.h>
#define rxpin 2                                                              
#define txpin 3                                                              

SoftwareSerial myserial = SoftwareSerial(rxpin, txpin);


String inputstring = "";
String sensorstring = "";
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;


void setup()
{
 Serial.begin(38400);
 myserial.begin(38400);
 inputstring.reserve(5);
 sensorstring.reserve(30);
}



void serialEvent()
{
 char inchar = (char)Serial.read();
 inputstring += inchar;

 if(inchar == '\r')
 {
   input_stringcomplete = true;
   Serial.print (">>> input_string complete: ");
 }
}



void loop()
{
 if (input_stringcomplete == true)
 {
   myserial.print(inputstring);
   Serial.println(inputstring);

   inputstring = "";
   input_stringcomplete = false;
 }


 while (myserial.available())
 {
   char inchar = (char)myserial.read();
   sensorstring += inchar;

   Serial.println ("/// in myserial.available");
//  Serial.println (sensorstring);

   if (inchar == '\r')
   {
     sensor_stringcomplete = true;
     Serial.println ("<<< sensor_string complete: ");
   }
 }


 if (sensor_stringcomplete == true)
 {
   Serial.println(sensorstring);
   sensorstring = "";
   sensor_stringcomplete = false;
 }

 delay (1000);

}



SerialEvent() gets triggered and prints ">>> input_string complete:".
In loop() the condition input_stringcomplete == true fires and returns the correct inputstring.
myserial.available() comes next, printing "/// in myserial.available".

Now it should receive a "\r" from the ph-driver board but the code never gets to do this:

Code: [Select]

   if (inchar == '\r')
   {
     sensor_stringcomplete = true;
     Serial.println ("<<< sensor_string complete: ");
   }


If I uncomment
Code: [Select]
Serial.println (sensorstring); in myserial.available() the output looks like this:

Quote

/// in myserial.available
???????
/// in myserial.available
????????
/// in myserial.available
?????????
/// in myserial.available
??????????
/// in myserial.available
??????????
.
.
.


As I said, I'm connected to the serial terminal with:
Code: [Select]
screen /dev/ttyACM0 38400,cs8,-parenb,-cstopb,-hupcl

Go Up