Adafruit Blinka

9.0.4 · active · verified Thu Apr 16

Adafruit Blinka provides CircuitPython APIs for non-CircuitPython versions of Python, primarily CPython on Linux. It allows users to run CircuitPython code on single-board computers like the Raspberry Pi, Jetson Nano, and others. The library is actively maintained with frequent releases (multiple per month) to add support for new boards, fix board-specific import paths, and address underlying system library interactions. The current version is 9.0.4.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to blink an LED using Blinka's CircuitPython-like API. It initializes a digital output pin and toggles its state. Users must ensure Blinka is properly set up for their specific single-board computer, including installing necessary system dependencies and configuring user permissions for GPIO access. The `LED_PIN` variable must be adjusted to a valid pin name for the target board.

import board
import digitalio
import time

# Blinka requires an initial setup for your specific board.
# On a Raspberry Pi, ensure you've run the setup script or installed dependencies.
# Example: curl -sL https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py | sudo python3

# Choose a pin appropriate for your board. For Raspberry Pi, GPIO4 (physical pin 7) is common.
# Refer to your board's pinout or Blinka documentation for available pins.
# Common options: board.D4, board.D18, board.D21
LED_PIN = board.D4 # IMPORTANT: Adjust this to a valid GPIO pin for your specific board

try:
    # Initialize the digital output pin
    led = digitalio.DigitalInOut(LED_PIN)
    led.direction = digitalio.Direction.OUTPUT

    print(f"Blinking LED on pin {LED_PIN} (adjust pin for your board). Press Ctrl+C to exit.")
    while True:
        led.value = True  # Turn LED on
        time.sleep(0.5)
        led.value = False # Turn LED off
        time.sleep(0.5)
except AttributeError as e:
    print(f"Error accessing pin '{LED_PIN}': {e}")
    print("Ensure Blinka is correctly configured for your board and the pin exists.")
    print("Example: For Raspberry Pi, run 'export BLINKA_BOARD=RASPBERRY_PI_ZERO' before execution.")
except RuntimeError as e:
    print(f"Runtime error: {e}")
    print("This often indicates missing system dependencies or incorrect permissions.")
    print("Ensure libgpiod-dev, python3-libgpiod are installed and your user is in the 'gpio' group.")
    print("Try: 'sudo usermod -a -G gpio $(whoami)' and reboot.")
except KeyboardInterrupt:
    print("\nBlinking stopped.")
finally:
    # Clean up GPIO if necessary (DigitalInOut handles this on exit but explicit is good)
    if 'led' in locals() and isinstance(led, digitalio.DigitalInOut):
        led.deinit()

view raw JSON →