So I am communicating with one of Atlas scientifics stamps for pH. I am trying to pass a string to it to read back a single pH value. It all works fine, however the serial terminal also displays a load of other nonsense:
You can see the values are coming back fine:
7.¾¿íÿ¿ÿûí·¯¿¿Í6.82
6.82
·¯¿¿í÷ÿÿûý7.<3
7.01
7.01
7.01
·¯¾½íÿ¯ÿÿÿ7.<1
7.01
7.01
7.01
7.01
ÿ�íÿÿÿÿý7.01
7.01
7.01
7.01
·¯<½íÿ¿ÿýÿ7/>9í7.01
7.01
7.01
·¯¿½ÿ¯¿½í÷ÿÿÿý7.81
In the past Ive only experienced this kind of thing when baud rates are out, however they aren't in this case. Im using the serial library to pass the info to the terminal and a softserial to communicate with the stamp, both at 38400 - the terminal is also at that rate. Im using an interupt every second to pass the command to the stamp - that all works fine, sorry for the long code but Im only attaching it so you believe I set my two serial bauds to the same!
#include <SoftwareSerial.h> //add the soft serial libray
#include <avr/io.h>
#include <avr/interrupt.h> //for the interrupt routine
#define ISR_TIMER1_COUNT 62499 // 16.0MHz clock / (prescaler = 256) 1Hz counter
#define rxph 2 //set the RX pin to pin 2
#define txph 3 //set the TX pin to pin 3
SoftwareSerial pH (rxph, txph); //enable the soft serial port
String inputstringPH = ""; //a string to hold incoming data from the PC
String sensorstringPH = ""; //a string to hold the data from the Atlas Scientific product
volatile boolean inputPH_stringcomplete = false; //have we received all the data from the PC
volatile boolean sensorPH_stringcomplete = false; //have we received all the data from the Atlas Scientific product
void setup() //set up the hardware
{
setupTimer1(); //calls the timer setup function for the interupt
Serial.begin(38400); //set baud rate for the hardware serial port to 38400
pH.begin(38400); //set baud rate for software serial port to 38400
pinMode(12, OUTPUT); //toggle the led when the interupt 'ticks'
inputstringPH.reserve(5); //set aside some bytes for receiving data from the PC
sensorstringPH.reserve(30); //set aside some bytes for receiving data from the Atlas Scientific product
inputstringPH = "R\r";
}
void loop() //here we go...
{
if (inputPH_stringcomplete) //if a string from the PC has been recived in its entiery
{
pH.print(inputstringPH); //send that string to the Atlas Scientific product
inputPH_stringcomplete = false; //reset the flag used to tell if we have recived a complete string from the PC
}
while (pH.available()) //while a char is holding in the serial buffer
{
char incharPH = (char)pH.read(); //get the new char
sensorstringPH += incharPH; //add it to the sensorstring
if (incharPH == '\r')
{
sensorPH_stringcomplete = true; //if the incoming character is a <CR>, set the flag
}
}
if (sensorPH_stringcomplete) //if a string from the Atlas Scientific product has been received in its entirety
{
Serial.println(sensorstringPH); //use the hardware serial port to send that data to the PC
sensorstringPH = ""; //clear the string:
sensorPH_stringcomplete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
}
}
Thanks guys