How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

sharanr15
Posts: 1
Joined: Fri Mar 18, 2022 11:49 am

How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby sharanr15 » Fri Mar 18, 2022 12:48 pm

Hi,

Using Arduino IDE i am trying to read a UART ultrasonic sensor on UART0 using GPIO pins 20 and 21, It is failing to read.
Previously i was using ESP32 Devkitv1, in which using Serial2 and GPIO pins 16 and 17, successfully read the UART ultrasonic sensor.

Can anyone let me know how to use UART on ESP32-C3 Devkitc-02 to read the UART ultrasonic sensor using Arduino IDE.

Thank You

drmpf321
Posts: 9
Joined: Thu Dec 10, 2015 10:33 pm

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby drmpf321 » Fri Apr 29, 2022 6:04 am

Here is an example of using the second UART on ESP32 C3
Remember to connect the ultrasonic TX to pin4 (ESP32 C3 RX) and the ultrasonic RX to pin5 (ESP32 C3 TX)

Code: Select all

// ESP32 C3 SERIAL1  (second UART)
void setup() {
   Serial.begin(115200);
   Serial1.begin(115200,SERIAL_8N1, 4,5); //int8_t rxPin=4, int8_t txPin=5 
}

void loop() {
    if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 4 & 5)
  }

  if (Serial1.available()) {     // If anything comes in Serial1 (pins 4 & 5)
    Serial.write(Serial1.read());   // read it and send it out Serial (USB)
  }
}

calvsg88
Posts: 10
Joined: Tue Aug 09, 2022 7:54 am

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby calvsg88 » Thu Dec 29, 2022 7:36 am

hi,

I am developing a software in Arduino IDE for ESP32-C3.
I want to use UART1 to communicate with another device using AT command.

I've tried using SoftwareSerial and HardwareSerial but can't get it to work.
I just need to be able to send "AT?" and get a "OK" as reply.

Any help?

Codes:

// ESP32 C3 SERIAL1 (second UART)
HardwareSerial mySerial1(1);

int rxPin=5;
int txPin=4;

void setup()
{
Serial.begin(115200);
pinMode(txPin,OUTPUT);
pinMode(rxPin,INPUT);

mySerial1.begin(115200, SERIAL_8N1, rxPin, txPin);
}

void loop()
{
mySerial1.println("AT?");
//delay(100);
if (mySerial1.available())
{ // If anything comes in Serial1
while (mySerial1.available())
Serial.write(mySerial1.read()); // read it and send it out Serial (USB)
}

}


I have swapped the TX and RX pins but no avail.

Thanks for any suggestions.

calvsg88
Posts: 10
Joined: Tue Aug 09, 2022 7:54 am

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby calvsg88 » Thu Dec 29, 2022 9:52 am

Hi,

The UART1 (hardware UART) is not exposed on the pin out, so I can't use it.
Will have to use ESPSoftwareSerial to get data thru UART with another module.

Anyone got experience with ESPSoftwareSerial on ESP32-C3? It works well?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby ESP_Sprite » Fri Dec 30, 2022 2:53 am

calvsg88 wrote:
Thu Dec 29, 2022 9:52 am
The UART1 (hardware UART) is not exposed on the pin out, so I can't use it.
As with most peripherals, UART1 is configurable to use almost any GPIO the ESP32C3 has; just initialize it with the pins you want to use it on. If a pin is said to have a function wrt a peripheral, generally you can see that as the 'default' pin, not the pin that you mandatorily need to use it on.

calvsg88
Posts: 10
Joined: Tue Aug 09, 2022 7:54 am

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby calvsg88 » Fri Dec 30, 2022 10:09 pm

Thanks.

Have tried to use UART1 with all the GPIO pins, but nothing is coming back (tried the code on ESP32 Wroom and it was fine).

Am using ESP32-C3-WROOM-02-N4.

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby bidrohini » Sun Jan 01, 2023 5:28 pm


calvsg88
Posts: 10
Joined: Tue Aug 09, 2022 7:54 am

Re: How to use UART on ESP32-C3 devkitc-02 to read UART ultrasonic sensor

Postby calvsg88 » Mon Jan 02, 2023 4:06 am

hi,

thanks for the link.

I am able to flash the esp32-c3, but not able to get data from uart1.
NO matter which free pins I used for the hardware serial, i don't get any response.

I can see the data from uart0 (which are shown on the Arduino serial output console).

Who is online

Users browsing this forum: No registered users and 54 guests