Adafruit PlatformDetect
Adafruit PlatformDetect is a Python library designed for best-guess platform detection across a wide range of single-board computers (SBCs) and other platforms. It primarily serves as a core dependency for Adafruit-Blinka, enabling CircuitPython API emulation on CPython. The library maintains an active development cycle with frequent releases to add support for new boards and chips.
Common errors
-
NotImplementedError: Adafruit-PlatformDetect version X.Y.Z was unable to identify the board and/or microcontroller running the [PLATFORM] platform.
cause The Adafruit-PlatformDetect library is an older version that does not include detection logic for your specific board or microcontroller, or the platform is genuinely unsupported.fixUpgrade to the latest version of adafruit-platformdetect and adafruit-blinka: `pip install --upgrade adafruit-platformdetect adafruit-blinka`. If the problem persists, open a 'New Board Request' issue on the Adafruit Blinka GitHub repository. -
ModuleNotFoundError: No module named 'adafruit_platformdetect'
cause The `adafruit-platformdetect` package is not installed in the Python environment where the script is being executed, or it was installed incorrectly (e.g., using `sudo pip` and running as a different user).fixEnsure the library is installed in your active Python environment: `pip install adafruit-platformdetect`. If using a virtual environment, make sure it is activated before installation and execution. If installed system-wide with `sudo`, ensure you run your script with `sudo` as well (though generally discouraged). -
RuntimeError: BLINKA_FT232H environment variable set, but no FT232H device found
cause The `BLINKA_FT232H` environment variable is set, forcing Adafruit-PlatformDetect to look for an FT232H device, but no such device is connected or detected by `pyftdi`.fixIf you are not using an FT232H, unset the `BLINKA_FT232H` environment variable. If you intend to use an FT232H, ensure it is properly connected and that `pyftdi` is installed (`pip install pyftdi`).
Warnings
- gotcha Platform detection can be overridden by environment variables like `BLINKA_FORCEBOARD` and `BLINKA_FORCECHIP`. This is primarily for testing or specific hardware setups (e.g., FT232H, SPIDriver). If these are set, they will bypass standard hardware detection.
- gotcha Running on new, unsupported hardware with an older version of adafruit-platformdetect can lead to `NotImplementedError` or 'Board not supported' messages.
- gotcha Incorrect installation methods (e.g., using `sudo pip install` then running as a normal user, or installing in a virtual environment and not activating it) can lead to `ModuleNotFoundError`.
Install
-
pip install adafruit-platformdetect
Imports
- Detector
from adafruit_platformdetect import Detector
Quickstart
import os
from adafruit_platformdetect import Detector
detector = Detector()
print(f"Chip ID: {detector.chip.id}")
print(f"Board ID: {detector.board.id}")
if detector.board.RASPBERRY_PI_3B_PLUS:
print("This is a Raspberry Pi 3B+")
elif detector.board.BEAGLEBONE_BLACK:
print("This is a BeagleBone Black")
elif detector.board.ORANGE_PI_PC:
print("This is an Orange Pi PC")
elif detector.board.GENERIC_LINUX_PC:
print("This is a generic Linux PC")
else:
print("Platform not specifically identified by common board checks.")
# Example of checking if a specific chip is present
if detector.chip.ANY_BROADCOM_CHIP:
print("Running on a Broadcom chip (like Raspberry Pi)")
# Example of forcing detection (for testing or specific setups)
# Uncomment and set an environment variable before running if needed
# os.environ['BLINKA_FORCEBOARD'] = 'GENERIC_LINUX_PC'
# os.environ['BLINKA_FORCECHIP'] = 'GENERIC_LINUX_CHIP'