4. Firmware API Reference¶
This chapter describes modules (function and class libraries) which are built into MicroPython. There are a few categories of modules:
- Modules which implement a subset of standard Python functionality and are not intended to be extended by the user.
- Modules which implement a subset of Python functionality, with a provision for extension by the user (via Python code).
- Modules which implement MicroPython extensions to the Python standard libraries.
- Modules specific to a particular port and thus not portable.
Note about the availability of modules and their contents: This documentation in general aspires to describe all modules and functions/classes which are implemented in MicroPython. However, MicroPython is highly configurable, and each port to a particular board/embedded system makes available only a subset of MicroPython libraries. For officially supported ports, there is an effort to either filter out non-applicable items, or mark individual descriptions with “Availability:” clauses describing which ports provide a given feature. With that in mind, please still be warned that some functions/classes in a module (or even the entire module) described in this documentation may be unavailable in a particular build of MicroPython on a particular board. The best place to find general information of the availability/non-availability of a particular feature is the “General Information” section which contains information pertaining to a specific port.
Beyond the built-in libraries described in this documentation, many more modules from the Python standard library, as well as further MicroPython extensions to it, can be found in the micropython-lib repository.
4.1 Pycom Modules¶
machine— functions related to the board
- class ADC – analog to digital conversion
- class DAC – digital to analog conversion
- class I2C – a two-wire serial protocol
- class Pin – control I/O pins
- class PWM – Pulse width modulation
- class PWMChannel — control a PWM channel
- class RTC – real time clock
- class SPI – a master-driven serial protocol
- class UART – duplex serial communication bus
- class WDT – watchdog timer
- class Timer – measure time spans and set alarms
- class SD – Secure digital memory card
network— network configuration
- class WLAN
- class Server
- class Bluetooth
- class GATTCConnection
- class GATTCService
- class GATTCCharacteristic
- class GATTSService
- class GATTSCharacteristic
- class LoRa
- class Sigfox
- class AES - Advanced Encryption Standard
pycom– Pycom boards specific features
4.2 Micropython libraries¶
The following list contains the standard Python libraries, MicroPython-specific libraries and Pycom specific modules that are available on our boards.
The standard Python libraries have been “micro-ified” to fit in with the philosophy of MicroPython. They provide the core functionality of that module and are intended to be a drop-in replacement for the standard Python library.
micropython– access and control MicroPython internals
uctypes– access binary data in a structured way
sys– system specific functions
uos– basic “operating system” services
array– arrays of numeric data
cmath– mathematical functions for complex numbers
math– mathematical functions
gc– control the garbage collector
ubinascii– binary/ASCII conversions
ujson– JSON encoding and decoding
ure– regular expressions
usocket– socket module
select– wait for events on a set of streams
utime– time related functions
uhashlib– hashing algorithm
ussl– ssl module
ustruct– Pack and unpack primitive data types
_threadLow-level threading API
- Builtin Functions
Some modules are available by an u-name, and also by their non-u-name. The
non-u-name can be overridden by a file of that name in your package path.
import json will first search for a file
json and load that package if it is found. If nothing is found,
it will fallback to loading the built-in