EasyManua.ls Logo

Adafruit Feather M4 Express - Trinket M0: Create UART before I2 C

Adafruit Feather M4 Express
178 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Trinket M0: Create UART before I2C
On the Trinket M0 (only), if you are using both busio.UART and busio.I2C , you must create the UART object first, e.g.:
>>> import board,busio
>>> uart = busio.UART(board.TX, board.RX)
>>> i2c = busio.I2C(board.SCL, board.SDA)
Creating busio.I2C first does not work:
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():
for rx_pin in get_unique_pins():
if rx_pin is tx_pin:
continue
else:
if is_hardware_uart(tx_pin, rx_pin):
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)
else:
pass
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 150 of 183

Table of Contents

Related product manuals