CircuitPython to list pin map

Many pins on CircuitPython compatible microcontroller boards have multiple names, however, typically, there's only one name labeled on the physical board. So how do you find out what the other available pin names are? Simple, with the following script! Each line printed out to the serial console contains the set of names for a particular pin.

ref:   CircuitPython Essentials > CircuitPython Pins and Modules > What Are All the Available Names?

# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""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 = []
        for alias in dir(board):
            if getattr(board, alias) is getattr(microcontroller.pin, pin):
                pins.append("board.{}".format(alias))
        if len(pins) > 0:
            board_pins.append(" ".join(pins))
for pins in sorted(board_pins):
    print(pins)


Here is the listed output of XIAO nRF52840 Sense running CircuitPython 8.1.0-beta.1.
board.A0 board.D0
board.A1 board.D1
board.A2 board.D2
board.A3 board.D3
board.A4 board.D4 board.SDA
board.A5 board.D5 board.SCL
board.CHARGE_RATE
board.CHARGE_STATUS
board.D10 board.MOSI
board.D6 board.TX
board.D7 board.RX
board.D8 board.SCK
board.D9 board.MISO
board.IMU_INT1
board.IMU_PWR
board.IMU_SCL
board.IMU_SDA
board.LED board.LED_RED
board.LED_BLUE
board.LED_GREEN
board.MIC_PWR
board.NFC1
board.NFC2
board.PDM_CLK
board.PDM_DATA
board.READ_BATT_ENABLE
board.VBATT


Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator