wokwi / wokwi-vscode-micropython

MicroPython in Wokwi for VS Code
MIT License
29 stars 9 forks source link

MicroPython Simulation in Wokwi for VS Code

Example project for running MicroPython on Wokwi for VS Code.

Prerequisites

  1. Install the Wokwi for VS Code extension.
  2. Install the mpremote tool, e.g. pip install mpremote.

Usage

  1. Clone this project and open it in VS Code.
  2. From the command palette, select "Wokwi: Start Simulator". You may need to activate your license first.
  3. Select one of the directories to simulate, e.g. "esp32".
  4. While the simulator is running, open a command prompt, and type:

    python -m mpremote connect port:rfc2217://localhost:4000 run main.py

    This will connect to the simulator and run the main.py file on the board. Note: keep the simulator tab visible while running the command, otherwise the simulator will pause and the command will timeout.

Advanced usage

You can also use the mpremote tool to upload files to the simulator, install libraries, and open a REPL session. For example, the following command will connect to the simulator, upload the main.py file, install the ssd1306 library, and then open a REPL session:

python -m mpremote connect port:rfc2217://localhost:4000 fs cp main.py :main.py + mip install ssd1306 + repl

See the mpremote documentation for more details.

Shortcut

On Unix based systems (e.g. Mac or Linux), you can create a shortcut for connecting to the simulator by running the following command:

mkdir -p ~/.config/mpremote
echo 'config={"wokwi": "connect port:rfc2217://localhost:4000"}' > ~/.config/mpremote/config.py

After running this command, you can connect to the simulator by running mpremote wokwi.

License

Licensed under the MIT license. See LICENSE for details.