Trouble reading serial for pH sensor Yun

Hi,

I have an atlas scientific pH sensor with the microcontroller - using http://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf?
I have the hardware setup for using the serial rx and tx on pins 12 and 13, I am using a Yun. I can send commands via the Console, e.g. L,0 to turn off the LED and L,1 to turn back on so that is working ok. When I request a reading from the sensor using the command R, I can see that the LED on the micro flashes blue so I know it is in UART mode and is receiving the command and it is understood. I am not getting anything back though, even if I send “I” which should just send back the device info I get nothing.

It seems that pHserial.available is always 0, if I just do pHserial.read() anyway I just get a string of -1’s.

Any suggestions would be greatly appreciated, I am a bit stuck. If I use a multimeter should I see anything from the TX pin on the microcontroller?

Thanks, Kari

#include <Bridge.h>
#include <Console.h>

#include <SoftwareSerial.h>

SoftwareSerial pHserial(12,13); //myserial(rx, tx);

String cmd;
byte startup=0;
byte received_from_sensor_PH=0;
char ph_data[20];
byte string_received=0;

void setup(){
Bridge.begin();
Console.begin();

pHserial.begin(9600); //enable the software serial port

if(startup==0){
pHserial.print(“c,0\r”);
delay(50);
pHserial.print(“c,0\r”);
delay(50);
pHserial.print(“I,0\r”);
pHserial.listen();
delay(50);
startup=1;
}

}

void loop(){
//Console.println(pHserial.available());
//Console.print(pHserial.read());

if(pHserial.available()>0){
Console.println(“pHserial available”);
received_from_sensor_PH=pHserial.readBytesUntil(13,ph_data,20);

ph_data[received_from_sensor_PH]=0;
string_received=1;
Console.print("pH: ");
Console.println(ph_data);

}

if(Console.available() > 0){

char c = Console.read();

if (c == ‘\n’) {
Console.println(cmd);
pHserial.listen(); // need this if using serial for more than one sensor, only 1 can listen at once
pHserial.print(cmd);
pHserial.print(’\r’);
delay(50);
cmd = “”;
}
else {
cmd += c;
}
}

}

Some questions. The Yun, like the Leonardo and Micro, has Serial connected to the usb-to-serial converter and Serial1 connected to pins 0 and 1. Why are you not using Serial1 to talk to the pH sensor?

The Mega, for instance, does not support pin change interrupts on all pins. Does the Yun? Are you CERTAIN that you can do SoftwareSerial on pins 12 and 13?

Thank you!
I had not realised that I could not use those pins for serial. I have it working on pins 10 and 11 now. I was not using Serial1 as I have to connect more than one sensor this way so I needed to use the other pins anyway. I have just tried on Serial1 however to test and it is not working, I need baud rate of 9600 - could that be a problem?
If you notice in the code below I have Console.println(“test”); in the loop - it does not even print this to the Console when I use the following code. Any thoughts on why that would be ?

Many thanks for you help!

#include <Bridge.h>
#include <Console.h>

#include <SoftwareSerial.h> //add the soft serial libray //set the TX pin to pin 3

//SoftwareSerial pHserial(10,11); //myserial(rx, tx);

String cmd;
byte startup=0;
byte received_from_sensor_PH=0;
char ph_data[20];
byte string_received=0;
String sensorstring = “”; //have we received all the data from the PC
boolean sensor_stringcomplete = false;

void setup(){
Bridge.begin();
Console.begin();

Serial1.begin(9600); //enable the software serial port

if(startup==0){
Serial1.print(“c,0\r”);
delay(50);
Serial1.print(“c,0\r”);
delay(50);
Serial1.print(“I,0\r”);
//pHserial.listen();
delay(50);
startup=1;
}

}

void loop(){
//Console.println(pHserial.available());
//Console.print(pHserial.read());
Console.println(“test”);
while (Serial1.available()) {

Console.println(“pHserial available”);
received_from_sensor_PH=Serial1.readBytesUntil(13,ph_data,20);

ph_data[received_from_sensor_PH]=0;
string_received=1;
Console.print("pH: ");//a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string has been received.
Console.println(ph_data); //lets transmit that data received from the pH Circuit to the serial monitor
//pHserial.print(“c,0\r”);
}

if(Console.available() > 0){

char c = Console.read();

if (c == ‘\n’) {
Console.println(cmd);
//pHserial.listen(); // need this if using serial for more than one sensor, only 1 can listen at once
Serial1.print(cmd); //needs to be println?
Serial1.print(’\r’);
delay(50);
cmd = “”;
}
else {
cmd += c;
}
}

}