using ESP32 UART0 as serial communication port

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

using ESP32 UART0 as serial communication port

Post by nir_bec » Mon Aug 09, 2021 5:41 pm

Hi,
I'm trying to implement serial communication (tx & rx) through my PC USB using ESP32-WROOM32 board running build 'esp32-20210623-v1.16.bin'.
I prefer to use UART0 as the board already have the USB/Serial bridge and i don't need to connect external one.

I already searched the forum and found few possible solutions while disabling the REPL which i don't need as i'm writing the main.py file, but unfortunately nothing seems to work for me.

- tried uos.dupterm(None,1) , but i keep getting error message saying the UART0 port is dedicated to the REPL.

Is there any solution for this? or the only way will be to connect the extra USB/Serial bridge component to other UART?

EDIT:
I just found this post https://github.com/micropython/micropyt ... -390764291
using:
from machine import UART
uart=UART(1, tx=1, rx=3)

which seems to work, but the only way to use ampy after that in order to edit main.py on the board is to 'erase_flash' and rewrite the micropython build.
Is this the correct way? any alternatives?

Thank you!

nir_bec
Posts: 12
Joined: Mon Aug 09, 2021 10:38 am

Re: using ESP32 UART0 as serial communication port

Post by nir_bec » Mon Aug 09, 2021 6:42 pm

in case it is possible to reattach the repl to UART0 possible solution can be:

Code: Select all

from machine import UART
import time
uart = UART(1, baudrate=115200, tx=1, rx=3)

while True:
    data = uart.any()
    if data:
        data = uart.read()
        if data == b'reset':
            uart = UART(0, baudrate=115200, tx=1, rx=3)
        else:
            uart.write(data)

    time.sleep(0.5)
so by sending 'reset' the repl will be re-attached.
unfortunately 'uart = UART(0, baudrate=115200, tx=1, rx=3)' not returns the repl to work..

Post Reply