Arduino UNO and ESP32 UART. UNO port not working

I've been testing the UART comms between my UNO board and ESP32. I've followed the basics of having a common ground, connecting RX pin 0 to TX2 and TX pin 1 to RX2, and using a lm1117t 3.3v as a voltage regulator to tone down the logic level.

Yet, when I connect both boards to my laptop, the ESP32 uploads the code as usual, but my UNO refuses to upload it. One thing to note is that, the UNO by itself works, but as soon as I connect the ESP32, everything stops working.

Here's the code for Arduino UNO

Serial.begin (9600);
Serial.println ("Inicio");
}

void loop() {
  // put your main code here, to run repeatedly:
if(Serial.available() > 0)
    {
      String mensaje = Serial.readStringUntil('\n');
      mensaje.trim();
      Serial.print("ARDUINO: ");
      Serial.println(mensaje);

    }
    delay(1);
    }

And here's the code for the ESP32

#define RXD2 16
#define TXD2 17
#define LED 2

void setup() {
  // put your setup code here, to run once:
Serial.begin (19200);
Serial2.begin (9600, SERIAL_8N1, RXD2, TXD2);
pinMode (LED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
if (Serial.available() > 0) {
  Serial.print ("ESP32: ");
  Serial.print ("Recibi el mensaje, ");
Serial.println (Serial2.readString());
digitalWrite (LED, HIGH);
delay (500);
digitalWrite (LED, LOW);
}
delay (1000);
}

This the error that shows up everytime I try to upload:

El Sketch usa 3310 bytes (10%) del espacio de almacenamiento de programa. El máximo es 32256 bytes.
Las variables Globales usan 214 bytes (10%) de la memoria dinámica, dejando 1834 bytes para las variables locales. El máximo es 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xd6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xd6
Failed uploading: uploading error: exit status 1

It is doing exactly what I would expect, nothing. Voltage regulators sound good but they do not work, they are designed to control voltage and take ripple, noise, etc out of the signal which your data would appear to be. Get a proper level translator and that will help part of it. Also you need to disconnect the UNO serial pins from anything external.

This won't work. You can connect the Uno Serial port to the ESP or to your PC, not to both at the same time.

1. Make the following setup (Fig-1); where, TX signal of UNO is level shifted by voltage divider; RX signal of UNO does not require level shifting. I have used Software UART Port for UNO leaving the Hardware UART Port being connected with PC for sketch uploading and debugging.


Figure-1:

2. Upload the following sketch (not tested) in UNO to receive the message "Arduino" from ESP32 at 1-sec interval.

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11); //SRX = 10, STX = 11
char myMsg[10];

void setup()
{
  Serial.begin (9600);
  SUART.begin(9600);
  Serial.println ("Inicio");
}

void loop()
{
  byte n = SUART.available();
  if (n != 0 )
  {
    byte m = SUART.readBytesUntil('\n', myMsg, sizeof myMsg - 1);
    myMsg[m] = '\0'; //nul character
    Serial.println(myMsg);  //check that Serial Monitor shows: Arduino
  }

}

3. Upload the following sketch (not tested) in ESP32 to send the message "Arduino" to UNO at 1-sec interval.


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

void loop()
{
  Serial2.print("Arduino");
  Serial2.println();
  Serial.println("Arduino");
  delay(1000);
}

4. Check that SM of UNO shows the message "Arduino" at 1-sec interval.

1 Like

I used the example in this vídeo to setup the connections, why is it that I can't use both ports at the same time?

UARTs implement a point-to-point communication, between only 2 ports.

I suppose I need to upload the code of the ESP32, but not actually keep it plugged to the PC at the same time as the UNO from what I see in your diagram

In fact, both Arduinos would reamin connected with the PC vai their respective UART?USB Ports. I have presented below the revised diagram (Fig-1). Sorry, for the inconvenience.


Figure-1:

Why did you assign 2 different names to the single Uno UART?

If you mean UART/USB, then my explanation/understanding is:
1. PC is connected with UNO using USB Port. The USB signal is converted to asynchronous signal which is fed to the MCU via its UART Port.

2. At the UNO side, the ATmega328P asserts asynchronous signal (TTL logic) via UART Port, which is then converted to USB Protocol by the onboard TTL/USB Converter chip.

3. At the PC side, the application asserts asynchronous signal on the Virtual COM Port (virtaul UART), which is converted to real USB Protocol for onward transmission over the physical USB Port of PC.

4. The following diagram (Fig-1) depicts my understanding at conceptual level about the concept of Virtual COM Port:


Figure-1:

verbose without anything new, the Uno only has a single UART. The USB interface chip connects to RX/TX. Thus the UART can be used for USB Serial Monitor communication or download, or for a device connected to RX/TX with USB disconnected.

1 Like

It's working now! Thank you. I've modified the code a little bit to make it useful for my project, but overall it's the same you provided me.

I'll put the code here in case I'm wrong about something.

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

void loop() {
  if (Serial.available() > 0) {
    String mensaje = Serial.readStringUntil('\n');
    mensaje.trim();
    
    if (mensaje.length() > 0) {
      String mensajeCompleto = "ESP32: " + mensaje; 
      Serial2.println(mensajeCompleto);  
      delay(100);  
    }
  }
}
#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11); //SRX = 10, STX = 11
char myMsg[10];

void setup()
{
  Serial.begin (9600);
  SUART.begin(9600);
  Serial.println ("Inicio");
}

void loop()
{
  byte n = SUART.available();
  if (n != 0 )
  {
    byte m = SUART.readBytesUntil('\n', myMsg, sizeof myMsg - 1);
    myMsg[m] = '\0'; 
    Serial.println(myMsg);  
  }
}

Your sketch looks alright.
Have fun and good day!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.