ESP32 doesn't read data from UART

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

ESP32 doesn't read data from UART

Postby GeorgeFlorian1 » Mon May 24, 2021 10:39 am

I would like to implement the TF02-Pro with the ESP32. I know that it works with Arduino so I've assumed that it will work with ESP as well.

Board: Wrover-B Devkit 4.

The TF02-Pro has 4 wires defined as: red +5V, black GND, green TX, white RX.

I have connected them as follows:
Sensor 5V to ESP 5V;
Sensor GND to ESP GND;
Sensor TX to ESP RX;
Sensor RX to ESP TX;

Also, the TF02-PRO adopts the serial port data communication protocol.

Communication interface: UART
Communication level: LVTTL(3.3V)
Default baud rate: 115200
Data bit: 8
Stop bit: 1
Parity check: None

I have followed this guide: https://www.roscomponents.com/en/index. ... chment=309

This is the code resulting:

Code: Select all

#include <Arduino.h>

#define RXD2 16
#define TXD2 17

int dist;     // LiDAR actually measured distance value
int strength; // LiDAR signal strength
int check;    // check numerical value storage
int i;
int uart[9];             // store data measured by LiDAR
const int HEADER = 0x59; // data package frame header

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Started.");
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
}

void loop()
{
  if (Serial2.available()) //check whether the serial port has data input
  {
    if (Serial2.read() == HEADER) // determine data package frame header 0x59
    {
      uart[0] = HEADER;
      if (Serial2.read() == HEADER) //determine data package frame header 0x59
      {
        uart[1] = HEADER;
        for (i = 2; i < 9; i++) // store data to array
        {
          uart[i] = Serial2.read();
        }
        check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
        if (uart[8] == (check & 0xff)) // check the received data as per protocols
        {
          dist = uart[2] + uart[3] * 256;     // calculate distance value
          strength = uart[4] + uart[5] * 256; // calculate signal strength value
          Serial.print("dist = ");
          Serial.print(dist); // output LiDAR tests distance value
          Serial.print('\t');
          Serial.print("strength = ");
          Serial.print(strength); // output signal strength value
          Serial.print('\n');
        }
      }
    }
  }
}
The issue is that I have no output except Serial.println("Started.");.

I have opened the sensor and I have measured the voltage input and it's around 4.5V. The Product Manual of TF02-Pro says that the supply voltage should be 5V~12V.
Attachments
27051054-1387-426b-ba53-6ef9a24363d5.jpg
27051054-1387-426b-ba53-6ef9a24363d5.jpg (130.48 KiB) Viewed 4650 times
Last edited by GeorgeFlorian1 on Mon May 24, 2021 12:35 pm, edited 4 times in total.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32 doesn't read data from UART

Postby chegewara » Mon May 24, 2021 10:47 am

Do you have enabled PSRAM?
It is wrover module and pins 16, 17 are used by PSRAM.

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Re: ESP32 doesn't read data from UART

Postby GeorgeFlorian1 » Mon May 24, 2021 11:14 am

chegewara wrote:
Mon May 24, 2021 10:47 am
Do you have enabled PSRAM?
It is wrover module and pins 16, 17 are used by PSRAM.
It is the Wrover-B, yes.

But I have no idea if the PSRAM is enabled. How do I check that ?

I have changed the pins to:

Code: Select all

#define RXD2 22
#define TXD2 23

void setup()
{
  Serial.begin(115200);
  Serial.println("Started.");
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
}
And I still have no output.

Who is online

Users browsing this forum: No registered users and 62 guests