Communication from Mega to Uno

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?

#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);
 
   }}
      }
 

Welcome to the forum

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

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

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

The Uno runs the normal GRBL skript

Sorry, but I don't know what that is

Does it use the Serial interface for anything ?

It is a skript für cnc machines

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".

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

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

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.

because I have a central power supply

Thats my Mega Setup

I have no code
I have only done the GRBLUPLOAD example

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

2 Likes

.

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.

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.

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

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.

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

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. 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.

1 Like