# Communication from Mega to Uno

**URL:** <https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306>\
**Category:** Networking, Protocols, and Devices\
**Created:** [August 22, 2024, 1:32pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306 "2024-08-22T13:32:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 1:32pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/1 "2024-08-22T13:32:37Z")

</div>

Hello i have got an Arduino Mega 2560 running with the skript below and a Arduino running grbl. The two arduinos connected by rx and tx (Rx of Mega to Tx of Uno and Tx of Mega to Rx from Uno)  
My skript on the Mega is running without connection to the Uno like it should, also the Grbl works fine without connection to the Uno an getting commands from the serial monitor. When both are connected the Rx Led on the Mega is burning and on the Uno nothing happend  
Where is the problem?

```arduino
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

int pos = 0;
int target = 0;
int target1 = 0;
byte digitCount = 0;
char incomingByte;
char incomingByteB;
char incomingByteC;
char incomingByteD;

//SETUP THE LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);

//SETUP THE KEYPAD
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
     '1','2','3','\a',
     '4','5','6','\b',
     '7','8','9','\e',
     '*','0','#','\f'
};

//byte rowPins[ROWS] = {22, 24, 26, 28}; //connect to the row pinouts of the keypad
//byte colPins[COLS] = {30, 32, 34, 36}; //connect to the column pinouts of the keypad

byte rowPins[ROWS] = {5, 4, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 9,10, 11}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {

  Serial.begin(115200);
  Serial1.begin(115200);
  Serial3.begin(115200);

//LETS SETUP THE LCD TEXT
  lcd.begin();
  lcd.backlight();
  lcd.print("ENTER LENGTH IN mm");
  lcd.setCursor(0,1); 
  lcd.print("--------------------");
  lcd.setCursor(0, 2);
  lcd.print("===> mm");
  lcd.setCursor(0, 3);
  lcd.print("STOP POSITION= 0");
  lcd.setCursor(5, 2);
  

}
void loop() {
//this simply sends serial3(esplink wifi) input to serial1 (GRBL) and sends the GRBL(serial1) outputs to Serial3(esplink wifi)
  if (Serial3.available() > 0) {
    // read the incoming byte from esplink
    incomingByte = Serial3.read();

    // send to grbl
       Serial1.print(incomingByte);
       Serial3.print(incomingByte);
        }
if (Serial1.available() > 0) {
    // read the incoming from grbl
    incomingByteB = Serial1.read();

    // send to esplink
       Serial3.print(incomingByteB);
        }

        if (Serial.available() > 0) {
    // read the incoming from usb
    incomingByteC = Serial.read();

    // send to grbl
       Serial1.print(incomingByteC);
        }
        if (Serial.available() > 0) {
    // read the incoming from grbl
    incomingByteD = Serial.read();

    // send to esplink
       Serial3.println(incomingByteD);
        }

      

  //FUNCTION TO HOMME WHEN THE * IS PRESSED
  char keypressed = keypad.getKey();
if (keypressed == '*'){
Serial1.println("$H");
Serial3 .print("Homming....");
 lcd.setCursor(14, 3);
     lcd.print(" ");
     lcd.setCursor(14, 3);
     lcd.print("HOMME");
     lcd.setCursor(5, 2);
 }
 //FUNCTION TO ADD 0.1MM WHEN THE B IS PRESSED
if (keypressed == '\b'){
Serial1.println("G91X+0.1");
Serial3.print("+0.1");
lcd.setCursor(14, 3);
lcd.print(" ");
lcd.setCursor(14, 3);
     lcd.print(target+0.1);
     lcd.setCursor(5, 2);

 }
 //FUNCTION TO REMOVE 0.1MM WHEN E IS PRESSED
 if (keypressed == '\e'){
Serial1.println("G91X-0.1");
Serial3.print("-0.1mm");
lcd.setCursor(14, 3);
lcd.print(" ");
lcd.setCursor(14, 3);
     lcd.print(target-0.1);
     lcd.setCursor(5, 2);
 }

 // FUNCTION TO FEED HOLD WHEN ! IS PRESSED
 if (keypressed == '\f'){
Serial1.println("!");
Serial3.print("Feed Hold !!");
 }

 // FUNCTION TO RESUME AFTER FEED HOLD WHEN # IS PRESSED
 if (keypressed == '#'){
Serial1.println("~");
Serial3.print("Resuming");
 }
 // FUNCTION TO DELETE THE INPUT DIMENTION WHEN A IS PRESSED
 if (keypressed == '\a'){
digitCount=0;
 target1= 0;
lcd.setCursor(5, 2);
lcd.print(" ");
lcd.setCursor(5, 2);
 }
 //FUNCTION TO INPUT DIRECTION TO MOVE AFTER 4 DIGITS IS ENTERED
if (keypressed >= '0'){// && Key <= '9') {
  lcd.print(keypressed);
      target1 = (target1 * 10) + keypressed -'0';
          digitCount++;
         delay(300);
                
       
   if (digitCount == 4) {
     target = target1;
          Serial1.print("G90X");
          Serial1.println(target1);
          Serial3.println(target1);
            lcd.setCursor(5, 2);
     lcd.print(target);
     Serial3.print(target);
     
   
     digitCount = 0;
     target1= 0;
     lcd.setCursor(5, 2);
     lcd.print(" ");
     keypressed = 0;
     lcd.setCursor(14, 3);
     lcd.print(" ");
     lcd.setCursor(14, 3);
     lcd.print(target);
     lcd.setCursor(5, 2);
 
   }}
      }
 

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 22, 2024, 1:35pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/2 "2024-08-22T13:35:55Z")

</div>

Welcome to the forum

> [@bache123](#):
>
> (Rx of Mega to Tx of Uno and Tx of Mega to Rx from Uno

Which pins on the Mega are you referring to when you say Rx and Tx ?

Pleas post the sketch that is running on the Uno

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [August 22, 2024, 1:43pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/3 "2024-08-22T13:43:02Z")

</div>

Check the Mega datasheet, are there not multiple TX/RX pairs? Do they need to be enabled, in hardware or software?

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 1:59pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/4 "2024-08-22T13:59:58Z")

</div>

Tx on the Mega is Pin 14 and Rx 15  
This is in the Datasheed Serial 3

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 2:05pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/5 "2024-08-22T14:05:05Z")

</div>

The Uno runs the normal GRBL skript

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 22, 2024, 2:06pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/6 "2024-08-22T14:06:05Z")

</div>

Sorry, but I don't know what that is

Does it use the Serial interface for anything ?

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 2:32pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/7 "2024-08-22T14:32:51Z")

</div>

It is a skript für cnc machines

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 22, 2024, 2:37pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/8 "2024-08-22T14:37:51Z")

</div>

> [@bache123](#):
>
> he two arduinos connected by rx and tx (Rx of Mega to Tx of Uno and Tx of Mega to Rx from Uno)

Did you forget to connect the grounds?

Note that controlling machinery can be a problem if the grounds are at different potentials. You may have to use opto isolators for TX and RX (and not connect grounds).

Look up "ground loop currents".

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 22, 2024, 2:38pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/9 "2024-08-22T14:38:45Z")

</div>

> [@bache123](#):
>
> It is a skript für cnc machines

I know what it is for, but I would like to see the code that you are using

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 3:06pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/10 "2024-08-22T15:06:26Z")

</div>

The grounds are connected, also 5V from the Mega goes to the Uno

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [August 22, 2024, 3:07pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/11 "2024-08-22T15:07:27Z")

</div>

You may have ground loop problems.

> 5V from the Mega goes to the Uno

Why is that? What _else_ is connected to the Uno?

Please post a description and wiring diagram for the entire system, with pins, connections and parts clearly labeled.

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 3:40pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/12 "2024-08-22T15:40:49Z")

</div>

because I have a central power supply

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 5:24pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/13 "2024-08-22T17:24:01Z")

</div>

> **[Arduino Mega GRBL control - Wokwi ESP32, STM32, Arduino Simulator](https://wokwi.com/projects/406939972185323521)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

Thats my Mega Setup

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 22, 2024, 5:31pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/14 "2024-08-22T17:31:05Z")

</div>

I have no code  
I have only done the GRBLUPLOAD example

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [August 23, 2024, 4:45am UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/15 "2024-08-23T04:45:53Z")

</div>

Please, do not make multiple topics with the same subject.

[https://forum.arduino.cc/t/grbl-kommunikation-zwischen-zwei-arduinos/1294484](https://forum.arduino.cc/t/grbl-kommunikation-zwischen-zwei-arduinos/1294484)

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [August 23, 2024, 5:06am UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/16 "2024-08-23T05:06:56Z")

</div>

.

> [@bache123](#):
>
> Thats my Mega Setup

Please post a description and wiring diagram for the entire system, with pins, connections and parts clearly labeled. This must include the connection between the two controllers.

further more upload pictures where we can see each connection between the two controllers.

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [August 23, 2024, 11:59am UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/17 "2024-08-23T11:59:54Z")

</div>

> [@bache123](#):
>
> I have only done the GRBLUPLOAD example

Which is where? Please remember, most helpers here will not have done exactly as you have done, so you may be using something literally NO ONE here has ever seen before.

---

<div class="post-metadata">

**Author:** ![bitherder\_57](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bitherder_57/32/1126810_2.png) [@bitherder\_57](https://forum.arduino.cc/u/bitherder_57)\
**Post date:** [August 23, 2024, 4:39pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/18 "2024-08-23T16:39:16Z")

</div>

There is a recent topic here with a very similar problem.

> [@Arduino Uno cannot communicate with Arduino Mega](https://forum.arduino.cc/t/arduino-uno-cannot-communicate-with-arduino-mega/1287932):
>
> Hi! This is my first post, so forgive me if this is in the wrong category. Currently I have two Arduinos, one Uno and one Mega2560 Rev3. I want the Mega to send GCode data over serial to the Uno, which will then command a CNC shield to step via [GRBL](https://github.com/grbl/grbl). Through the IDE (with Uno selected) I can type something like "G01 x10" and have my X motor move 10 steps. However, when I try to send ANY data from the Mega to the Uno, whether or not GRBL is on the Board, it receives nothing. I have read the [Seri…](https://forum.arduino.cc/t/serial-input-basics-updated/382007/3)

In that case the user was trying to use the USB and pins 0 an 1 at the same time. I suspect you are doing the same.

---

<div class="post-metadata">

**Author:** ![bache123](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bache123](https://forum.arduino.cc/u/bache123)\
**Post date:** [August 24, 2024, 7:17pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/19 "2024-08-24T19:17:09Z")

</div>

No i don’t use it at the same time.  
But when i use it at the same time i see on the serial monitor from the uno error codes from the grbl and the tx led is burning.  
When i don’t use it at the same time the led is not burning

---

<div class="post-metadata">

**Author:** ![afterglow79](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/afterglow79/32/1098793_2.png) [@afterglow79](https://forum.arduino.cc/u/afterglow79)\
**Post date:** [August 26, 2024, 8:49pm UTC](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306/20 "2024-08-26T20:49:15Z")

</div>

Hi! Said user here. I would recommend running a simple serial communication sketch to test if they can send and receive messages, see [example 3 (or 5) of this post](https://forum.arduino.cc/t/serial-input-basics-updated/382007). You should be able to tell if something was transmitted by either sending the received signal back to the Mega and having it display on your computer, or watching the RX/TX lights on your Uno. If neither light up, you have a problem somewhere that is unrelated to GRBL.

Also, I cannot stress this enough, double check to make sure your USB cable is unplugged from your computer when using Serial comms on the Uno.

[Next page](https://forum.arduino.cc/t/communication-from-mega-to-uno/1294306.md?page=2)
