Migrating Wokwi projects to VS Code
The web-based Wokwi simulator is a powerful and well-integrated way to try out your project designs: there are many capabilities which "just work" in the online simulator which will require some additional steps or workarounds to build and run locally.
This checklist of steps should help you overcome the most common issues. It is assumed that you have already installed the VS Code extension for Wokwi (see the Getting started guide).
Using MicroPython? The setup for MicroPython projects is quite different - please see the VS Code for MicroPython page.
Download the project source
To start, the first step is to save your online project. From the same menu, under the save button, you can then select to download a .zip archive of the project. This will contain useful files such as any source code and the diagram.json file used by Wokwi.
Once downloaded you can extract the files from the archive and use them in your local project.
Create an empty project in VS Code
If you are using an extension such as ESP-IDF or PlatformIO in VS Code, it is far easier to create an empty template project first before adding your Wokwi code. Use the provided templates for your chosen platform to create a new empty project. This will include specifying the hardware to be targeted and will create the required source structure and build files.
This step will create a boilerplate project in a working state, ready to add your own code.
Add the source
Depending on the complexity of your project, adding the source should be quite straightforward.
- PlatformIO
- ESP-IDF
- Zephyr
For a new PlatformIO Arduino project, the directory tree should look like this:
├── .gitignore
├── include
│ └── README
├── lib
│ └── README
├── platformio.ini
├── src
│ └── main.cpp
└── test
└── README
In this case you would delete the /src/main.cpp and replace it with the '.ino' file from the project you downloaded.
PlatformIO encourages the use of standard C++ files (.cpp). To convert your .ino file, you can rename it and change the extension to '.cpp', but you will also need to add a line to include the standard Arduino headers at the beginning of the file:
#include <Arduino.h>
Any user functions should also be declared before they are called. There is a more detailed example of this in the PlatformIO documentation FAQ.
For ESP-IDF the default project directory tree looks like this:
├── build
│ ├── app-flash_args
│ ├── bootloader
│ ├── bootloader-flash_args
│ ├── bootloader-prefix
| ...
│ ├── cmake_install.cmake