I'm tearing my hair out. Having got the Nano chatting happily with Serial to enable/disable sampling and perform other actions by receipt of simple commands I'm now attempting to connect the Nano to a Mega which will collect data from several places and merge into one.
I just can't get the mega<-->nano comms working and it's driving me nuts!
Mega: Take Serial and pipe to Serial1, read from Serial1 and echo to Serial
#define PULSE_PIN 51
void setup()
{
pinMode ( PULSE_PIN, OUTPUT ) ;
Serial.begin(115200);
Serial1.begin ( 57600 ) ;
}
void loop()
{
if ( Serial.available() >0 )
{
Serial1.write ( Serial.read() ) ;
}
if ( Serial1.available() > 0 )
{
Serial.write ( Serial1.read() ) ;
}
if ( millis() % 1000 < 500 )
{
digitalWrite (PULSE_PIN, HIGH) ;
}
else
{
digitalWrite (PULSE_PIN, LOW) ;
}
}
NANO: Read SoftwareSerial and then echo back
#include <SoftwareSerial.h>
SoftwareSerial MySerial(5, 6) ; // RX, TX
#define PULSE_PIN 12
void setup()
{
pinMode ( PULSE_PIN, OUTPUT ) ;
MySerial.begin(57600);
}
void loop()
{
unsigned char chIn ;
static bool bLight = false ;
if ( MySerial.available() )
{
chIn = MySerial.read() ;
MySerial.write ( chIn ) ;
if ( bLight )
{
digitalWrite ( PULSE_PIN, HIGH ) ;
}
else
{
digitalWrite ( PULSE_PIN, LOW ) ;
}
bLight = !bLight ;
}
}
I've made sure that NANO-TX --> MEGA-RX and NANO-RX -->MEGA-TX. Hey, it's got so bad that I've even reversed them, just in case!
Are there any strange hardware requirements that I have to be aware of related to SoftwareSerial please? Pull-ups/downs/etc?
The two boards have a common ground and VCC and are < 15cm apart.
I've happily had Megas chatting with each other using Serial1/2/3.
Sorry if this isn't quite in the right section of the forum... this seemed most appropriate.