Transfer data from ESP32 to Arduino Uno using UART

No, I was referring to the UNO as the converter.
I'm sure my suggestion is not what the instructor has in mind, they likely want to teach how to use serial communications. I was just using the simplistic approach, do all the code in the ESP32, and just have the UNO as a meaningless "look at input pin and set output pin to same state".

Ok, what part are you stuck on? are you still unsure about the serial communication?

So you recommend I don't use UNO?

Yes, but serial communication is not working. I can send data from UNO to esp32 but I can't send from esp32 to arduino (which is what I need)

void loop(){
  if(mySerial.available()){
    String received = "";
    received = Serial.readStringUntil('\n');
    Serial.println(received);
  }
}

You are reading from the wrong serial port!!!

What would be correct, david?

void loop(){
  if(mySerial.available()){
    String received = "";
    received = mySerial.readStringUntil('\n');
    Serial.println(received);
  }
}

"mySerial.readStringUntil('\n');"

mySerial.readStringUntil(), the port connected to the ESP32.

I just made the code change. But still no result on the serial monitor, no message is printed from the arduino side

Ok, I'm actually not very familiar with the string library, so I'll post an alternative from a very good tutorial called: Serial Input Basics . If you need more characters to be sent through, then follow the rest of the tutorial.

Most people recommend you use char variables (or char arrays), instead of strings.

Sender ESP32

#define RXD1 14
#define TXD1 15

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1);
}

void loop() {

  delay(1000);

  Serial.print("0");
  Serial1.print("0");

  delay(1000);

  Serial.print("1");
  Serial1.print("1");
}

Receiver Arduino


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

char receivedChar;
boolean newData = false;

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
}

void loop() {
  recvOneChar();
  showNewData();
}

void recvOneChar() {
  if (mySerial.available() > 0) {
    receivedChar = mySerial.read();
    newData = true;
  }
}

void showNewData() {
  if (newData == true) {

    newData = false;

    switch (receivedChar) {
      case '0':  // receiving 0 will lock
        Serial.println("lock");
        break;
      case '1':  // receiving 0 will unlock
        Serial.println("unlock");
        break;
    }
  }
}
1 Like

I made the change to the david code, but the arduino still wasn't able to receive the code. I'll post a picture of my connections

I turned off the plates so as not to interfere with your visualization.

Hi,
Try removing the resistor between ESP32 Tx and the UNO Rx and try connecting direct.

The direction you want your comms to go is from 3V3 logic to 5V logic.

Tom... :smiley: :+1: :coffee: :australia:

As I can see you connected resistors in series on Rx Tx line, what is that for??
You need a 2 resistor voltage divider on ESP32`s Rx pin only.

Ok Tom, I just removed them and connected directly to the UNO

I just removed both resistors, I'll test again

You need to change that code to fit to the ESP32's additional serial port. However, based on the photograph, it appears you have a hardware problem.

In this case, the ESP32 serial port would be 115200, correct? just change the serial.begin?

The hardware I followed from this tutorial.