Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to board object other Serial and I2c pin names #6273

Merged
merged 1 commit into from
Apr 10, 2022

Conversation

KurtE
Copy link

@KurtE KurtE commented Apr 10, 2022

While testing out this and the new MicroMod Teensy port, @mjs513
and myself found it desirable to have logical pin names for the
different Serial UART objects. It is a lot easier and clearer
to use and maintain to do something
like: uart4 = busio.UART(board.TX4, board.RX4)
than have to go look up the pin numbers for each board.

So we added them to the pins.c file in both the teensy40 and teensy41 directories

While testing out this and the new MicroMod Teensy port, @mjs513
and myself found it desirable to have logical pin names for the
different Serial UART objects.  It is a lot easier and clearer
to use and maintain to do something
like: uart4 = busio.UART(board.TX4, board.RX4)
than have to go look up the pin numbers for each board.
@KurtE
Copy link
Author

KurtE commented Apr 10, 2022

Here is an example sketch that I am using to test the different uarts, where I can use jumper wires to
connect the tx of one uart to rx of another and then when I type in something at terminal it tries to walk it through and the last uart you wish to test it tie it back to the rx of the first uart...

Warning, there is probably cleaner python code than this, but:

import time
import board
import busio
import supervisor
from digitalio import DigitalInOut, Direction, Pull

led = DigitalInOut(board.LED)
led.direction = Direction.OUTPUT

check_pin = DigitalInOut(board.D2)
check_pin.direction = Direction.INPUT
check_pin.pull = Pull.DOWN
uarts = None

last_check_value = check_pin.value

def CheckAndEchoUart(index, uart):
    waiting_count = uart.in_waiting
    if waiting_count:
        print("*** Uart", index, " input(", waiting_count, ") ***")
        data = uart.read(waiting_count)

        if (index == 0):
            print("Echoed back len:",len(data), "data:", data.decode())
        else:
            print(index,">>", data.decode())
            uart.write(data)

while True:
    if check_pin.value:
        if uarts == None:
            print("Initialize Uarts")
            uarts = []
            for index in range(9):
                tx_name = "TX"+str(index)
                rx_name = "RX"+str(index)
                if hasattr(board, tx_name):
                    tx_pin = getattr(board, tx_name)
                    rx_pin = getattr(board, rx_name)
                    uart = busio.UART(tx_pin, rx_pin, baudrate=5000000)
                    uarts.append(uart)
                    print("\tAdded: ",index, " TX:",tx_pin, " RX:", rx_pin)

            # we have not yet tried to iniatialize the uarts
        if supervisor.runtime.serial_bytes_available:
            text = input()
            print("*** Serial input ***", text)
            b = bytearray()
            b.extend(text)
            #uart1.write(b)
            uarts[0].write(b)

        for index in range(len(uarts)):
            CheckAndEchoUart(index, uarts[index])
    # cycle colors
    if led.value:
        led.value = False
    else:
        led.value = True
    time.sleep(0.5)

@ladyada ladyada merged commit df74c68 into adafruit:main Apr 10, 2022
@KurtE KurtE deleted the t4x_board_dir_add_txrx_names branch April 10, 2022 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants