Adafruit PlatformDetect
raw JSON → 3.88.0 verified Thu Apr 16 auth: no python
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.
pip install adafruit-platformdetect Common errors
error 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.
fix
Upgrade 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. error 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).
fix
Ensure 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). error 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`.
fix
If 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. ↓
fix Be aware of these environment variables if detection results are unexpected. Unset them if not intentionally used, or consult `adafruit_platformdetect/chip.py` and `adafruit_platformdetect/board.py` for their effects.
gotcha Running on new, unsupported hardware with an older version of adafruit-platformdetect can lead to `NotImplementedError` or 'Board not supported' messages. ↓
fix Always ensure you have the latest version installed: `pip install --upgrade adafruit-platformdetect adafruit-blinka`.
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`. ↓
fix Always install either for the current user (`pip install adafruit-platformdetect`) or within an activated virtual environment. Avoid `sudo pip install` unless absolutely necessary for system-wide installations and understand the implications.
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'