I've modified the basic example TwoPortReceive on my Arduino Uno so that instead of the two serial ports just listening, they speak to each other.
#include <SoftwareSerial.h>
SoftwareSerial portOne(10, 11);
SoftwareSerial portTwo(8, 9);
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Start each software serial port
portOne.begin(9600);
portTwo.begin(9600);
}
void loop() {
portOne.listen();
Serial.println("Sending data from portOne:");
// while there is data coming in, read it
// and send to the hardware serial port
portOne.println("Hi there from portOne!");
Serial.println("Reading data from portTwo:");
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
// blank line to separate data from the two ports:
Serial.println();
delay(500);
// Now listen on the second port
portTwo.listen();
Serial.println("Sending data from portTwo:");
// while there is data coming in, read it
// and send to the hardware serial port:
portOne.println("Hi there from portTwo!");
Serial.println("Reading data from portOne:");
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
// blank line to separate data from the two ports:
Serial.println();
}
I have port 11 wired to 8 and port 10 wired to 9. What I would expect is that portOne will transmit over port 11 to port8. portTwo will read this data and print it to the Serial console, and vice versa.
I see that code, but it doesn't exactly help... Software Serial Tx simply isn't working.
I set up the code as simply as possible in a new example:
#include <SoftwareSerial.h>
// software serial #1: RX = digital pin 10, TX = digital pin 11
SoftwareSerial portOne(10, 11);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
portOne.begin(9600);
}
void loop() {
portOne.listen();
Serial.println("Sending data from Tx 11");
portOne.println("Hi there from 11!");
Serial.println("Reading data from 10:");
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
// blank line to separate data from the two ports:
Serial.println();
delay(1000);
}
And I wired 10 to 11. 10 is not received any data transmitted by 11, but if I hook 10 up to TX(1) it receives data.
Here is my wiring for the two setups, just to see what's going on. Does this seem like a hardware problem, or are there any troubleshooting steps that I can follow through with?
Is there anything inherent in software serial communications that would prevent two on the same chip from communicating?
My current experience is that Software Serial Tx does not work in any capacity at the moment.
You can't send from one instance of Software Serial to another instance on the same Arduino. Only one instance can work at any one time. Software Serial is a very poor imitation of Hardware Serial.