MicroPython or CircuitPython?
The Raspberry Pi Pico (and other RP2040 based boards) can be used with both MicroPython and CircuitPython. Let's look what they are and what is different between them.
MicroPython
MicroPython was announced in 2013, as a KickStarter campaing by Damien P. George. The aim was to create an optimized Python version that cuild be run directly in a microcontroller. The current version can be found in the official site and the source code is at github.
MicroPython implements most of the Python 3 language and standard libraries and adds features specific for microcontrollers. One key feature of MicroPython is the interactive operation over a serial connection (the REPL - Read-Eval-Print Loop). You type in a command, it is executed, the resulted is printed and a new command is awaited. Usually you interact with MicroPython using an IDE that supports REPL, like Thonny.
In MicroPython there is a machine module for microcontroller specific features. The Raspberry Pi Foundation has support MicroPython from the Pi Pico launch, including a machine module (with PIO support), examples and documentation.
Here is the traditional blink program fot the Pi Pico in MicroPython:
import machine import utime led_onboard = machine.Pin(25, machine.Pin.OUT) while True: led_onboard.value(1) utime.sleep(5) led_onboard.value(0) utime.sleep(5)CircuitPython
CircuitPython is a fork of MicroPython, sponsored by Adafruit. Most of the code is the same. Again, the current version is in the official site and source code is at github.
- CircuitPython uses the native USB controller of the supported boards to implement a disk drive. To execute a program you write it into this drive with a special name.
- Access to microcontroller features is different. Instead of the machine module there are many others, in a effort to create a consistent API (but pin names change according to the board).
- There is no support to concurrent execution (interrupts and threading).
import board import digitalio import time led = digitalio.DigitalInOut(board.LED) led.direction = digitalio.Direction.OUTPUT while True: led.value = True time.sleep(0.5) led.value = False time.sleep(0.5)
Comments
Post a Comment