Page 1 of 1

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

Posted: Fri Mar 18, 2022 12:48 pm
by sharanr15
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

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

Posted: Fri Apr 29, 2022 6:04 am
by drmpf321
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)
  }
}

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

Posted: Thu Dec 29, 2022 7:36 am
by calvsg88
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.

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

Posted: Thu Dec 29, 2022 9:52 am
by calvsg88
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?

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

Posted: Fri Dec 30, 2022 2:53 am
by ESP_Sprite
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.

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

Posted: Fri Dec 30, 2022 10:09 pm
by calvsg88
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.

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

Posted: Sun Jan 01, 2023 5:28 pm
by bidrohini

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

Posted: Mon Jan 02, 2023 4:06 am
by calvsg88
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).