xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Pico simulator All In One

Pico simulator All In One

Raspberry Pi Pico simulator online / 树莓派 Pico 在线模拟器

Wokwi

  • Raspberry Pi Pico
  • Arduino
  • ESP32
  • STM32

Simulate with Wokwi Online

image

技术实现原理分析:交互式 SVG 动画,Canvas 图片绘制

image

Wokwi 是浏览器端, 网页版在线单片机 / 嵌入式仿真平台,主打 ESP32,也支持 Arduino、STM32、树莓派 Pico,不用买开发板,直接在网页里搭电路、写代码、跑仿真

https://wokwi.com/

image

Raspberry Pi Pico Simulator

A faster way to prototype Pi Pico projects

image

image

https://wokwi.com/pi-pico

demos

Pico 控制 OLED 屏幕 SSD1306 显示 中文字符 💩

Pico 安装 micropython-ssd1306py 中文库

Pico 控制 OLED 屏幕 SSD1306 显示 ASIIC 字符 ✅

https://wokwi.com/projects/480877345624011777

project template

https://wokwi.com/projects/480861481381704705

image

main.py

from machine import Pin, I2C, SoftI2C
import ssd1306
# import sh1106
import time

# I2C0:SDA=GP16,SCL=GP17
DATA_PIN = 16
SCL_PIN = 17
i2c = I2C(0, sda=Pin(DATA_PIN), scl=Pin(SCL_PIN), freq=400_000)

# 扫描设备地址
devices = i2c.scan()
print("扫描到 I2C 设备:", devices)
# [60]
# 使用地址: 0x3C,rotate=180 翻转画面
# 128 x 64
oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
# oled = sh1106.SH1106_I2C(128, 64, i2c, addr=0x3c, rotate=180)

def clear():
    # 清空屏幕
    oled.fill(0)
    pass

def draw_text():
  # 写文字
  oled.text("Hello Pico!", 0, 0)
  oled.text("OLED SSD1306", 0, 16)
  oled.text("I2C Test", 0, 32)
  oled.show()

def draw_line():
  # 画一条线
  oled.hline(0, 48, 128, 1)
  oled.show()

if __name__ == "__main__":
    try:
        clear()
        draw_text()
        draw_line()
    except KeyboardInterrupt:
        clear()


ssd1306.py 驱动程序 ✅

# SSD1306 OLED driver, I2C
from micropython import const
import framebuf

SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xA4)
SET_NORM_INV = const(0xA6)
SET_DISP = const(0xAE)
SET_MEM_ADDR = const(0x20)
SET_COL_ADDR = const(0x21)
SET_PAGE_ADDR = const(0x22)
SET_DISP_START_LINE = const(0x40)
SET_SEG_REMAP = const(0xA0)
SET_MUX_RATIO = const(0xA8)
SET_COM_OUT_DIR = const(0xC0)
SET_DISP_OFFSET = const(0xD3)
SET_COM_PIN_CFG = const(0xDA)
SET_DISP_CLK_DIV = const(0xD5)
SET_PRECHARGE = const(0xD9)
SET_VCOM_DESEL = const(0xDB)
SET_CHARGE_PUMP = const(0x8D)

class SSD1306(framebuf.FrameBuffer):
    def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
        self.i2c = i2c
        self.addr = addr
        self.width = width
        self.height = height
        self.external_vcc = external_vcc
        self.pages = self.height // 8
        self.buffer = bytearray(self.pages * self.width)
        super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
        self.init_display()

    def init_display(self):
        for cmd in (
            SET_DISP | 0x00,
            SET_MEM_ADDR, 0x00,
            SET_DISP_START_LINE | 0x00,
            SET_SEG_REMAP | 0x01,
            SET_MUX_RATIO, self.height - 1,
            SET_COM_OUT_DIR | 0x08,
            SET_DISP_OFFSET, 0x00,
            SET_COM_PIN_CFG, 0x02 if self.height == 32 else 0x12,
            SET_DISP_CLK_DIV, 0x80,
            SET_PRECHARGE, 0x22 if self.external_vcc else 0xF1,
            SET_VCOM_DESEL, 0x30,
            SET_CONTRAST, 0xFF,
            SET_ENTIRE_ON,
            SET_NORM_INV,
            SET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14,
            SET_DISP | 0x01):
            self.write_cmd(cmd)
        self.fill(0)
        self.show()

    def write_cmd(self, cmd):
        self.i2c.writeto(self.addr, bytearray([0x80, cmd]))

    def write_data(self, buf):
        self.i2c.writeto(self.addr, b'\x40' + buf)

    def show(self):
        x0 = 0
        x1 = self.width - 1
        if self.width == 64:
            x0 += 32
            x1 += 32
        self.write_cmd(SET_COL_ADDR)
        self.write_cmd(x0)
        self.write_cmd(x1)
        self.write_cmd(SET_PAGE_ADDR)
        self.write_cmd(0)
        self.write_cmd(self.pages - 1)
        self.write_data(self.buffer)

class SSD1306_I2C(SSD1306):
    def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
        super().__init__(width, height, i2c, addr, external_vcc)

diagram.json UI 渲染 JSON 对象


{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    {
      "type": "wokwi-pi-pico",
      "id": "pico",
      "top": -104.9,
      "left": -107.55,
      "rotate": 90,
      "attrs": { "env": "micropython-20260406-v1.28.0" }
    },
    {
      "type": "board-ssd1306",
      "id": "oled1",
      "top": 89.54,
      "left": -66.97,
      "attrs": { "i2cAddress": "0x3c" }
    }
  ],
  "connections": [
    [ "pico:3V3", "oled1:VCC", "red", [ "h0" ] ],
    [ "pico:GND.8", "oled1:GND", "black", [ "v30", "h-28.8" ] ],
    [ "oled1:SCL", "pico:GP17", "violet", [ "v-19.2", "h57.9", "v105.6", "h-201.6" ] ],
    [ "oled1:SDA", "pico:GP16", "limegreen", [ "v-28.8", "h57.67", "v124.8", "h-220.8" ] ]
  ],
  "dependencies": {}
}

https://www.cnblogs.com/xgqfrms/p/23646976#5430403

image

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

ASCII

MicroPython 的 framebuf.text() 内置的是 8 位 ASCII 字库:

  • ✅ A-Z 0-9 !@# 英文数字符号
  • ❌ 中文、emoji、特殊 Unicode 全都没有点阵

想显示中文,必须自己准备「字模(汉字点阵)」。

  1. PCtoLCD2002 / 在线取模工具

把需要的字(比如「你好」)提取成 16×16 点阵,存在字典里,用 blit() 画上去。

取模软件在线版(字模提取 / 汉字取模 / 图片取模)

https://go-tools.org/zh/tools/lcd-font-generator

https://github.com/caowent/PCtoLCD2018

  1. micropython-ssd1306py

自带中英文,不用自己一个个取模。

Unicode / Emoji

🕵️‍♂️ emoji 更别想:

  • 它是组合 Unicode 表情,自带字库完全不支持
  • 就算字库也不可能把 emoji 点阵塞进 Pico

refs

image



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2026-11-16 23:33  xgqfrms  阅读(14)  评论(11)    收藏  举报