使用 ESP IDF 开发 Esp Iot 项目
安装开发工具
在官方网站下载 esp idf 开发工具,并按照要求安装。
创建项目
使用官方的 esp idf template 或者 https://github.com/twn39/esp-idf-template 创建项目,进行项目名称等参数更改,可参考 esp idf 目录自带的 example 中的 hello world 项目。
配置编译组件和选项
打开 idf 命令行,切换路径到项目目录,运行:
idf.py menuconfig
自定义编译命令和组件,配置完成之后会保存为 sdkconfig。
编写代码
这里参考 hello world 示例代码:
#include <stdio.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "sdkconfig.h" /* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink, or you can edit the following line and set a number here. */ #define BLINK_GPIO 2 void app_main() { /* Configure the IOMUX register for pad BLINK_GPIO (some pads are muxed to GPIO on reset already, but some default to other functions and need to be switched to GPIO. Consult the Technical Reference for a list of pads and their default functions.) */ gpio_pad_select_gpio(BLINK_GPIO); /* Set the GPIO as a push/pull output */ gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT); while(1) { /* Blink off (output low) */ printf("Turning off the LED\n"); gpio_set_level(BLINK_GPIO, 0); vTaskDelay(1000 / portTICK_PERIOD_MS); /* Blink on (output high) */ printf("Turning on the LED\n"); gpio_set_level(BLINK_GPIO, 1); vTaskDelay(1000 / portTICK_PERIOD_MS); } }
编译、烧入和监控
编译:
idf.py build
烧入和监控:
idf.py -p COM5 -b 115200 flash monitor
需要注意的是这里用到的 esp32 波特率为 115200
, 默认的是 460800
。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论