查找Platform
平台即Platform通常与芯片对应,同一platform下通常有多种board。例如ESP8266平台下有Wemos,NodeMCU等。
pio platform search esp8266
返回的espressif8266
即为platform的完整名称
espressif8266 ~ Espressif 8266
==============================
Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications.
Home: https://espressif.com/
Frameworks: arduino, simba, esp8266-rtos-sdk, esp8266-nonos-sdk
Packages: framework-arduinoespressif8266, framework-esp8266-nonos-sdk, framework-esp8266-rtos-sdk, framework-simba, tool-esptool, tool-esptoolpy, tool-mklittlefs, tool-mkspiffs, toolchain-xtensa
查找Board
通过board名称查找
platformio boards |grep nodemcu
也可以限定平台后查找Board
pio boards espressif8266 |grep nodemcu
返回名称及硬件信息:
nodemcu ESP8266 80MHz 4MB 80KB NodeMCU 0.9 (ESP-12 Module)
nodemcuv2 ESP8266 80MHz 4MB 80KB NodeMCU 1.0 (ESP-12E Module)
创建并初始化项目
mkdir sample ; cd sample
pio project init --board nodemcuv2 --board nodemcu
也可以使用--ide
选项配置IDE,
pio project init --board nodemcuv2 --board nodemcu --ide emacs
完成后platformio.ini的文件内容如下
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
[env:nodemcu]
platform = espressif8266
board = nodemcu
framework = arduino
若需使用特定版本的platform,则修改platformio.ini的platform配置,例如
platform = [email protected]
添加包
根据header文件搜索包:
pio lib search "header:WiFiManager.h"
使用结果列表里的ID安装包,例如
pio lib install 567
常用操作
- 查看当前项目支持的操作
pio run --list-targets
- 清除固件
pio run --target erase
- 编译固件,
pio run # 仅编译指定配置项 pio run -e nodemcu
编译成功后固件保存在.piio/build/[env]
目录。对于ESP,可用于OTA的固件为.pio/build/[env]/firmware.bin
。
- 编译并上传固件,连接设备后执行
pio run -t upload
使用-v
选项显示调试信息,比较有用的是使用这个选项后,会显示上传固件实际使用的命令,量产时可适当修改此命令后使用。例如下面是上传ESP32固件时用到的命令:
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /home/garfield/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader_dio_40m.bin 0x8000 /opt/garfield/projects/platformio/ESP32-TOF/.pio/build/featheresp32/partitions.bin 0xe000 /home/garfield/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/featheresp32/firmware.bin