2

Expected behavior:

in hardware I connect UART of a number 0/1 to the correct Pin numbers tx/rx and get it based on that connection

Actual behavior:

in hardware I connected UART of a number 0/1 to the correct Pin numbers tx/rx and got it on all of the related UARTs 0/1

I have this Array of UARTs where I can split them kinda like usb ports, and when I receive an input I get it from different indecies. to me it's a bit strange but it get's on all UART0 at once eventhough I'm connecting certain one only, or the same on all UART1.

ports = [ UART(0, 115200, timeout=0, tx=Pin(0), rx=Pin(1)), UART(1, 115200, timeout=0, tx=Pin(4), rx=Pin(5)), UART(1, 115200, timeout=0, tx=Pin(8), rx=Pin(9)), UART(0, 115200, timeout=0, tx=Pin(12), rx=Pin(13)), UART(0, 115200, timeout=0, tx=Pin(16), rx=Pin(17)) ] 

The code:

from machine import UART, Pin from time import time import re ports = [ UART(0, 115200, timeout=0, tx=Pin(0), rx=Pin(1)), UART(1, 115200, timeout=0, tx=Pin(4), rx=Pin(5)), UART(1, 115200, timeout=0, tx=Pin(8), rx=Pin(9)), UART(0, 115200, timeout=0, tx=Pin(12), rx=Pin(13)), UART(0, 115200, timeout=0, tx=Pin(16), rx=Pin(17)) ] def read_ports(): """Returns a list of ports with indecies that are receiving data""" port_list = [] for i,port in enumerate(ports): if port.any() > 0: port_list.append({ "port": port, "index": i }) return port_list request = [ bytes(), bytes(), bytes(), bytes(), bytes() ] while True: # Available Ports active_ports = read_ports() if len(active_ports) == 0: continue for uart in active_ports: index, port = uart["index"], uart["port"] byte = port.read(1) if byte == b'' or None or not byte: continue print("(index %d) (length %d) byte" % (index, len(request[index])), byte) request[index] += byte 

If I have UART0 connected all UART0 get the bytes at random.

I just don't get it why? and how to solve it? and if it's normal behavior what is the point of having all of these UART ports if I can't use one when I need many?

1 Answer 1

3

There are only two UARTS on the Pico. They are identified as the channel 0 UART and the channel 1 UART.

For convenience each UART is routed to multiple GPIO.

See the table I give at https://abyz.me.uk/picod/py_picod.html#serial_open

 channel:= the channel to open (0 or 1). tx:= the GPIO to use for transmit. channel 0: one of 0, 12, 16, 28, 255. channel 1: one of 4, 8, 20, 24, 255. rx:= the GPIO to use for receive. channel 0: one of 1, 13, 17, 29, 255. channel 1: one of 5, 9, 21, 25, 255. baud:= baud rate in bits per second, 120 to 4000000. cts:= the GPIO to use for CTS. channel 0: one of 2, 14, 18, 255. channel 1: one of 6, 10, 22, 26, 255. rts:= the GPIO to use for RTS. channel 0: one of 3, 15, 19, 255. channel 1: one of 7, 11, 23, 27, 255. 
3
  • That is eye opening for me, I'm still in the beginning of this and learning on a slow pace. as I understood it, there is only 2 channels in which Pico routes it to different GPIO pins. But is it possible to divide each in a fixed way and identify each pin pairs with a unique identifier? kinda like how any OS can identify each USB on it's own without confusing it with others? Commented Aug 29, 2022 at 15:18
  • There are only two UARTs. You can mix and match which GPIO make up those UARTs. You MIGHT be able to connect multiple devices to a single UART if you open/closed each serial device in turn. Commented Aug 29, 2022 at 15:31
  • that might be an option. thanks for your answer, I will see what is best, I wish I had more points to upvote your answer, but all I can do is mark it as correct, thanks again :) Commented Aug 29, 2022 at 15:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.