这里写自定义目录标题
嵌入式在线仿真平台wokwi使用
Wokwi 是一个在线电子电路仿真平台,主要用于模拟和测试基于微控制器的项目(如 Arduino、ESP32、Raspberry Pi Pico 等)。它无需安装任何软件,直接在浏览器中即可完成电路设计、代码编写和实时仿真,适合开发者、教育者和爱好者快速验证想法。
主要特点:
- 无需安装 ,通过浏览器即可访(https://wokwi.com/))。
支持多人协作,轻松分享项目链接。 - 支持的硬件 ,
微控制器:Arduino Uno、ESP32、ATtiny85、Raspberry Pi Pico 等。
外设:LED、传感器(温湿度、超声波等)、LCD 屏幕、电机、舵机等。
扩展库:支持自定义元件和第三方库(如 Adafruit 传感器)。
代码编辑与调试 - 代码编辑与调试 ,
内置代码编辑器,支持 Arduino C/C++、MicroPython 等语言。
提供实时仿真日志、串口监视器、变量跟踪和调试工具(如断点)。 - 可视化交互 ,
仿真时可点击按钮、旋转电位器,模拟真实硬件交互。
支持虚拟示波器(Logic Analyzer),查看信号波形。
使用介绍
通过wokwi官方文档的案例试用一下。
1 Arduino Uno 打印"Hello World" ,
```c
/* Hello Wokwi! */
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("Hello, Wokwi!");
}
void loop() {
lcd.setCursor(7, 1);
lcd.print(millis() / 1000);
}
2 ATtiny85模块监测温湿度 " ,
/*
Why the heart icon? Because I thought it was cool
and I want to use it in the future with some heartbeat sensor.
I needed to keep it somewhere and it was here. ;)
*/
#include <dht.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#define DHT22_PIN PB1
const unsigned char img_heart_small[] PROGMEM = {
0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00
};
const unsigned char img_heart_big[] PROGMEM = {
0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
};
const unsigned char img_thermometer[] PROGMEM = {
0x00, 0xfe, 0x03, 0xfe, 0x50,
0x00, 0xff, 0x00, 0xff, 0x55,
0x60, 0x9f, 0x80, 0x9f, 0x65,
};
dht DHT;
void splash() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(42, 3);
oled.print(F("Example"));
oled.setCursor(35, 7);
oled.print(F("wokwi.com"));
}
void heartBeat() {
static char big = 1;
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Update if 200ms passed
if ((currentTime - startTime) > 200) {
startTime = currentTime;
big = 1 - big;
if (big) {
oled.bitmap(20, 4, 37, 6, img_heart_big);
} else {
oled.bitmap(20, 4, 37, 6, img_heart_small);
}
}
}
void prepareDisplay() {
unsigned int i, k;
unsigned char ch[5];
oled.clear();
oled.begin();
oled.setCursor(20, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(3, 2);
oled.print(F("temperature|humidity"));
oled.bitmap(105, 4, 110, 7, img_thermometer);
oled.setCursor(57, 4);
oled.print(F("24.0C"));
oled.setCursor(57, 5);
oled.print(F("40.0%"));
oled.bitmap(10, 5, 17, 2, img_heart_small);
}
float getTemperature() {
return DHT.temperature;
}
float getHumidity() {
return DHT.humidity;
}
void setup() {
pinMode(DHT22_PIN, INPUT);
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// To clear all the memory
oled.clear();
oled.on();
splash();
delay(3000);
prepareDisplay();
}
void loop() {
static long startTime = 0;
long currentTime;
DHT.read22(DHT22_PIN);
// Get current time
currentTime = millis();
// Checks 1 second passed
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
// Update temperature
float temperature = getTemperature();
// Set cursor
oled.setCursor(57, 4);
// Print to display
oled.print(temperature, 1);
oled.print("C ");
// Update humidity
float humidity = getHumidity();
// Set cursor
oled.setCursor(57, 5);
// Print to display
oled.print(humidity, 1);
oled.print("% ");
oled.bitmap(105, 4, 110, 7, img_thermometer);
}
heartBeat();
}
嵌入式在线仿真平台wokwi试用