XIAO C3 micropython: how to use USB serial and UART0/UART1 at the same time?

Hi, how to do this in micropython?:

Hello! You can read this document from the micropython.org: https://github.com/micropython/micropython/blob/master/docs/library/machine.Pin.rst, it mentioned how to init the pin mode, and then we know that this board have the UART0 21/20 pins and the UART1 with every two pins you choose, if you are using the usb serial you can using the serial of UART1 at the same time, just print the output from the uart if any message is well

I think the link I posted earlier shows how to use usb serial and the both HW uarts (scenario when you have 2 UART devices managed by ESP_C3). The article literally say: “As you can see, the XIAO ESP32C3 actually has three UARTs available.” So I wonder, how to accomplish in MP.

1 Like

Oh, I am sorry we do not have declare the interface resource of the C3 in the wiki or blog which may troubles you, thank you for feedback!

did you find a solution? I have the same problem

Hello, not yet. I am gonna workaround it with switching between 2 UART setups (different pins and speeds) that use the same HW uart.

hello,I tried it’s not terrible, in addition you have to play on waiting for an answer :frowning:

Hello, after receive your feedback we found you can set board with USB CDC mode and communicate with the computer, and then you can use the two UART interface, here is the tutorial: Pin Multiplexing | Seeed Studio Wiki

Here is the reference blog you can read: ESP32C3 USB & UART Download Mode_esp32 usb_25March的博客-CSDN博客

hello, you don’t understand the question, you post the same thing as him, the wiki we read it, the question is why under micropython only UART1 is available and not UART0?

Could I know your deploy situation? Because our UART0 of the board is connect with the DM/DP pins of the typec interface, so if you wanna flash the code into the board you must using the uart, USB CDC or WIFI OTA, so the previous two method you should use the one of the two uart interface, the last one is feasible for using two uart interface

hello, you do not understand the card is already flashed with micropython, so no problem with flashing, but a problem under micropython only one UART works it is UART 1 the other does not, it seems busy.

Hi , what about this ?

ESP 8266 ,The UART0 is by default attached to Web REPL. Using the UART0 for serial data communication 
must be first detached from REPL. UART0 can be detached from REPL using the following code snippet.
import os
os.dupterm(None, 1)

MicroPython allows multiplexing any GPIO with the hardware UARTs of ESP32.
Therefore, irrespective of which default pins are exposed or not, 
all three UARTs **can** be used in a MicroPython script. 
While instantiating a UART object for ESP32, the Rx and Tx pins should also be 
passed as arguments.

? idunno just a guess :slight_smile:
GL :slight_smile: PJ

Thank you for the answer, I will test it and let you know if it works.

unfortunately the “UART0” does not detach from the repl, here is a piece of script for the test, it does not work

"import os
from machine import UART

os.dupterm(None, 0)

uart = UART(0, baudrate=9600, tx=21, rx=20)

uart.write(“Hello”)

response = uart.read(10)

print("Response received: “, response)” no response.

and on “os.dupterm(None, 1)” I have an error: Traceback (most recent call last):
File “”, line 6, in
ValueError: invalid dupterm index.

Hi there,
I notice you don’t issue an OPEN uart to start the port ?
like this example?

import machine

# Create a UART object on UART0
uart0 = machine.UART(0, baudrate=115200) //<---- DEFAULT up port speed btw

# Create a UART object on UART1
uart1 = machine.UART(1, baudrate=115200)

# Open the UART objects
uart0.open()
uart1.open()

# Send a string to UART0
uart0.write("Hello, world!")

# Receive a string from UART1
data = uart1.read(10)

# Print the received string
print(data)

# Close the UART objects
uart0.close()
uart1.close()

What does your setup look like?
HTH
GL :slight_smile: PJ

Hi, can you point to open method of UART object? I cannot see any here: class UART – duplex serial communication bus — MicroPython latest documentation

UART in MicroPython does not have an “open” method, it must be called directly, like this: but the answer is “none”,I will return to circuitpython even if it has problems downloading the libraries or at least both UARTs work.

import machine

Create a UART object on UART0

uart0 = machine.UART(0, baudrate=9600)

Create a UART object on UART1

uart1 = machine.UART(1, baudrate=9600)

Send a string to UART0

uart0.write(“Hello, world!”)

Receive a string from UART1

data = uart1.read(10)

Print the received string

print(data)