ESP32 - Getting serial port input

Hello all,

I’m using:

[options]
platform = espressif32@~6.1.0
board = esp32dev
framework =
    espidf
    arduino

& the sdkconfig contains:

CONFIG_ESP_CONSOLE_UART_DEFAULT=y
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_NONE is not set
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200

Whats the best (i.e. most straightforward way to get user input from the serial port (UART0)? I’ve looked at the console examples but they seem overkill, I don’t need any console interaction, just need to be able to get the user input & use it in my application.

I looked at Serial.read() (i.e. using the Arduino interface) but the serial output then gets polluted with lots of garbage.

Many thanks.

For anyone else, this sort of answers the question:

Generally, it is not recommended to use UART0 as a normal serial communication port, because it is the default LOG output port.

I’m going to try using UART1 only for RX, & UART0 only for TX & see how that goes.

It turns out that using UART0 ‘on top’ of the console is satisfactory.

One of my issues was using the incorrect clock for UART0 which resulted in garbled input, using the followoing fixed it:

.source_clk = UART_SCLK_REF_TICK,

The only remaining issue I have is that as soon as the ESP32 enters light sleep I get a constant stream of rubbish output:

I (186194) UART_TEST: [DATA EVT]: �
I (186296) UART_TEST: [DATA EVT]: �
I (186320) UART_TEST: [DATA EVT]: �
I (186399) UART_TEST: [DATA EVT]: �
I (186501) UART_TEST: [DATA EVT]: �
I (186604) UART_TEST: [DATA EVT]: �
I (186705) UART_TEST: [DATA EVT]: �
I (186805) UART_TEST: [DATA EVT]: �

My code is based on this example from espressif.

Found the issue, in the skdconfig the following was enabled

CONFIG_PM_SLP_DISABLE_GPIO=y

This disables GPIO pins during sleep. Commenting it out resolved the issue.

1 Like