Device Simulator Express is a programming extension for VSCode. It allows you to simulate and debug Python programs on Circuit Playground Express (CPX) or BBC micro:bit without hardware. You can also observe the output of the device through the serial port. Device Simulator Express is similar to the device simulator in Makecode, but it is a simulator for Python programs and is currently the most powerful Python simulator on microbit.
After installing the Device Simulator Express extension, you will also need to install nodejs, python (version 3.74+), the Python VS Code extension, and several python dependencies (see the installation instructions for specific steps). After installing the Device Simulator Express extension, press CTRL+SHIFT+P or open the command palette from the menu and 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 the python program, save it after completion (saving is not a necessary step, but it can prevent the program from being accidentally lost), and then enter 'Device Simulator Express: [micro:bit] Open Simulator' from the command palette to start the simulator. If you modify the program, you can press the reload button in the simulator to reload the program.
There are two function buttons below the simulator, Start/Stop and Reload. Below these two buttons is a row of sensor and function buttons, which can be clicked to open a function and set sensor parameters; or you can directly click the buttons and GPIO on the board in the simulator.
The running effect of the simulator is as follows:
The on the microbit is beating .
CPX flash program simulation effect
Note:
-
The main functions of microbit and CPX can now be simulated, but some sensors and libraries cannot be used yet (such as magnetic field sensor, music, etc.).
-
The Device Simulator Express extension supports CPX by default. If you want to simulate microbit, you need to enable the preview mode option in the extension options.
-
The microbit uses a customized version of micropython, and the CPX runs CircuitPython.
-
vscode is a bit slow in starting the simulator, so you need to be patient and wait. I hope the speed problem can be solved later.
-
This extension can also be used under Linux, where the simulator is slightly faster than under Windows.
-
When you start the simulator for the first time, you will be prompted to install the required Python dependency modules.
-
You need to install the required software and Python modules according to the documentation, otherwise an exception will be prompted during operation. (Recently, due to network reasons, some modules may be difficult to install. You need to try several times, or try in the middle of the night when there are few people)
Related links
This content is originally created by dcexpert , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source