CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-adafruit-blinka

CircuitPython APIs for non-CircuitPython versions of Python such as CPython on Linux and MicroPython.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

board-pins.mddocs/

Board Pin Definitions

Platform-specific pin mappings and hardware interfaces with automatic detection and configuration for 100+ supported development boards. Provides CircuitPython-compatible pin definitions and singleton interfaces with standardized naming conventions across diverse hardware platforms.

Capabilities

Pin Constants

Board-specific pin definitions that provide standardized names for GPIO pins, communication interfaces, and specialized functions. Pin constants are automatically imported based on detected hardware platform.

# Digital GPIO pins (board-specific availability)
D0: Pin          # Digital pin 0
D1: Pin          # Digital pin 1
D2: Pin          # Digital pin 2
# ... (continues up to board-specific maximum)

# I2C pins (if available)
SDA: Pin         # I2C data line
SCL: Pin         # I2C clock line

# SPI pins (if available)
MOSI: Pin        # SPI Master Out Slave In
MISO: Pin        # SPI Master In Slave Out
SCLK: Pin        # SPI clock
SCK: Pin         # SPI clock (alias)
CE0: Pin         # SPI chip enable 0
CE1: Pin         # SPI chip enable 1

# UART pins (if available)  
TX: Pin          # UART transmit
RX: Pin          # UART receive
TXD: Pin         # UART transmit (alias)
RXD: Pin         # UART receive (alias)

# Analog pins (platform-dependent)
A0: Pin          # Analog input 0
A1: Pin          # Analog input 1
# ... (if supported by platform)

Singleton Interface Functions

Pre-configured communication interfaces using default pin assignments. Automatically use board-appropriate pins for I2C and SPI communication.

def I2C() -> busio.I2C:
    """
    Return default I2C interface using board's SDA and SCL pins.
    
    Returns:
        busio.I2C: Pre-configured I2C interface
    
    Raises:
        AttributeError: If SDA/SCL pins not available on this board
    """

def SPI() -> busio.SPI:
    """
    Return default SPI interface using board's SCLK, MOSI, and MISO pins.
    
    Returns:
        busio.SPI: Pre-configured SPI interface
    
    Raises:
        AttributeError: If SPI pins not available on this board
    """

Board Identification

Constants that provide information about the Blinka library and board detection.

__version__: str = "0.0.0+auto.0"       # Blinka version string
__repo__: str = "https://github.com/adafruit/Adafruit_Blinka.git"  # Repository URL
__blinka__: bool = True                  # Always True for Blinka identification

Usage Examples

Basic Pin Usage

import board
import digitalio

# Use board-specific pin definitions
led = digitalio.DigitalInOut(board.D18)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.D2)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

# Read button and control LED
led.value = not button.value  # Inverted due to pull-up

# Cleanup
led.deinit()
button.deinit()

Default I2C Interface

import board
import time

# Use board's default I2C interface
i2c = board.I2C()

# Scan for devices
with i2c:
    devices = i2c.scan()
    print(f"I2C devices found: {[hex(d) for d in devices]}")

# Equivalent manual configuration
# i2c = busio.I2C(board.SCL, board.SDA)

i2c.deinit()

Default SPI Interface

import board
import digitalio

# Use board's default SPI interface
spi = board.SPI()

# Setup chip select
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OUTPUT
cs.value = True

# Use SPI with manual locking
while not spi.try_lock():
    pass

try:
    spi.configure(baudrate=1000000)
    
    # Communicate with device
    cs.value = False
    spi.write(b'\x01\x02\x03')
    cs.value = True
    
finally:
    spi.unlock()

# Cleanup
spi.deinit()
cs.deinit()

Pin Availability Checking

import board

# Check for I2C availability
if hasattr(board, 'SDA') and hasattr(board, 'SCL'):
    print("I2C pins available")
    print(f"SDA: {board.SDA}, SCL: {board.SCL}")
    
    # Use default I2C
    i2c = board.I2C()
    # ... use I2C
    i2c.deinit()
else:
    print("I2C not available on this board")

# Check for SPI availability  
if hasattr(board, 'SCLK') and hasattr(board, 'MOSI') and hasattr(board, 'MISO'):
    print("SPI pins available")
    print(f"SCLK: {board.SCLK}, MOSI: {board.MOSI}, MISO: {board.MISO}")
    
    # Use default SPI
    spi = board.SPI()
    # ... use SPI
    spi.deinit()
else:
    print("SPI not available on this board")

# Check for analog pins
analog_pins = [attr for attr in dir(board) if attr.startswith('A') and attr[1:].isdigit()]
if analog_pins:
    print(f"Analog pins available: {analog_pins}")
else:
    print("No analog pins available on this board")

Platform-Specific Pin Examples

import board

# Common pin usage patterns across platforms
def setup_common_pins():
    pins = {}
    
    # Try to setup LED (common pin numbers)
    for pin_name in ['D18', 'D13', 'D2', 'D25']:
        if hasattr(board, pin_name):
            pins['led'] = getattr(board, pin_name)
            break
    
    # Try to setup button
    for pin_name in ['D2', 'D0', 'D16']:
        if hasattr(board, pin_name) and pin_name != pins.get('led'):
            pins['button'] = getattr(board, pin_name)
            break
    
    return pins

# Get available pins for this board
available_pins = setup_common_pins()
print(f"Available pins: {available_pins}")

# Use pins if available
if 'led' in available_pins:
    import digitalio
    led = digitalio.DigitalInOut(available_pins['led'])
    led.direction = digitalio.Direction.OUTPUT
    # ... use LED
    led.deinit()

Multiple SPI Buses

import board
import busio

# Some boards support multiple SPI buses
# Primary SPI bus
spi0 = board.SPI()  # Uses SCLK, MOSI, MISO

# Secondary SPI bus (if available)
if hasattr(board, 'SCLK_1') and hasattr(board, 'MOSI_1') and hasattr(board, 'MISO_1'):
    spi1 = busio.SPI(board.SCLK_1, board.MOSI_1, board.MISO_1)
    print("Secondary SPI bus available")
    # ... use secondary SPI
    spi1.deinit()
else:
    print("Only primary SPI bus available")

spi0.deinit()

Board Information

import board
from adafruit_blinka.agnostic import board_id, detector

# Board identification
print(f"Blinka version: {board.__version__}")
print(f"Repository: {board.__repo__}")
print(f"Is Blinka: {board.__blinka__}")

# Platform detection information
print(f"Board ID: {board_id}")
print(f"Chip ID: {detector.chip.id}")

# List all available pins
pins = [attr for attr in dir(board) if not attr.startswith('_') and 
        attr not in ['I2C', 'SPI', '__version__', '__repo__', '__blinka__']]
print(f"Available pins: {sorted(pins)}")

# Categorize pins
digital_pins = [p for p in pins if p.startswith('D') and p[1:].isdigit()]
analog_pins = [p for p in pins if p.startswith('A') and p[1:].isdigit()]
special_pins = [p for p in pins if p not in digital_pins + analog_pins]

print(f"Digital pins: {sorted(digital_pins)}")
print(f"Analog pins: {sorted(analog_pins)}")
print(f"Special pins: {sorted(special_pins)}")

Platform Considerations

Supported Board Categories

Single Board Computers:

  • Raspberry Pi: All models from Pi 1 to Pi 5, including Compute Modules
  • BeagleBone: Black, Blue, Green, AI, PocketBeagle variants
  • Orange Pi: Full range including Zero, PC, 4, 5 series
  • Banana Pi: M2, M4, M5, F3, F5, AI series
  • Rock Pi: 3A, 3C, 4, 5, S, E variants
  • Jetson: TX1, TX2, Xavier, Nano, NX, Orin series
  • Odroid: C2, C4, N2, M1/M1S, XU4

Development Boards:

  • FTDI Adapters: FT232H, FT2232H, FT4232H for USB-to-GPIO
  • Microchip: MCP2221 USB-to-GPIO converter
  • Binho Nova: Multi-protocol USB adapter
  • GreatFET One: USB analysis and hacking tool

Specialized Platforms:

  • RP2040 via U2IF: Pico, Feather, QT Py, ItsyBitsy, MacroPad variants
  • Coral: Edge TPU development boards
  • UDOO: x86 boards with Arduino-compatible GPIO

Pin Naming Conventions

Standard Digital Pins: D0, D1, D2, ... (board-specific maximum)

Communication Pins:

  • I2C: SDA, SCL
  • SPI: MOSI, MISO, SCLK/SCK, CE0, CE1
  • UART: TX/TXD, RX/RXD

Analog Pins: A0, A1, A2, ... (platform-dependent availability)

Board-Specific Aliases: Many boards provide alternative names (e.g., GPIO18 vs D18)

Platform Detection

from adafruit_blinka.agnostic import detector, board_id

# Check platform capabilities
if detector.board.any_raspberry_pi:
    print("Running on Raspberry Pi")
elif detector.board.any_beaglebone:
    print("Running on BeagleBone")
elif detector.board.any_jetson_board:
    print("Running on NVIDIA Jetson")
elif detector.board.ftdi_ft232h:
    print("Using FTDI FT232H adapter")

# Board-specific features
if hasattr(board, 'A0'):
    print("Board supports analog input")
if hasattr(board, 'SDA'):
    print("Board supports I2C")
if hasattr(board, 'SCLK'):
    print("Board supports SPI")

Error Handling

import board

try:
    # Try to use I2C
    i2c = board.I2C()
    print("I2C interface created successfully")
    i2c.deinit()
except AttributeError:
    print("I2C pins not available on this board")

try:
    # Try to access specific pin
    pin = board.D18
    print(f"Pin D18 is available: {pin}")
except AttributeError:
    print("Pin D18 not available on this board")

# Safe pin access
def get_pin_safe(pin_name, default=None):
    """Safely get a pin, returning default if not available"""
    return getattr(board, pin_name, default)

led_pin = get_pin_safe('D18')
if led_pin:
    print(f"LED pin available: {led_pin}")
else:
    print("Default LED pin not available")

Install with Tessl CLI

npx tessl i tessl/pypi-adafruit-blinka

docs

analog-io.md

bitbangio.md

board-pins.md

communication.md

core-framework.md

digital-io.md

index.md

peripherals.md

pwm-pulse.md

utilities.md

tile.json