Adsense HTML/JavaScript

Saturday, March 19, 2022

Nano RP2040 Connect/CircuitPython: list pins name of GPIOs

Many pins on CircuitPython compatible microcontroller boards have multiple names, however, typically, there's only one name labeled on the physical board. This example (modified from CircuitPython on the Arduino Nano RP2040 Connect > CircuitPython Pins and Modules > What Are All the Available Names?) run on Arduino Nano RP2040 Connect/CircuitPython 7.2.3 to list available pin names for all GPIOs.

"""CircuitPython Essentials Pin Map Script"""
import microcontroller
import board

board_pins = []
for pin in dir(microcontroller.pin):
    if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
        pins = []
        
        pins.append("microcontroller.{}".format(pin))
        pins.append('\t-')
        
        for alias in dir(board):
            if getattr(board, alias) is getattr(microcontroller.pin, pin):
                pins.append("board.{}\t".format(alias))
        if len(pins) > 0:
            board_pins.append(" ".join(pins))
for pins in sorted(board_pins):
    print(pins)




No comments:

Post a Comment