Adafruit CircuitPython API Reference¶
Welcome to the API reference documentation for Adafruit CircuitPython. This contains low-level API reference docs which may link out to separate “getting started” guides. Adafruit has many excellent tutorials available through the Adafruit Learning System.
CircuitPython is a beginner friendly, open source version of Python for tiny, inexpensive
computers called microcontrollers. Microcontrollers are the brains of many electronics including a
wide variety of development boards used to build hobby projects and prototypes. CircuitPython in
electronics is one of the best ways to learn to code because it connects code to reality. Simply
install CircuitPython on a supported USB board usually via drag and drop and then edit a
file on the CIRCUITPY drive. The code will automatically reload. No software installs are needed
besides a text editor (we recommend Mu for beginners.)
Starting with CircuitPython 7.0.0, some boards may only be connectable over Bluetooth Low Energy (BLE). Those boards provide serial and file access over BLE instead of USB using open protocols. (Some boards may use both USB and BLE.) BLE access can be done from a variety of apps including code.circuitpython.org.
CircuitPython features unified Python core APIs and a growing list of 300+ device libraries and drivers that work with it. These libraries also work on single board computers with regular Python via the Adafruit Blinka Library.
CircuitPython is based on MicroPython. See below for differences. Most, but not all, CircuitPython development is sponsored by Adafruit and is available on their educational development boards. Please support both MicroPython and Adafruit.
Official binaries for all supported boards are available through circuitpython.org/downloads. The site includes stable, unstable and continuous builds. Full release notes are available through GitHub releases as well.
Guides and videos are available through the Adafruit Learning System under the CircuitPython category. An API reference is also available on Read the Docs. A collection of awesome resources can be found at Awesome CircuitPython.
Specifically useful documentation when starting out:
GitHub doesn’t currently support code search on forks. Therefore, CircuitPython doesn’t have code search through GitHub because it is a fork of MicroPython. Luckily, SourceGraph has free code search for public repos like CircuitPython. So, visit sourcegraph.com/github.com/adafruit/circuitpython to search the CircuitPython codebase online.
See CONTRIBUTING.md for full guidelines but please be aware that by contributing to this project you are agreeing to the Code of Conduct. Contributors who follow the Code of Conduct are welcome to submit pull requests and they will be promptly reviewed by project admins. Please join the Discord too.
While we are happy to see CircuitPython forked and modified, we’d appreciate it if forked releases not use the name “CircuitPython” or the Blinka logo. “CircuitPython” means something special to us and those who learn about it. As a result, we’d like to make sure products referring to it meet a common set of requirements.
If you’d like to use the term “CircuitPython” and Blinka for your product here is what we ask:
Your product is supported by the primary “adafruit/circuitpython” repo. This way we can update any custom code as we update the CircuitPython internals.
Your product has a user accessible USB plug which appears as a CIRCUITPY drive when plugged in AND/OR provides file and serial access over Bluetooth Low Energy. Boards that do not support USB should be clearly marked as BLE-only CircuitPython.
If you choose not to meet these requirements, then we ask you call your version of CircuitPython something else (for example, SuperDuperPython) and not use the Blinka logo. You can say it is “CircuitPython-compatible” if most CircuitPython drivers will work with it.
Differences from MicroPython¶
Supports native USB on most boards and BLE otherwise, allowing file editing without special tools.
Floats (aka decimals) are enabled for all builds.
Error messages are translated into 10+ languages.
Concurrency within Python is not well supported. Interrupts and threading are disabled. async/await keywords are available on some boards for cooperative multitasking. Some concurrency is achieved with native modules for tasks that require it such as audio file playback.
The order that files are run and the state that is shared between them. CircuitPython’s goal is to clarify the role of each file and make each file independent from each other.
boot.pyruns only once on start up before USB is initialized. This lays the ground work for configuring USB at startup rather than it being fixed. Since serial is not available, output is written to
main.py) is run after every reload until it finishes or is interrupted. After it is done running, the vm and hardware is reinitialized. This means you cannot read state from
code.pyin the REPL anymore, as the REPL is a fresh vm. CircuitPython’s goal for this change includes reducing confusion about pins and memory being used.
After the main code is finished the REPL can be entered by pressing any key.
Autoreload state will be maintained across reload.
Adds a safe mode that does not run user code after a hard crash or brown out. This makes it possible to fix code that causes nasty crashes by making it available through mass storage after the crash. A reset (the button) is needed after it’s fixed to get back into normal mode.
RGB status LED indicating CircuitPython state.
code.pyor other main file after file system writes over USB mass storage. (Disable with
Autoreload is disabled while the REPL is active.
Main is one of these:
Boot is one of these:
Unified hardware APIs. Documented on ReadTheDocs.
API docs are Python stubs within the C files in
No module aliasing. (
utimeare not available as
randomare CPython compatible.
storagemodule which manages file system mounts. (Functionality from
Modules with a CPython counterpart, such as
random, are strict subsets of their CPython version. Therefore, code from CircuitPython is runnable on CPython but not necessarily the reverse.
tick count is available as time.monotonic()
Here is an overview of the top-level source code directories.
The core code of MicroPython is shared amongst ports including CircuitPython:
docsHigh level user documentation in Sphinx reStructuredText format.
driversExternal device drivers written in Python.
examplesA few example Python scripts.
extmodShared C code used in multiple ports’ modules.
libShared core C code including externally developed libraries such as FATFS.
logoThe CircuitPython logo.
mpy-crossA cross compiler that converts Python files to byte code prior to being run in MicroPython. Useful for reducing library size.
pyCore Python implementation, including compiler, runtime, and core library.
shared-bindingsShared definition of Python modules, their docs and backing C APIs. Ports must implement the C API to support the corresponding module.
shared-moduleShared implementation of Python modules that may be based on
testsTest framework and test scripts.
toolsVarious tools, including the pyboard.py module.
Ports include the code unique to a microcontroller line.
stableHighly unlikely to have bugs or missing functionality.
betaBeing actively improved but may be missing functionality and have bugs.
alphaWill have bugs and missing functionality.
boardsdirectory containing boards which belong to a specific microcontroller line.
A list of native modules supported by a particular board can be found here.
Full Table of Contents¶
- Core Modules
_bleio– Bluetooth Low Energy (BLE) communication
_eve– Low-level BridgeTek EVE bindings
_pew– LED matrix driver
_stage– C-level helpers for animation of sprites on a stage
adafruit_bus_device– Hardware accelerated external bus access
adafruit_pixelbuf– A fast RGB(W) pixel buffer library for like NeoPixel and DotStar
aesio– AES encryption routines
alarm– Alarms and sleep
analogio– Analog hardware support
atexit– Atexit Module
audiobusio– Support for audio input and output over digital buses
audiocore– Support for audio samples
audioio– Support for audio output
audiomixer– Support for audio mixing
audiomp3– Support for MP3-compressed audio files
audiopwmio– Audio output via digital PWM
bitbangio– Digital protocols implemented by the CPU
bitmaptools– Collection of bitmap manipulation tools
bitops– Routines for low-level manipulation of binary data
board– Board specific pin names
busio– Hardware accelerated external bus access
camera– Support for camera input
canio– CAN bus access
countio– Support for edge counting
digitalio– Basic digital pin support
displayio– Native helpers for driving displays
dualbank– DUALBANK Module
floppyio– Read flux transition information into the buffer.
fontio– Core font related data structures
framebufferio– Native framebuffer display driving
frequencyio– Support for frequency based protocols
gamepadshift– Tracks button presses read through a shift register.
getpass– Getpass Module
gifio– Access GIF-format images
gnss– Global Navigation Satellite System
i2cperipheral– Two wire serial protocol peripheral
imagecapture– Support for “Parallel capture” interfaces
is31fl3741– Creates an in-memory framebuffer for a IS31FL3741 device.
keypad– Support for scanning keys and key matrices
math– mathematical functions
mdns– Multicast Domain Name Service
memorymonitor– Memory monitoring helpers
microcontroller– Pin references and cpu functionality
msgpack– Pack object in msgpack format
multiterminal– Manage additional terminal sources
neopixel_write– Low-level neopixel implementation
nvm– Non-volatile memory
onewireio– Low-level bit primitives for Maxim (formerly Dallas Semi) one-wire protocol.
os– functions that an OS normally provides
paralleldisplay– Native helpers for driving parallel displays
ps2io– Support for PS/2 protocol
pulseio– Support for individual pulse based protocols
pwmio– Support for PWM based protocols
qrio– Low-level QR code decoding
random– pseudo-random numbers and choices
rgbmatrix– Low-level routines for bitbanged LED matrices
rotaryio– Support for reading rotation sensors
rp2pio– Hardware interface to RP2 series’ programmable IO (PIO) peripheral.
rtc– Real Time Clock
samd– SAMD implementation settings
sdcardio– Interface to an SD card via the SPI bus
sdioio– Interface to an SD card via the SDIO bus
sharpdisplay– Support for Sharp Memory Display framebuffers
storage– Storage management
struct– Manipulation of c-style data
supervisor– Supervisor settings
synthio– Support for MIDI synthesis
terminalio– Displays text in a TileGrid
time– time and timing related functions
touchio– Touch related IO
traceback– Traceback Module
uheap– Heap size analysis
ulab– Manipulate numeric data similar to numpy
usb– PyUSB-compatible USB host API
usb_cdc– USB CDC Serial streams
usb_hid– USB Human Interface Device
usb_host– USB Host
usb_midi– MIDI over USB
ustack– Stack information and analysis
vectorio– Lightweight 2D shapes for displays
watchdog– Watchdog Timer
zlib– zlib decompression functionality
help()– Built-in method to provide helpful information
- Supported Ports
- SAMD21 and SAMD51
- CircuitPython port to Spresense
- CircuitPython on Espressif SoCs
- LiteX (FPGA)
- CircuitPython Port To The NXP i.MX RT10xx Series
- CircuitPython Port To The Nordic Semiconductor nRF52 Series
- Circuitpython on STM32
- Additional CircuitPython Libraries and Drivers on GitHub