Trouble with Software Serial on Yun

Background info:
I’m putting together a pH/temperature sensor system. So I need some serial communication to get data from the sensors. Since hardware serial is reserved for the on-board Linux distro, the next logical step was to implement software serial ports.

My problem:
I am using the generic SoftwareSerial example code to get things up and running. Naturally, not even the most basic things work right away. No matter what I do, all I ever see on the serial monitor after I compile and uplaod the code is “Goodnight, Moon!”, but no “Hello, world!”, which indicates to me that softwareSerial isn’t ever working, but the regular serial communication and the board itself must be alright because I am at least able to get the first message to appear consistently.

Yes, I have tried using other pins. No, it doesn’t seem to matter which I use, even if they have interrupt functionality (I’ve tried combos such as 8&9, 10&11, 13&15 and even 7&3 for Rx and Tx respectively, all to no avail). I’ve tried resetting & not resetting the board during upload, I’ve tried messing with baud rates, every trick in the book I could find in forums and through existing documentation and I am at my wit’s end trying to get this extremely basic code to run on this Leonardo board. If you have any ideas, I would love to hear them. Thank you!

“My” code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println(“Goodnight moon!”);

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println(“Hello, world?”);
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Since hardware serial is reserved for the on-board Linux distro,

So how come you can see Goodnight Moon ?

You haven't said what the software serial is connected to. It would appear to be nothing, which goes quite some way to explain why you don't any Hello World.

You need to re-think what you are doing, it is almost certainly a lot easier than you think. IF you want to read some sensors, AND you remain connected to the serial monitor, i.e. Serial.println("Goodnight Moon"), then you are not likely to need software serial, unless the sensors are serial devices.

To answer your first question:

Frankly, I don’t know. I was expecting to have the reverse problem where I’d see the “Hello, World” message and not the “Goodnight, moon” message, if indeed hardware serial was dedicated to the Linux distro. Although, since I am able to print from hardware serial, as you are saying, then it must not be fully reserved.

That said, I still can’t use them for the sensors because I will be using the WiFi functionality to wirelessly communicate the data to other software through a dedicated API. So, I will still need to implement software serial.

To answer your other question:

You’re right, I have nothing wired up to the software or hardware serial ports right now, but that’s also not the point of what I’m doing, which I maybe didn’t clarify originally. I’m just testing them with the script. Those messages are just stand-ins for actual data. All I am trying to do right now is make sure that all of the ports are capable of sending and receiving data BEFORE I wire up the actual sensors so that I don’t have a troubleshooting nightmare LATER.

nekomancer:
You're right, I have nothing wired up to the software or hardware serial ports right now, but that's also not the point of what I'm doing, which I maybe didn't clarify originally. I'm just testing them with the script. Those messages are just stand-ins for actual data. All I am trying to do right now is make sure that all of the ports are capable of sending and receiving data BEFORE I wire up the actual sensors so that I don't have a troubleshooting nightmare LATER.

Well, you seem to be on the wrong tram there... Your code may be 100% kosher and software serial is doing exactly what it is supposed to do - converse with pins 10,11 as written. But you will never know until you connect something to pins 10,11 that can can receive/transmit something. You can say "Hello World" as loudly as you like, but it is a pointless exercise if nobody is listening.

Further, despite your assertion, you are connected to Hardware serial, hence the "Goodnight Moon", so you can stick that on the wall as a half-triumph. I would submit that the test for successful transmission by software serial is simply to suck it and see, rather than theorise. All you have done is bring your troubleshooting nightmare to the NOW. I know nothing about the Yun, and don't know what a distro is, but it would seem that your first job is to prove that you can use the Wifi, which I understand is built-in, but I suspect you have never tried..

That said, I still can't use them for the sensors because I will be using the WiFi functionality to wirelessly communicate the data to other software through a dedicated API. So, I will still need to implement software serial.

Incoherent, but probably not an answer.