xiao-esp32s3
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseXIAO ESP32S3 via arduino-cli (Windows)
通过arduino-cli操作XIAO ESP32S3(Windows系统)
Everything below was verified on real hardware (esp32 core 3.3.10, 2026-07).
Follow it literally and you will not need to troubleshoot.
Paths below are relative to this skill's folder. is the board's COM
port and is a sketch folder in the user's workspace.
<PORT><SKETCH_DIR>以下所有内容均在真实硬件上验证通过(esp32核心库3.3.10版本,2026年7月)。严格按照步骤操作即可无需排查问题。
以下路径均相对于本技能的文件夹。为开发板的COM端口,为用户工作区中的sketch文件夹。
<PORT><SKETCH_DIR>One-time setup (skip any step that is already true)
一次性设置(已完成的步骤可跳过)
powershell
arduino-cli version # confirm arduino-cli exists
arduino-cli core list # is esp32:esp32 3.x installed?powershell
arduino-cli version # 确认arduino-cli已安装
arduino-cli core list # 是否已安装esp32:esp32 3.x版本?if not (this downloads ~1 GB and can take several minutes — use a long timeout):
若未安装(此步骤将下载约1GB数据,可能需要数分钟——请设置较长超时时间):
arduino-cli core update-index
arduino-cli core install esp32:esp32
undefinedarduino-cli core update-index
arduino-cli core install esp32:esp32
undefinedFinding the board
查找开发板
powershell
arduino-cli board listThe XIAO usually shows as an unidentified "Serial Port (USB)" — that row's
port (e.g. ) is . If NO port appears: the board may be in deep
sleep (port only exists while awake — see pitfall 2), or needs bootloader
mode (hold the BOOT button while plugging in USB; port number may change).
COM4<PORT>powershell
arduino-cli board listXIAO通常显示为未识别的“Serial Port (USB)”——该行的端口(如)即为。若未显示任何端口:开发板可能处于深度睡眠状态(仅在唤醒时才会显示端口——见陷阱2),或者需要进入引导加载模式(插入USB时按住BOOT按钮;端口号可能会变化)。
COM4<PORT>Standard workflow
标准工作流程
powershell
undefinedpowershell
undefinedsketch layout rule: folder name and .ino name must match: my_sketch\my_sketch.ino
sketch命名规则:文件夹名称与.ino文件名必须一致:my_sketch\my_sketch.ino
compile (first compile of a session takes 1-3 min; cached after)
编译(会话中的首次编译需要1-3分钟;之后会缓存)
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 <SKETCH_DIR>
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 <SKETCH_DIR>
upload
上传
arduino-cli upload -p <PORT> --fqbn esp32:esp32:XIAO_ESP32S3 <SKETCH_DIR>
arduino-cli upload -p <PORT> --fqbn esp32:esp32:XIAO_ESP32S3 <SKETCH_DIR>
read serial for 10 s (NEVER arduino-cli monitor
— it blocks forever)
arduino-cli monitor读取串口10秒(绝对不要使用arduino-cli monitor
——它会永久阻塞)
arduino-cli monitorpowershell -File scripts\read_serial.ps1 -Port <PORT> -Seconds 10
powershell -File scripts\read_serial.ps1 -Port <PORT> -Seconds 10
optional: send a line to the board and read the response
可选:向开发板发送一行数据并读取响应
powershell -File scripts\read_serial.ps1 -Port <PORT> -Seconds 10 -Send "hello"
PowerShell 5.1 has no `&&`. Chain with `;` or `if ($?) { ... }`.powershell -File scripts\read_serial.ps1 -Port <PORT> -Seconds 10 -Send "hello"
PowerShell 5.1不支持`&&`。使用`;`或`if ($?) { ... }`来链式执行命令。Verified example sketches
经过验证的示例sketch
assets/sketches/references/examples.mdassets/sketches/references/examples.mdSketch rules that prevent bugs
避免bug的Sketch编写规则
- then
Serial.begin(115200);before the first print — USB CDC needs time to enumerate, otherwise early output is silently lost.delay(3000); - The user LED is (GPIO21) and is inverted:
LED_BUILTIN= ON,LOW= OFF.HIGH= full brightness.analogWrite(LED_BUILTIN, 0) - ADC: call ; read raw with
analogReadResolution(12)and millivolts withanalogRead(A0). A floating pin reads noisy 60–160 raw — that is normal, not a bug.analogReadMilliVolts(A0) - Touch: (T2 = GPIO2 = pin D1). Baseline ≈ 17,500; the value RISES well above 40,000 when touched (opposite of original ESP32).
touchRead(T2) - returns
WiFi.macAddress()until WiFi is started with00:00:00:00:00:00— not an error.WiFi.mode(WIFI_STA) - Networking in core 3.x: use /
NetworkClient(oldNetworkServer/WiFiClientnames may not exist).WiFiServer
- 先执行,再执行
Serial.begin(115200);后才进行首次打印——USB CDC需要时间枚举设备,否则早期输出会被静默丢失。delay(3000); - 用户LED为(GPIO21),且为反向逻辑:
LED_BUILTIN=点亮,LOW=熄灭。HIGH=最大亮度。analogWrite(LED_BUILTIN, 0) - ADC:调用;使用
analogReadResolution(12)读取原始值,使用analogRead(A0)读取毫伏值。悬空引脚会读取到60–160的噪声值——这是正常现象,并非bug。analogReadMilliVolts(A0) - 触摸:(T2=GPIO2=引脚D1)。基准值≈17500;触摸时数值会上升至40000以上(与原始ESP32相反)。
touchRead(T2) - 在调用
WiFi.macAddress()启动WiFi前会返回WiFi.mode(WIFI_STA)——这并非错误。00:00:00:00:00:00 - 3.x版本核心库中的网络功能:使用/
NetworkClient(旧的NetworkServer/WiFiClient名称可能已不存在)。WiFiServer
Pin map (XIAO ESP32S3)
XIAO ESP32S3引脚映射
| Label | GPIO | Notes |
|---|---|---|
| D0 | 1 | A0, touch T1 |
| D1 | 2 | A1, touch T2 |
| D2 | 3 | A2, touch T3 |
| D3 | 4 | A3, touch T4 |
| D4 | 5 | SDA, touch T5 |
| D5 | 6 | SCL, touch T6 |
| D6 | 43 | UART TX (Serial1) |
| D7 | 44 | UART RX (Serial1) |
| D8 | 7 | SPI SCK |
| D9 | 8 | SPI MISO |
| D10 | 9 | SPI MOSI |
| user LED | 21 | inverted (LOW = on) |
| 标签 | GPIO | 说明 |
|---|---|---|
| D0 | 1 | A0,触摸T1 |
| D1 | 2 | A1,触摸T2 |
| D2 | 3 | A2,触摸T3 |
| D3 | 4 | A3,触摸T4 |
| D4 | 5 | SDA,触摸T5 |
| D5 | 6 | SCL,触摸T6 |
| D6 | 43 | UART TX(Serial1) |
| D7 | 44 | UART RX(Serial1) |
| D8 | 7 | SPI SCK |
| D9 | 8 | SPI MISO |
| D10 | 9 | SPI MOSI |
| 用户LED | 21 | 反向逻辑(LOW=点亮) |
Known pitfalls — read before "debugging"
已知陷阱——调试前务必阅读
- Opening the COM port resets the board (DTR toggle → ). Every serial read starts from a fresh boot. This also wipes
rst:0x15 USB_UART_CHIP_RESETvariables, so you cannot observe deep-sleep boot counts through a serial monitor. It is not a crash.RTC_DATA_ATTR - Deep sleep makes the COM port disappear. USB CDC powers down during
sleep, so the port vanishes and Windows plays disconnect/connect sounds
every cycle. This is normal and is the correct evidence that sleep works.
Verify the cycle with (logs appear/disappear timestamps) instead of opening the port. To reflash a sleeping board, catch the short awake window, or hold the BOOT button while plugging USB (bootloader mode; the port number may change).
scripts\watch_port.ps1 -Port <PORT> - never exits. In an automated session it hangs your shell. Always use
arduino-cli monitor, which has a deadline.scripts\read_serial.ps1 - PSRAM reads 0 bytes by default. The default build has PSRAM disabled.
If a sketch needs PSRAM (camera, big buffers), add
to BOTH compile and upload commands.
--board-options PSRAM=opi - is cached and may not show a SoftAP the board just created. Trust the board's serial output ("AP IP address: 192.168.4.1"); test the AP from a phone instead.
netsh wlan show networks - Upload fails / port busy: make sure no serial reader is still running (only one process can hold the port). If the board looks bricked, use bootloader mode (pitfall 2).
- First compile is slow (cold cache, big toolchain). Do not kill it before ~3 minutes; use a generous timeout.
- Board can get stuck in reset after a serial session (only the ROM
banner prints, app never boots, SoftAP/servers die). Cause: DTR/RTS line state left by the PC when closing the port. Recover with
ESP-ROM:esp32s3-...(esptool's reset sequence fixes it). If a headless demo (web server etc.) must keep running, avoid opening the serial port at all — use mDNS or the router's DHCP table to find the board instead of reading its IP over serial.arduino-cli upload - Same-name Edge Impulse library swap needs . Replacing the
--cleanlibrary with a rebuilt copy (same version) leaves stale objects in arduino-cli's cache — symptoms:<project>_inferencinglink errors or edits that appear to have no effect. Always passobjs.a ... is not an objecton the first compile after swapping the library.--clean
- 打开COM端口会重置开发板(DTR电平切换→)。每次读取串口都会从全新启动开始。这也会清除
rst:0x15 USB_UART_CHIP_RESET变量,因此无法通过串口监视器观察深度睡眠启动次数。这并非崩溃。RTC_DATA_ATTR - 深度睡眠会导致COM端口消失。深度睡眠期间USB CDC会断电,因此端口会消失,Windows会在每个周期播放断开/连接提示音。这是正常现象,也是睡眠功能正常工作的正确证据。使用(记录端口出现/消失的时间戳)来验证周期,而非直接打开端口。要重新烧录处于睡眠状态的开发板,需抓住短暂的唤醒窗口,或者插入USB时按住BOOT按钮(进入引导加载模式;端口号可能会变化)。
scripts\watch_port.ps1 -Port <PORT> - 永远不会退出。在自动化会话中会导致shell挂起。请始终使用
arduino-cli monitor,它有时间限制。scripts\read_serial.ps1 - 默认情况下PSRAM读取0字节。默认构建版本中PSRAM已禁用。若sketch需要PSRAM(如摄像头、大缓冲区),需在编译和上传命令中均添加。
--board-options PSRAM=opi - 存在缓存,可能无法显示开发板刚创建的SoftAP。请信任开发板的串口输出(“AP IP地址:192.168.4.1”);使用手机测试AP即可。
netsh wlan show networks - 上传失败/端口忙:确保没有串口读取程序仍在运行(同一时间只有一个进程可以占用端口)。若开发板看起来变砖,使用引导加载模式(见陷阱2)。
- 首次编译速度慢(冷缓存、工具链庞大)。请勿在约3分钟前终止进程;请设置充足的超时时间。
- 串口会话结束后开发板可能陷入重置循环(仅打印ROM启动信息,应用程序永远无法启动,SoftAP/服务器无法运行)。原因:PC关闭端口时留下的DTR/RTS线路状态。使用
ESP-ROM:esp32s3-...恢复(esptool的重置序列可修复此问题)。若无头演示(如Web服务器等)必须持续运行,请完全避免打开串口端口——使用mDNS或路由器的DHCP表查找开发板,而非通过串口读取其IP地址。arduino-cli upload - 同名Edge Impulse库替换需要添加。用重新构建的副本替换
--clean库(版本相同)会在arduino-cli的缓存中留下过期对象——症状:出现<project>_inferencing链接错误或修改似乎未生效。替换库后的首次编译请务必添加objs.a ... is not an object参数。--clean
Verifying without human eyes
无需人工目视的验证方法
- LED/PWM: also print state to serial each cycle so the log proves behavior.
- WiFi scan / BLE scan: success = a numbered list of networks/devices.
- SoftAP: success = serial prints the AP IP; full HTTP test needs a phone.
- Deep sleep: success = shows a stable disappear/appear cycle matching the programmed sleep time (+ ~3 s awake).
watch_port.ps1
- LED/PWM:同时在每个周期将状态打印到串口,以便日志证明行为。
- WiFi扫描/BLE扫描:成功标志为显示编号的网络/设备列表。
- SoftAP:成功标志为串口打印AP IP地址;完整HTTP测试需要使用手机。
- 深度睡眠:成功标志为显示稳定的消失/出现周期,与编程的睡眠时间匹配(+约3秒唤醒时间)。
watch_port.ps1