Description
CircuitPython version
Adafruit CircuitPython 7.3.0-beta.0 on 2022-04-01; Adafruit Feather RP2040 with rp2040
Code/REPL
import board
import digitalio
import time
import busio
import supervisor
############################
"""CircuitPython Essentials UART possible pin-pair identifying script"""
"""
import board
import busio
from microcontroller import Pin
def is_hardware_uart(tx, rx):
try:
p = busio.UART(tx, rx)
p.deinit()
return True
except ValueError:
return False
def get_unique_pins():
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
pins = [pin for pin in [
getattr(board, p) for p in dir(board) if p not in exclude]
if isinstance(pin, Pin)]
unique = []
for p in pins:
if p not in unique:
unique.append(p)
return unique
for tx_pin in get_unique_pins():
print("start tx: ", tx_pin)
for rx_pin in get_unique_pins():
if rx_pin is tx_pin:
continue
if is_hardware_uart(tx_pin, rx_pin):
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)
##########################
"""
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
loop_count = 0
uart1 = busio.UART(board.D1, board.D0, baudrate=1000000)
uart2 = busio.UART(board.D25, board.D24, baudrate=1000000)
while True:
if supervisor.runtime.serial_bytes_available:
text = input()
print("*** Serial input ***", text)
b = bytearray()
b.extend(text)
uart1.write(b)
waiting_count = uart1.in_waiting
if waiting_count:
print("*** Uart1 input(", waiting_count, ") ***")
data = uart1.read(waiting_count)
uart2.write(data)
print("\t len:",len(data), "data:", data.decode())
waiting_count = uart2.in_waiting
if waiting_count:
print("*** Uart2 input(", waiting_count, ") ***")
data = uart2.read(waiting_count)
print("\t len:",len(data), "data:", data.decode())
led.value = True
time.sleep(0.2)
led.value = False
time.sleep(0.2)
led.value = True
led.value = True
time.sleep(0.2)
led.value = False
time.sleep(0.2)
led.value = True
led.value = True
time.sleep(0.2)
led.value = False
time.sleep(0.8)
loop_count += 1
if (loop_count & 0x1F) == 0:
print(loop_count)
Behavior
Au
5836
to-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 52, in
ValueError: Invalid pins
Code done running.
Description
I was curious if the issue I found with Teensy 4/4.1 would replicate with the RP2040, so
looking at the product page, I believe it has two UARTS and looking at the pin out diagram:
https://learn.adafruit.com/adafruit-feather-rp2040-pico/pinouts
It looked like D24 and D25 were valid for RX1/TX1, but when I tried it failed on the line...
Note: I then curious if any pins would work so went to the uart page:
https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial?gclid=Cj0KCQjw6J-SBhCrARIsAH0yMZjK2fy-7NfvWWWtwnJ0AteCGJzXWiwsAJxAXq2IplZnNILAEqKG7uoaArHCEALw_wcB
And copied in the code to detect valid rx/tx pins.
which is commented out in the above. but if I then remove it from comments and comment out the main code.
And ran it and received no output. So I put output line on the outer loop showing the tx pin being tried:
Output:
code.py output:
start tx: board.A0
start tx: board.A1
start tx: board.A2
start tx: board.A3
start tx: board.D0
start tx: board.D1
start tx: board.D10
start tx: board.D11
start tx: board.D12
start tx: board.D13
start tx: board.D24
start tx: board.D25
start tx: board.D4
start tx: board.D5
start tx: board.D6
start tx: board.D9
start tx: board.MISO
start tx: board.MOSI
start tx: board.SCK
start tx: board.SCL
start tx: board.SDA
Additional information
Sorry if this is a known issue..