# xdial_lvgl_micropython **Repository Path**: r-cute/xdial_lvgl_micropython ## Basic Information - **Project Name**: xdial_lvgl_micropython - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-01-19 - **Last Updated**: 2025-01-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # xdial_lvgl_micropython 固件 该固件的编译参考 https://github.com/lvgl-micropython/lvgl_micropython, 版本: eps-idf v5.2 + lvgl v9.? src 目录里的是与 xDial 设备相关的库,已经预编译到固件中。 ## lvgl 教程 * lvgl 各控件例子 https://docs.lvgl.io/8.4/widgets/index.html 注意这是 lvgl v8 版本, 固件中用的是 v9,大致相同 * lvgl + python 在线版: https://sim.lvgl.io/ ## 烧录固件 1. 安装 esptool.py ```sh pip install esptool ``` 2. 下载固件(https://gitee.com/r-cute/xdial_lvgl_micropython/releases/) 并烧录到地址 0 ```sh python -m esptool --chip esp32c3 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m --erase-all 0x0 xdial_C3_MINI_4M_lvgl_micropython.bin ``` ## IDE 推荐 [Thonny](https://thonny.org/), 设置 Tools -> Options -> Interpreter -> MicroPython(ESP32) ## 例子 ### 屏幕和 lvgl ```py from xdial import * import lvgl as lv disp = Display() # 必须先创建 display 才能使用 lvgl disp.backlight(100) # 背光亮度 100% # 创建一个弧形进度条放到屏幕中间 scr = lv.screen_active() arc = lv.arc(scr) arc.center() ``` ### 蜂鸣器 ```py buz = Buzzer() buz.tone(400, 300) # 频率400hz, 鸣300 ms buz.play('A3:8 A3 G3:4 R', tempo=60, repeat=2) # A3:8 表示 A3音节 8分之一拍, 如果省略节拍长短则与前一个相同; R 表示休止 ```` * 当然也可以用第三方库去控制硬件 ```py dir(pins) # 列出各引脚 buz = MyBuzzer(pins.BUZ) ```` ### 转盘 ```py # mode: BOUNDED 转盘数值只能在 range 之间, UNBOUNDED 无界限, WRAP 超出 max 则回到 min, 超出 min 则回到 max # ratio: 放大系数,ratio=4 时转动一小格 value 增长4, ratio=1/4 时,转动4小格才会触发一次 handler rot = RotaryEncoder(range=(0, 100), mode=RotaryEncoder.BOUNDED, ratio=1) rot.handler = lambda delta: arc.set_value(rot.value) ``` ### 按钮 ```py def btn_press(pressed): if pressed: buz.tone(300,50) btn = Buttons() btn.left.handler = btn_press btn.right.handler = btn_press ``` ## API 参考 src/xdial.py 文件