How to send data from arduino to esp32

I am trying to capture data from a Lidar Lite V3 sensor through an Arduino and, via UART connection, send the Arduino data to an ESP32.


But Im only receiving the information 'NO data from Arduino' on the serial monitor;

esp32


void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, 16, 17); // Configura a comunicação serial com os pinos RX e TX
}

void loop() {
  if (Serial2.available()) {
    String receivedMessage = Serial2.readStringUntil('\n');
    Serial.println("Received from Arduino: " + receivedMessage);
  } else {
    Serial.println("No data from Arduino");
  }
  delay(1000);
}

Arduino

#include <Wire.h>
#include <LIDARLite.h>

LIDARLite lidar;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  lidar.begin(0, false, 'b'); // Inicializa o LIDAR Lite v3
  delay(100);
}

void loop() {
  int distance = readLidar(); // Função para ler a distância do LIDAR
  Serial.print("Distance: ");
  Serial.println(distance);
  delay(1000);
}

int readLidar() {
  int distance = lidar.distance(); // Lê a distância medida pelo LIDAR Lite v3
  return distance; // Retorna a distância medida
}

Someone can help me?

A logic level converter is required to connect I/O pins on a 5V Arduino to pins on a 3.3V ESP32.

Please do not post pictures of code or error messages. Use copy/paste and code tags instead.

1 Like

@gugateles

Here are links showing two methods of logic level shifting (voltage dividing):

1 Like

1. Here is a setup (Fig-1) between UNO-ESP32 using voltage-divider as a level shifter on the STX-RX2 line. There is no need for level shifter on SRX-TX2 line. I have used SUART Port (Software UART Port) at the UNO side as the UNO has only one hardware UART (UART) Port which usually remains engaged with IDE/SM fro program ploading and debugging.


Figure-1:

2. Alternative setup (Fig-2, recommended)


Figure-2:

1 Like

The Uno's data (0 & 1) aren't going to ESP32's 16 & 17 -- according to your diagram (even though they are "ADC 16 & 17", but that's different).

1 Like

having to program two microcontrollers and the resultant communications makes the overall task complexity an order of magnitude greater

maybe simpler to connect the Lidar Lite V3 to the ESP32 and discard the UNO
the Lidar Lite V3 uses 5V logic so you will require a level shifter to convert the I2C signals to 3.3V logic

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