I am having trouble running an alternative serial line from a Mega to an Uno using either Serial3 or SoftwareSerial without the Mega's standard serial plugged into a computer's USB port. Seems odd.
The intent is to run the Arduino Mega as a remote data collection device, powered by a standard "9V 1A Arduino power supply adapter 110V AC" - without a USB connection to a computer, and passing its collected system probe data to an Arduino Uno via an alternative Serial connection. The Uno is to be an Uno WiFi that simply collects data from remote data collection devices like the mega.
Code is not much:
/*
* Arduino Uno - Software Serial Example
* Updated: 170610
*/
#include <SoftwareSerial.h>
// Wiring: pins 10 to 10 and 11 to 11
const byte rxPin = 10;
const byte txPin = 11;
SoftwareSerial swSerial(rxPin, txPin);
void setup()
{
Serial.begin(9600);
swSerial.begin(9600);
delay( 1000 );
Serial.println( "Uno started." );
}
void loop()
{
swSerial.println( "From Uno" );
delay( 1000 );
while( swSerial.available() ) {
Serial.print( (char) swSerial.read() );
}
delay( 1000 );
}
/*
* Arduino Mega
* Updated: 170610
*/
#include <SoftwareSerial.h>
// Wiring: pins 10 to 10 and 11 to 11
const byte rxPin = 11;
const byte txPin = 10;
SoftwareSerial swSerial(rxPin, txPin);
void setup()
{
Serial.begin(9600);
swSerial.begin(9600);
delay( 1000 );
Serial.println( "Mega started." );
swSerial.println( "From Mega" );
}
void loop()
{
delay( 1000 );
Serial.println( "Sending to Uno." );
while( swSerial.available() ) {
swSerial.write( (char) swSerial.read() );
}
}
This example works great until I unplug the Mega's USB cable - then communications fail.
Any thoughts?