Convert MicroPython to CircuitPython: The Safe Porting Guide 🤖

You can convert MicroPython to CircuitPython, but there’s no reliable one-click converter: keep your portable Python logic and adapt the board-specific hardware code, libraries, and startup behavior. Before you begin, confirm that CircuitPython supports your exact board and the sensors, motors, and other peripherals your project needs.

The runtimes share a Python heritage, so a robot’s calculations or state machine may need only small changes. The surprise usually arrives at the pins: code using machine.Pin, PWM, or I2C often needs CircuitPython’s digitalio, pwmio, or busio APIs instead.

We’ve seen a promising sensor driver become the day’s main character simply because it expected a different I2C interface. Port one peripheral at a time, test it on the actual board, and you’ll catch mismatches before your rover starts behaving like the floor plan is merely a suggestion.

Key Takeaways

  • There’s no universal automatic converter. Treat migration as a code port, not a firmware file swap.
  • Check board and library support first. A CircuitPython build and compatible drivers must exist for your exact hardware.
  • Keep portable logic separate from hardware code. This makes the project easier to test and maintain across runtimes.
  • Expect to adapt GPIO, PWM, ADC, buses, and startup files. CircuitPython commonly uses digitalio, pwmio, analogio, busio, and code.py.
  • Test one hardware feature at a time. Start with a simple GPIO test, then add sensors, motors, and networking.
  • Blinka is a compatibility option, not a universal converter. It can support some CircuitPython libraries on specific MicroPython setups, but compatibility depends on the board and library.

Table of Contents


Table of Contents

⚡️ Quick Tips and Facts

If you’re searching for whether MicroPython is compatible with CircuitPython, the short version is: they share Python roots, but they are not drop-in substitutes. Converting a project usually means adapting its hardware APIs, drivers, startup behavior, and board configuration—not running a magic translator.

Quick fact What it means for your project
CircuitPython is derived from MicroPython Many Python language features feel familiar, but hardware APIs and supported modules can differ.
Firmware must support your exact board Check the official CircuitPython downloads before planning a port.
MicroPython’s machine APIs often need rewriting CircuitPython commonly uses modules such as board, digitalio, analogio, and busio.
CircuitPython commonly runs code.py from a USB-visible drive This makes editing convenient, but the drive and filesystem workflow differ from typical MicroPython setups.
Libraries are not automatically interchangeable Check the library’s implementation, dependencies, and board support before copying it over.
Blinka is a compatibility layer, not a conversion tool It can help run some CircuitPython libraries on supported MicroPython hardware, but it does not turn MicroPython firmware into CircuitPython.

Our practical recommendation: port one hardware feature at a time. Start with a small GPIO test, then bring up sensors, motors, networking, and the main application in stages. In robotics, changing the firmware and all your drivers at once is a fine way to make a working rover mysteriously become a very expensive paperweight. 🤖

We’ve found that the most useful early question is not “How do I convert every line?” It’s “Which layer is actually tied to MicroPython?” Pure Python logic may need little or no change; pin setup and peripheral drivers usually need the attention.

🧭 What “Converting MicroPython to CircuitPython” Really Means


Video: #240 Time to Say Goodbye to Arduino and Go On to Micropython/ Adafruit Circuitpython?








There is no single universal convert-micropython-to-circuitpython command. Most projects involve porting Python application code and hardware access to a CircuitPython firmware build that supports your board.

A useful way to picture the work is as three layers:

Project layer Typical migration effort Examples
General Python logic Low Calculations, state machines, data formatting
Runtime and system behavior Medium Startup scripts, file handling, timing, networking
Hardware and board-specific code Medium to high GPIO, PWM, I2C, SPI, UART, sensor drivers

For example, code that calculates a robot’s steering correction may transfer almost unchanged. Code that creates a machine.Pin, configures PWM, or imports a MicroPython-only sensor driver is more likely to need adaptation.

The goal is usually one of these:

  • Move the whole project to CircuitPython to use its board support, library ecosystem, USB workflow, or tutorials.
  • Port one or more drivers so they work with CircuitPython hardware APIs.
  • Keep MicroPython firmware and use an appropriate compatibility layer or reimplementation.
  • Share the portable logic between both runtimes while maintaining separate hardware back ends.

That last option is often the best engineering choice for a robotics project. Put motion planning and sensor interpretation in ordinary Python modules, then isolate firmware-specific I/O in small files. You get two runtimes without turning every future feature into a code fork. Our broader coding-language guides cover this kind of separation of concerns.

📚 MicroPython vs. CircuitPython: Key Differences


Video: CircuitPython – The easiest way to program microcontrollers.








Both runtimes let you write Python-style code for microcontrollers, but their design choices lead to different workflows. CircuitPython emphasizes consistent hardware APIs and a beginner-friendly editing experience. MicroPython supports a wider range of ports and offers a more general-purpose approach, with APIs and capabilities that can vary by port and board. Consult the official MicroPython documentation and CircuitPython documentation for the specifics of your target.

Area MicroPython CircuitPython Migration takeaway
Board support Many ports and boards; capabilities vary Board-specific builds and APIs; support is listed by board Verify the exact board and peripheral support first
Common GPIO API Often machine.Pin Commonly board and digitalio Rewrite pin setup and reads/writes
I2C and SPI Commonly under machine Commonly busio Adapt bus construction, pins, and locking
PWM Often machine.PWM Commonly pwmio.PWMOut Recheck frequency, duty-cycle range, and pin support
Analog input Often machine.ADC Commonly analogio.AnalogIn Adjust scaling and verify analog-capable pins
USB file workflow Depends on board and firmware setup Typically exposes a CIRCUITPY drive on supported boards Understand drive behavior and safe editing
Libraries MicroPython-specific modules and packages CircuitPython library bundle and Board Support Packages Check each driver’s compatibility rather than trusting its name
Startup conventions Often uses files such as boot.py and main.py Typically runs code.py, with boot.py for early setup Move entry-point logic deliberately
Hardware documentation May differ by port and board Consistent API style is a central design goal CircuitPython can simplify portable hardware code, but not every board feature is exposed

A video perspective sometimes gets repeated inaccurately: CircuitPython is not made by Arduino. It is an Adafruit-led open-source project derived from MicroPython. The video summary’s claim that both are based on Python is broadly right; its attribution to Arduino is not. For project history and supported boards, trust the official CircuitPython project site and Adafruit’s documentation, not a mistaken spoken line.

What tends to stay the same? Python syntax, many standard programming concepts, and plain logic. What tends to change? The hardware interface, available modules, board pin names, and assumptions about startup and storage.

🕰️ How MicroPython and CircuitPython Evolved


Video: CircuitPython with Raspberry Pi Pico – Getting Started.








MicroPython brought a lean Python implementation to microcontrollers. CircuitPython began as a fork of MicroPython, with Adafruit focusing on a consistent, approachable experience for supported boards and hardware projects. That shared history explains why code can look familiar while still requiring API changes.

A helpful analogy: they are cousins who inherited the same family recipes, but one has a different kitchen layout. You may recognize the ingredients; the drawers, appliances, and labels have changed.

CircuitPython’s design priorities include a consistent hardware API, straightforward file editing on supported boards, and a large collection of hardware libraries. MicroPython’s broad set of ports makes it attractive when you need a particular platform, low-level capability, or an established MicroPython ecosystem. Neither is universally “better”—the best fit depends on your board, libraries, and project constraints.

The key historical detail for a conversion is that shared ancestry does not guarantee API compatibility. A driver that imports machine or relies on a MicroPython port-specific feature may not work unchanged in CircuitPython.

🔍 Can You Automatically Convert MicroPython Code to CircuitPython?


Video: CircuitPython · 6/7 · CircuitPython vs MicroPython.







Not reliably as a whole project. A text editor can replace simple patterns, but it cannot safely infer which pins exist on your board, how a sensor driver handles its bus, or whether a MicroPython-specific feature has a CircuitPython equivalent.

Automatic search-and-replace is risky for cases such as:

  • machine.Pin becoming digitalio.DigitalInOut: construction and direction settings are different.
  • machine.PWM becoming pwmio.PWMOut: duty-cycle ranges and supported pins need verification.
  • machine.I2C becoming busio.I2C: bus initialization and locking differ.
  • time.sleep_ms() becoming a different timing call: code may depend on millisecond precision or scheduling behavior.
  • A library import appearing to match while its internal APIs or dependencies do not.

You can automate some housekeeping with scripts, tests, or linting, but treat those assistants—not migration engineers. A safer workflow is:

  1. Separate pure Python logic from hardware access.
  2. Search for MicroPython-specific imports and methods.
  3. Port one peripheral at a time.
  4. Run a small test on the real target board.
  5. Keep a known-good firmware image and project backup.

For reusable projects, a small hardware abstraction layer can save repeated work:

# hardware_interface.py
def read_distance_cm():
 raise NotImplementedError
``

Then create separate implementations for each runtime, while keeping your robot’s navigation logic independent of either. It’s less glamorous than a one-click converter, but it’s much easier to debug at 2 a.m. beside a robot that insists the wall is “probably optional.”

## 🧰 Before You Migrate: Check Your Board, Firmware, and Dependencies

Before changing firmware, make a short compatibility inventory. This is where you avoid the classic mistake: porting the code perfectly for a board that does not have a supported CircuitPython build.

### Board and chip compatibility

Write down the exact board name and revision—not just the chip family. Two boards built around the same microcontroller can expose different pins, onboard sensors, USB behavior, memory, or peripheral wiring.

Check:

- The board’s official product or manufacturer page.
- Whether a CircuitPython build is listed in the [downloads directory](https://circuitpython.org/downloads).
- Which pins are available for digital I/O, analog input, PWM, I2C, SPI, and UART.
- Whether your motor driver, display, radio, or sensor is supported by a compatible library.
- Any board-specific limitations noted in the firmware release or library documentation.

For robotics projects with multiple sensors, start a pin map before touching code. A table in your README can prevent the “SDA is on which header again?” ritual.

### Choosing the right CircuitPython build

Use the build for the **exact board model** whenever it exists. The board module defines convenient pin names, and board-specific firmware may include configuration needed for onboard hardware. Start from [CircuitPython’s download page](https://circuitpython.org/downloads) and follow the board manufacturer’s installation directions.

Keep these details together:

| Item to record | Why it matters |
|---|---|
| Board model and revision | Determines firmware and pin definitions |
| CircuitPython version | Helps reproduce library and API behavior |
| Library bundle version | Libraries should be matched to the runtime |
| Firmware file name | Useful when restoring or comparing builds |
| USB drive label and mount behavior | Helps diagnose file and boot problems |

Do not assume a generic firmware build is interchangeable with a board-specific one. If a feature depends on an onboard device or special pin mapping, the right build can make the difference between a clean boot and a confusing import or pin error.

### Back up your files and identify MicroPython-specific code

Back up your project, existing firmware, configuration, and any files stored on the board. Then search the codebase for likely MicroPython dependencies:

```text
machine
machine.Pin
machine.PWM
machine.ADC
machine.I2C
machine.SPI
machine.UART
time.sleep_ms
time.ticks_ms
uos
ujson
``

This list is a starting point, not a complete audit. Some names may have equivalents; others may be available in your target CircuitPython build, but differ in behavior. Check the [CircuitPython module documentation](https://docs.circuitpython.org/en/latest/shared-bindings/index.html) and the relevant MicroPython port docs.

Also inventory external libraries:

- Which are pure Python?
- Which import `machine`, `uasyncio`, `uos`, or other MicroPython-specific modules?
- Which control a particular sensor, display, motor controller, or radio?
- Are there CircuitPython versions, or will you need to port the driver?

For sensor-heavy builds, link each device to its driver and bus in your notes. Our [robotic sensors category](https://roboticcoding.com/category/robotic-sensors/) is a useful starting point for planning those hardware relationships.

## 🔄 How to Convert MicroPython to CircuitPython: 10 Migration Steps

Think of this as a controlled port, not a bulk file copy. The order below moves from the firmware foundation to application behavior, so each test tells you something useful.

### 1. Install CircuitPython on your board

1. Find your exact board in the [CircuitPython downloads](https://circuitpython.org/downloads).
2. Read the manufacturer’s board-specific flashing instructions.
3. Enter the board’s bootloader mode as documented.
4. Copy or flash the correct CircuitPython firmware.
5. Wait for the board to restart, then confirm the firmware starts without a persistent error.

Firmware installation methods differ. Some boards appear as a bootloader drive where you copy a UF2 file; others need a different flashing process. Follow the instructions for your board rather than borrowing a procedure from a superficially similar one.

If the board does not reboot as expected, stop and verify its model and bootloader procedure before repeatedly flashing it.

### 2. Confirm the CIRCUITPY drive appears

On many supported CircuitPython boards, a USB storage drive named `CIRCUITPY` appears after startup. The [CircuitPython essentials guide](https://learn.adafruit.com/circuitpython-essentials/circuitpython-essentials) explains the common workflow.

Before transferring your project:

- Check that the drive mounts and can be read.
- Open the serial console and confirm the CircuitPython version.
- Use a minimal test file if required by the board’s setup.
- Avoid simultaneous writes from multiple tools.

**Important:** the USB drive is a real filesystem on the device. Unpluging or resetting during a write can damage files, and the board may not be able to safely share the filesystem with a computer while code is modifying it. Follow CircuitPython’s [USB drive guidance](https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage) for the right workflow.

### 3. Move your main script to `code.py`

A common CircuitPython entry point is `code.py`. Copy your application there after confirming the board and drive work.

A simple project layout might be:

```text
CIRCUITPY/
├── code.py
├── settings.toml
└── lib/
 ├── adafruit_display_text/
 └── adafruit_bus_device/
``

The exact contents depend on your build and project. Keep startup configuration separate from normal application code when appropriate, and consult the [CircuitPython documentation](https://docs.circuitpython.org/en/latest/docs/index.html) before relying on a particular boot behavior.

Do not blindly rename a large MicroPython `main.py` and expect it to work. First remove or adapt hardware imports and startup assumptions so an error in one section does not obscure every other issue.

### 4. Replace board-specific pin definitions

MicroPython code may refer to pins by numbers or port-specific names. CircuitPython builds commonly offer named pins through `board`.

MicroPython:

```python
from machine import Pin

led = Pin(25, Pin.OUT)
``

CircuitPython:

```python
import board
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
``

`board.LED` is an example, not a universal pin name. Your board may expose a different name—or no onboard LED at all. Check its board module and pinout in the [CircuitPython downloads and documentation](https://circuitpython.org/downloads).

**Robotics tip:** create a pin map with signal name, physical connection, voltage, and CircuitPython identifier. That makes later hardware changes much less error-prone.

### 5. Update GPIO and digital I/O code

CircuitPython’s `digitalio.DigitalInOut` replaces many common uses of `machine.Pin`. You explicitly configure direction and pull resistors, then read or write the `.value` property.

For example:

```python
import board
import digitalio

button = digitalio.DigitalInOut(board.D5)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
``

Check active-low logic carefully. A button connected between a pin and ground with a pull-up resistor often reads `False` when pressed. A motor-driver enable line may also be active-low, so switching runtimes is a good time to label logic levels clearly.

Release resources where needed:

```python
led.deinit()
button.deinit()
``

Leaving objects open can matter when you reconfigure pins or buses. For interrupt handling, timing-critical signals, and port-specific GPIO features, consult the board documentation before assuming a direct equivalent exists.

### 6. Adapt analog input, PWM, and timing

Analog input commonly moves from `machine.ADC` to `analogio.AnalogIn`:

```python
import board
import analogio

sensor = analogio.AnalogIn(board.A0)
raw = sensor.value
volts = (raw * 3.3) / 65535
``

The example’s voltage calculation assumes a 3.3 V reference and a corresponding full-scale reading. **Check your board’s ADC resolution, input limits, reference voltage, and pin support** before using it in a real design.

PWM commonly uses `pwmio.PWMOut`:

```python
import board
import pwmio

motor_enable = pwmio.PWMOut(
 board.D5,
 frequency=100,
 duty_cycle=0
)

motor_enable.duty_cycle = 32768
``

CircuitPython’s PWM duty cycle is represented on a 16-bit scale from `0` to `65535`; MicroPython PWM APIs may use a different range or method. Recheck the motor driver’s requirements, PWM frequency, and board support. For servos, many CircuitPython projects use a compatible servo library such as [Adafruit’s ServoKit](https://docs.circuitpython.org/projects/servokit/en/latest/), but the board, PWM hardware, and servo power supply all matter.

Timing needs the same care:

- Replace MicroPython-only helpers such as `sleep_ms()` or `ticks_ms()` with documented CircuitPython APIs.
- Avoid long blocking sleeps in control loops that must respond to sensors.
- Use monotonic time for elapsed-time calculations when available.
- Measure actual loop behavior; do not assume two runtimes schedule work identically.

A rover that reads an obstacle sensor only after a long blocking delay is less “autonomous robot” and more “robot with a strong opinion about waiting.”

### 7. Replace I2C, SPI, and UART setup

CircuitPython commonly uses `busio` for hardware buses. On a board with board-defined bus pins, I2C setup often looks like:

```python
import board
import busio

i2c = busio.I2C(board.SCL, board.SDA)
``

Some boards provide helpers such as `board.I2C()`; use the documented option for that board. An I2C bus may need to be locked while scanning or communicating. Consult the [CircuitPython bus documentation](https://docs.circuitpython.org/en/latest/shared-bindings/busio/index.html) and driver examples.

A diagnostic scan can help confirm wiring, but use the correct locking pattern for your CircuitPython version. A typical approach is:

```python
while not i2c.try_lock():
 pass

try:
 print([hex(address) for address in i2c.scan()])
finally:
 i2c.unlock()
``

For SPI and UART, the exact construction depends on the pins and board. Before moving a sensor driver, verify:

- SDA/SCL or MOSI/MISO/SCK pin mapping.
- Pull-up resistors for I2C where required.
- Chip-select wiring for SPI.
- UART transmit/receive crossing and baud rate.
- Bus frequency, device voltage, and logic levels.

A successful bus scan confirms that something answered at an address; it does **not** prove the driver, power supply, or sensor configuration is correct.

### 8. Port displays, sensors, and other peripherals

Drivers are where migration effort varies the most. Start by searching for an existing CircuitPython library on the [CircuitPython libraries page](https://circuitpython.org/libraries) or in Adafruit’s [CircuitPython library documentation](https://docs.circuitpython.org/en/latest/docs/index.html).

For each device:

1. Identify its bus: GPIO, I2C, SPI, UART, or another interface.
2. Check the driver’s supported runtime and board assumptions.
3. Install its dependencies in the board’s `lib` directory as directed.
4. Match the driver version to your CircuitPython firmware.
5. Run the library’s simplest example before integrating your robot’s logic.
6. Compare returned units, error behavior, and initialization steps with the old driver.

**Do not choose a driver solely because the sensor name matches.** Two libraries for the same chip may differ in supported bus APIs, device features, or calibration handling.

For a project combining Adafruit’s PA1010 GPS driver with a MicroPython-only MS5637 driver, the practical options are to find a compatible CircuitPython MS5637 driver, port the MicroPython driver, keep the project on MicroPython and evaluate Blinka’s supported workflow, or split the software across devices. A community discussion about this sort of mismatch suggested Blinka as a possible route, but the discussion did not provide a complete reverse-port recipe. That’s a useful clue—not proof that every combination works.

### 9. Install and update CircuitPython libraries

CircuitPython libraries are generally copied to the board’s `lib` folder, but dependencies matter. The official [library bundle information](https://circuitpython.org/libraries) helps you find libraries and compatible bundles.

A sensible library workflow:

- Download a library bundle that matches your CircuitPython release guidance.
- Copy only the required library folders and dependencies.
- Keep the directory structure intact.
- Check free space on the device before copying.
- Use small, targeted libraries on constrained boards.
- Record library versions so a future update is reproducible.

If the import fails, verify the file path and capitalization first. Then check the library’s own requirements and whether its dependency modules are installed. Copying every library into `lib` may seem reassuring, but it consumes storage and makes dependency errors harder to diagnose.

### 10. Test, debug, and optimize the migrated project

Test in layers:

1. Firmware boots.
2. `code.py` runs a simple print statement.
3. One output pin works.
4. One input pin reads correctly.
5. Each peripheral initializes separately.
6. The full robot operates with motors disabled or wheels raised.
7. Safety and recovery behavior works under realistic conditions.

Use the serial console to capture the first traceback. CircuitPython’s [serial console guide](https://learn.adafruit.com/welcome-to-circuitpython/advanced-serial-console-on-mac-and-linux) and [Troubleshooting guide](https://learn.adafruit.com/welcome-to-circuitpython/troubleshooting) are practical references.

For robotics, add tests beyond “it compiled”:

- Verify emergency stop behavior.
- Confirm motors default to a safe state at boot.
- Test sensor disconnects and invalid readings.
- Check how the robot behaves after a reset.
- Measure loop timing under the full library load.
- Test battery voltage and power noise separately from USB power.

A board that boots on a laptop may behave differently on battery power once motors start. That is not necessarily a Python bug; power and grounding deserve their own inspection.

## 💻 MicroPython-to-CircuitPython Code Examples

The snippets below show common patterns, but pin names and features are board-specific. Confirm each one against your board’s pinout and the [CircuitPython API reference](https://docs.circuitpython.org/en/latest/shared-bindings/index.html).

### Blink an LED

MicroPython:

```python
from machine import Pin
from time import sleep

led = Pin(25, Pin.OUT)

while True:
 led.toggle()
 sleep(0.5)
``

CircuitPython:

```python
import time
import board
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
 led.value = not led.value
 time.sleep(0.5)
``

The `board.LED` pin is not guaranteed on every board. If your board does not define it, use an available digital pin and an external LED with an appropriate resistor.

### Read a button with a pull-up resistor

```python
import time
import board
import digitalio

button = digitalio.DigitalInOut(board.D5)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

while True:
 if not button.value:
 print("Button pressed")
 time.sleep(0.02)
``

A pull-up setup usually means the input is high when idle and low when the button connects it to ground. Add **debouncing** if your application needs reliable press events. A simple delay can work for a basic interface, but a state-based debounce is better for responsive robotics controls.

### Read analog sensor

```python
import time
import board
import analogio

sensor = analogio.AnalogIn(board.A0)

while True:
 print(sensor.value)
 time.sleep(0.1)
``

This prints the raw analog reading. Convert it into voltage or physical units only after checking your board’s ADC behavior and the sensor’s calibration. Never connect a sensor output above the board’s permitted input voltage; a small mismatch can become a permanent hardware feature.

### Use I2C with a sensor or display

```python
import board
import busio

i2c = busio.I2C(board.SCL, board.SDA)

while not i2c.try_lock():
 pass

try:
 print("I2C devices:", [hex(address) for address in i2c.scan()])
finally:
 i2c.unlock()
``

This checks for responding I2C addresses. It does not identify the device or validate its driver. Once the scan finds an address, confirm it against the sensor or display documentation and run the simplest supported CircuitPython example.

### Run code repeatedly without blocking

A blocking loop can delay other work. For a simple periodic task, compare elapsed time rather than sleeping for a long interval:

```python
import time

interval = 0.1
last_run = time.monotonic()

while True:
 now = time.monotonic()

 if now - last_run >= interval:
 last_run = now
 print("Periodic task")
``

This pattern is not a full real-time scheduler, and it does not guarantee hard real-time behavior. For motor control or safety-critical timing, confirm that the target board and runtime meet your timing requirements; consider dedicated hardware, a separate controller, or a design that fails safely.

## 📦 CircuitPython Libraries on MicroPython Boards: What Works and What Doesn’t

There are two different tasks that often get tangled together:

1. **Convert a MicroPython project to CircuitPython:** install CircuitPython firmware and adapt the project.
2. **Use a CircuitPython library while keeping MicroPython firmware:** use a compatible layer or port where supported.

They are not the same thing. Adafruit’s guide describes Blinka as a compatibility layer that started with MicroPython boards and later expanded to Linux-based computers. It also explains approaches for Raspberry Pico projects. See [CircuitPython Libraries on MicroPython using the Raspberry Pico](https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico/overview).

### Using CircuitPython libraries on a Raspberry Pico running MicroPython

The guide’s Pico approach uses **Blinka compatibility tooling** to make some CircuitPython libraries usable while the board remains on MicroPython. That can be useful when you have a library that is otherwise missing from your MicroPython setup—but it does not mean every CircuitPython library will work on every MicroPython board.

Adafruit’s documentation explains that changes were needed to make Blinka work over MicroPython and that Pico support was added for this setup. This is a supported pathway with its own requirements, not an automatic guarantee of compatibility.

Another option described in Adafruit’s documentation is **U2IF**, where a host computer runs Blinka and communicates with a Pico acting as a peripheral bridge. That is a different architecture from running the library entirely on a Pico.

Finally, the simplest option may be native CircuitPython firmware on a supported Pico. The [Raspberry Pico documentation](https://www.raspberrypi.com/documentation/microcontrollers/) and the board’s CircuitPython page can help you compare the available routes.

### Why the Blinka compatibility layer is not a universal solution

Blinka can help expose a CircuitPython-style API on supported platforms, but it does not magically resolve every mismatch. Compatibility depends on the board, firmware, library, hardware features, and available backend.

Expect friction when a library relies on:

- A CircuitPython feature not implemented by the compatibility layer.
- A particular microcontroller peripheral or pin behavior.
- A dependency that is unavailable on the target runtime.
- Timing or memory behavior the target board cannot provide.

The Core Electronics discussion about pairing an Adafruit GPS PA1010 CircuitPython driver with a MicroPython pressure-sensor driver is a good example of the question engineers face. A forum reply suggests Blinka, but it does not provide a proven, step-by-step conversion for that exact pair. The sensible conclusion is **test the exact hardware and library combination**, not “Blinka makes all drivers interchangeable.” The [original discussion](https://forum.core-electronics.com.au/t/conversion-between-circuitpython-and-micropython/11547) is useful context, but official library and board documentation should be your technical source of truth.

### Finding CircuitPython library equivalents for MicroPython modules

Start with the official [CircuitPython library index](https://circuitpython.org/libraries) and [project documentation](https://docs.circuitpython.org/en/latest/docs/index.html). Search by the sensor’s chip name and vendor, not just the marketing name of a breakout board.

When evaluating an equivalent, compare:

| Check | Why it matters |
|---|---|
| Supported sensor features | A basic reading may work while advanced modes do not |
| Required bus and pin type | The driver may assume a particular interface |
| Dependency list | Missing dependency modules cause import failures |
| Firmware and board support | APIs and memory use vary by target |
| Data units and calibration | Similar method names can return different scales |
| Maintenance and examples | A clear example speeds up safe integration |

If no CircuitPython driver exists, porting a pure Python driver may be reasonable. If it depends heavily on MicroPython internals, consider finding a native driver, writing a small new driver against the documented bus API, or staying on MicroPython.

## 🧩 Common API and Module Changes

There is no complete one-to-one translation table because API availability differs by board and release. Use this table as a map to inspect, then verify each replacement in the target board’s documentation.

### GPIO: machine.Pin and digitalio

| MicroPython pattern | Common CircuitPython pattern |
|---|---|
| `Pin(pin, Pin.OUT)` | `digitalio.DigitalInOut(board.<PIN>)` and set `.direction` |
| `pin.value(1)` | `pin.value = True` |
| `Pin.IN, Pin.PULL_UP` | Set `.direction = digitalio.Direction.INPUT` and `.pull = digitalio.Pull.UP` |
| Port-specific pin number | Board-defined name such as `board.D5` |

CircuitPython objects often express configuration through properties. Be especially careful with pin names, pull-up logic, active-low signals, and deinitialization.

### I2C and SPI: machine buses and busio

| MicroPython pattern | Common CircuitPython pattern |
|---|---|
| `machine.I2C(...)` | `busio.I2C(...)` or a board-provided bus helper |
| `machine.SPI(...)` | `busio.SPI(...)` or a board-provided bus helper |
| Direct bus access | Library drivers often manage device transactions and locking |
| Port-specific bus IDs | Explicit or board-defined pins |

Read the target board’s I2C and SPI examples. Bus construction, lock handling, frequency support, and pin selection are details that should be checked rather than guessed.

### PWM, ADC, and timers

| Need | Common MicroPython API | Common CircuitPython API |
|---|---|---|
| PWM output | `machine.PWM` | `pwmio.PWMOut` |
| Analog input | `machine.ADC` | `analogio.AnalogIn` |
| Millisecond sleep | Often `time.sleep_ms()` | Use documented `time` functions |
| Elapsed-time measurement | Often `ticks_ms()` family | Use an appropriate monotonic clock and verify API support |

PWM duty-cycle formats can differ. ADC resolution and usable pins are board-specific. Timer and interrupt APIs may not have a direct portable equivalent; if your project depends on precise timing, consult the exact board documentation and test the real hardware.

### Wi-Fi, networking, and sockets

Networking APIs are especially board-dependent. MicroPython projects may use modules such as `network`, while CircuitPython support can involve board-specific Wi-Fi modules and libraries.

Before porting network code, check:

- Whether the board has Wi-Fi hardware.
- Whether the CircuitPython build supports that hardware.
- Which networking libraries are needed.
- How credentials should be stored.
- Whether the project requires sockets, HTTP, MQTT, or another protocol.
- Whether the board’s memory and connection stability suit the workload.

Do not paste credentials into a public repository or expose them in an example file. CircuitPython’s [settings documentation](https://docs.circuitpython.org/en/latest/docs/environment.html) and the relevant board guides explain supported configuration options.

### Storage, filesystems, and USB drive behavior

CircuitPython’s `CIRCUITPY` drive is convenient for editing, but its storage model is not identical to every MicroPython deployment. A board may use a USB mass-storage workflow, a different filesystem setup, or a board-specific configuration.

Use safe practices:

- Back up before firmware changes.
- Let file writes finish before resetting or unpluging.
- Avoid editing files through two tools at once.
- Check the board’s storage guidance when application code writes to files.
- Keep configuration and application data separate where practical.

For filesystem behavior, follow the [CircuitPython storage documentation](https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage) and the target board’s official instructions.

### Async code, interrupts, and multitasking

Some MicroPython projects use `uasyncio`, interrupts, or port-specific scheduling. CircuitPython support and behavior depend on the runtime release and board. Do not assume an async program or interrupt callback will behave identically after a firmware swap.

For each concurrency feature:

1. Check that the target runtime exposes the module or API you need.
2. Verify that every imported dependency is available.
3. Test timing under realistic peripheral load.
4. Avoid long, blocking operations in tasks that must respond quickly.
5. Keep motor safety independent of a best-effort Python loop where possible.

For robotics, a watchdog, hardware motor-enable line, or dedicated controller can provide a safer fallback than relying on software scheduling alone.

## 🛠️ Troubleshooting Migration Errors

### ImportError or missing module

**Likely causes:**

- A MicroPython-only module was copied into CircuitPython code.
- A CircuitPython library or dependency is missing from `lib`.
- The library is incompatible with the firmware version.
- The imported name or folder structure is incorrect.

**Try this:**

1. Read the first line of the traceback and identify the missing module.
2. Search the target runtime’s documentation for that module.
3. Check the library’s installation instructions and dependencies.
4. Confirm the library is in the expected folder with the expected capitalization.
5. Run a minimal import test before restoring the full application.

Do not fix an import error by copying a similarly named MicroPython file into `lib` and hoping. The module may rely on APIs CircuitPython does not provide.

### AttributeError or incompatible API

An `AttributeError` often means the code imported successfully but expects a method or property the object does not have. The old driver may be calling a MicroPython-specific method, or the wrong object may have been constructed.

Check:

- The actual class and module imported.
- The installed library version.
- The driver’s documented initialization example.
- Whether a property is now assigned rather than called as a function.
- Whether the board supports the requested feature.

Make one API change at a time and print the object’s relevant values during a minimal test. The official [CircuitPython shared-bindings reference](https://docs.circuitpython.org/en/latest/shared-bindings/index.html) is more reliable than guessing from a library with a similar name.

### Board won’t boot or CIRCUITPY is missing

Start with the board’s bootloader and firmware instructions. Confirm that the file is intended for the exact board model, and check whether the board is showing a bootloader drive rather than the normal runtime drive.

Common checks:

- Use a known-good USB data cable.
- Try a different USB port or computer.
- Re-enter the documented bootloader mode.
- Reflash the correct board firmware.
- Disconnect external hardware that could hold a boot pin or overload the board.
- Check the serial console for the actual error.

If the board has onboard power or battery circuitry, disconnect external power sources only as directed by the manufacturer. Avoid random pin-shorting advice from unrelated boards.

### Memory limits, slowdowns, and storage problems

A project that ran under MicroPython may exceed available CircuitPython storage or memory once libraries are added. Large library bundles, display fonts, image data, and verbose logging can all contribute.

Reduce the load methodically:

- Install only the libraries your project imports.
- Remove unused examples, assets, and old firmware files.
- Use compact data structures and avoid unnecessary copies.
- Test the main loop with logging enabled and disabled.
- Check available memory and storage using documented APIs.
- Consider a board with more RAM or a different architecture if the project’s requirements exceed the target.

For motorized projects, do not “optimize” by removing safety checks before measuring the actual bottleneck.

### Serial console and REPL debugging

A serial console shows tracebacks and startup messages that may not appear on the USB drive. Adafruit’s [serial console guide](https://learn.adafruit.com/welcome-to-circuitpython/advanced-serial-console-on-mac-and-linux) covers common connection steps; terminal software differs by operating system.

A focused debugging sequence:

1. Connect the board and open its serial console.
2. Reset the board and capture the earliest message.
3. Fix the first error rather than the last symptom.
4. Test the failing import or peripheral in isolation.
5. Restart the full application and verify the fix.

A red or blinking status indicator can be useful, but its meaning varies by board. Always check the board-specific troubleshooting reference.

## ✅ When to Choose CircuitPython—and When to Stay on MicroPython

Choose CircuitPython when:

- Your exact board has a supported build.
- The CircuitPython library ecosystem covers your sensors and peripherals.
- You value the USB storage workflow and consistent hardware API.
- You are teaching, protyping, or building an interactive project where clear examples matter.
- Your application does not depend on unavailable MicroPython-specific features.

Stay on MicroPython when:

- Your board or peripheral support is stronger there.
- Your project depends on MicroPython-specific libraries or APIs.
- You need a particular port’s feature, behavior, or existing deployment setup.
- Converting the drivers would introduce more risk than value.
- The hardware is already stable and there is no concrete benefit to changing runtimes.

A split approach is also reasonable: keep shared logic portable, then maintain a thin hardware layer for each runtime. That is particularly useful for robot platforms used across several boards.

**Our recommendation:** pick the runtime based on the **exact board-plus-library combination**, not general claims that one is easier or more powerful. For a supported board with good CircuitPython drivers, CircuitPython can make hardware projects approachable and tidy. For an existing MicroPython robot whose drivers already work, staying put is often the more reliable engineering decision.

## 🔗 Related Guides: Raspberry Pico, ESP32, Sensors, and Libraries

- **Raspberry Pico:** Compare native CircuitPython firmware, MicroPython firmware with Blinka, and the U2IF host-computer approach in Adafruit’s [Pico libraries guide](https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico/overview) and [U2IF guide](https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico).
- **ESP32:** Check the exact chip and board model on the [CircuitPython downloads page](https://circuitpython.org/downloads) before choosing firmware; ESP32-family boards do not all share identical features.
- **Sensor drivers:** Search the official [CircuitPython libraries](https://circuitpython.org/libraries) and Adafruit’s [project documentation](https://docs.circuitpython.org/en/latest/docs/index.html), then verify the driver’s bus and board support.
- **Robotics concepts:** Explore our [robotic simulations](https://roboticcoding.com/category/robotic-simulations/) for testing control logic and the [robotic sensors category](https://roboticcoding.com/category/robotic-sensors/) for sensor-related project ideas.

**The question we parked earlier—does Blinka solve a MicroPython-to-CircuitPython conversion?—has a precise answer: no.** It may bridge some CircuitPython library APIs onto supported MicroPython platforms, but that is a compatibility strategy, not firmware conversion or universal driver support. For a clean move, port and test each hardware layer.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.