Using serial to trigger functions on another arduino

Hello

I am undertaking a project that involves an Arduino Mega and an Arduino Uno.

The Mega needs to be able to send data to the Uno via serial (Serial2) and the Uno act accordingly.

i.e., if the Mega sends a "1", the Uno should do function 1

or if the Mega sends a "2", the Uno should do function 2

I'm having trouble getting data to be sent over serial

My pins are mapped as follows:

Mega 17 RX2 - Uno 1 TX
Mega 16 TX2 - Uno 0 RX

Does anyone have any sample code or ideas as to how this could be approached? I am thinking maybe a case statement may be suitable.

Many thanks

I'm having trouble getting data to be sent over serial

And those troubles are what?

Did you jumper the grounds of both boards together? Connect the grounds so the signals will all be relative to the same ground. Voltage is always relative to its own ground.

Mega2560 has Serial, Serial1, Serial2 and Serial3 with RX/TX, RX1/TX1, RX2,TX2 and RX3/TX3.

Use Serial.write() to send binary data. Use print() to send text.

Start with 1200 baud at both ends. That's still 120 cps.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. The system in the 3rd example will be the most reliable.

Just get the sending Arduino to match the program for the receiving Arduino.

...R