Mega and Due serial communication

hi all

I want to send a variable from due to mega and also from mega to due. I converted 5v to 3.3v by 5v to 3.3 converter and even by resistor voltage divider, the data is sent from due to mega but problem is sending from mega to due. can you help me?

even I use this sample code for testing the communication , but the LED is always ON!

sender code:

void setup() { Serial.begin(9600);

} void loop() { Serial.print('H'); delay(1000); Serial.print('L'); delay(1000); }

Receiver code :

const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into

void setup() { // initialize serial communication: Serial.begin(9600);

// initialize the LED pin as an output: pinMode(ledPin, OUTPUT); }

void loop() { // see if there's incoming serial data: // if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'L') { digitalWrite(ledPin, LOW); } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); } }

thank you

Is the serial monitor disconnected? Since you have four serial ports, it is better practice to start with Serial1, pins 18,19 for Comms like this.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

I have used the 3rd example to communicate between a Mega and Micro. I don't have a Due but I can't think why it would not work with it.

...R