文章目录
- [Wokwi 简介](#Wokwi 简介)
-
- 安装客户端(Mac/Linux)
- [创建 Token](#创建 Token)
- [Arduino IDE](#Arduino IDE)
- [VSCode 配置](#VSCode 配置)
-
- [安装 wokwi 插件](#安装 wokwi 插件)
- 打开编译后目录
- [ESP32C3 示例](#ESP32C3 示例)
Wokwi 简介
Wokwi 是一款在线电子模拟器。您可以使用它来模拟 Arduino、ESP32、STM32 以及许多其他流行的主板、部件和传感器。
- Github: https://github.com/wokwi/wokwi-cli
- 官网:https://wokwi.com/
- 文档: https://docs.wokwi.com/zh-CN/?utm_source=wokwi
安装客户端(Mac/Linux)
bash
curl -L https://wokwi.com/ci/install.sh | sh
- 添加环境变量
bash
export PATH="/usr/local/bin:$PATH"
创建 Token
Arduino IDE
- 选择 ESP32 Dev Module
- demo.ino
c
#define LED 2
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
- 编译后的文件所在目录
bash
cd /private/var/folders/y3/m5gygl0x29qb6gqzwbzhnbl40000gn/T/arduino/sketches/7BF1D604324680D884686063EF3F4C75/
- 创建模拟器
- 生成 diagram.json 与 wokwi.toml 文件
- 修改 diagram.json 文件
json
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": -3.33,
"left": 153.33,
"attrs": { "color": "red" }
},
{ "type": "wokwi-resistor", "id": "r1", "top": 64, "left": 149.33, "rotate": 90, "attrs": {} }
],
"connections": [
[ "esp:TX0", "$serialMonitor:RX", "", [] ],
[ "esp:RX0", "$serialMonitor:TX", "", [] ],
[ "esp:GND.1", "led1:C", "black", [ "h0" ] ],
[ "led1:A", "r1:1", "green", [ "v0" ] ],
[ "r1:2", "esp:D2", "green", [ "h0", "v38" ] ]
]
}
VSCode 配置
安装 wokwi 插件
打开编译后目录
注: 选中 diagram.json 文件就会显示模拟器。
ESP32C3 示例
Arduino IDE
- demo.ino
c
#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // 初始化串口通信
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello World!"); // 输出 "Hello World"
delay(1000); // 等待 1 秒
}
注: 进入编译后的可执行文件目录
bash
cd /private/var/folders/y3/m5gygl0x29qb6gqzwbzhnbl40000gn/T/arduino/sketches/7BF1D604324680D884686063EF3F4C75/
创建模拟器
bash
wokwi-cli init
运行模拟器
bash
wokwi-cli .