Python Simulator for micro:bit and Circuit Playground Express

Device Simulator Express is a programming extension for VSCode that allows you to simulate and debug Python programs for the Circuit Playground Express (CPX) or BBC micro:bit without hardware. Additionally, you can observe the device’s output through the serial port. Device Simulator Express has similar functionalities to the device simulator in MakeCode, but it is a simulator for Python programs and is currently the most powerful Python simulator available for micro:bit.

Python Simulator for micro:bit and Circuit Playground Express

After installing the Device Simulator Express extension, you also need to install Node.js, Python (version 3.74+), the Python VS Code extension, and several Python dependency modules (please refer to the installation documentation for specific steps). Once the Device Simulator Express extension is installed, press CTRL+SHIFT+P or open the command palette from the menu, then type ‘Device Simulator Express: [Circuit Playground Express] New File’ to create a new CPX program; or use ‘Device Simulator Express: [micro:bit] New File’ to create a new micro:bit program.

Then enter your Python program, and when finished, save it (saving is not mandatory, but it helps prevent accidental loss of the program). Next, from the command palette, type ‘Device Simulator Express: [micro:bit] Open Simulator’ to launch the simulator. If you modify the program, you can press the reload button in the simulator to reload the program.

At the bottom of the simulator, there are two functional buttons: start/stop and reload. Below these buttons is a row of sensors and functional buttons that you can click to open a specific function and set sensor parameters; you can also directly click the buttons and GPIO on the board in the simulator.

The running effect of the simulator is as follows:

Heartbeat on micro:bit Running Effect

Python Simulator for micro:bit and Circuit Playground Express

CPX Flashing Light Program Simulation Effect

Python Simulator for micro:bit and Circuit Playground Express

Notes:

  • The main functions of micro:bit and CPX can now be simulated, but some sensors and libraries are still not usable (e.g., magnetic field sensor, music, etc.).

  • The Device Simulator Express extension defaults to support CPX; if you want to simulate micro:bit, you need to enable the preview mode option in the extension settings.

  • Micro:bit uses a customized version of MicroPython, while CPX runs CircuitPython.

  • The startup speed of the simulator in VSCode is a bit slow, so please be patient; we hope the speed issue can be resolved in the future.

  • This extension can also be used on Linux, where the simulator runs slightly faster than on Windows.

  • When starting the simulator for the first time, you will be prompted to install the required Python dependency modules.

  • You need to follow the documentation to install all the required software and Python modules; otherwise, exceptions will be prompted during runtime. (Recently, due to network issues, some modules may be difficult to install; try multiple times or attempt at night when fewer people are online.)

  • Since the public account cannot send links, please click the original text below to view the related links.

Leave a Comment