1.环境配置
手动配置IDF内置pip包管理器
(注:这一步并不是必须的!是我本人琢磨出来的!网上貌似还没有这样的做法!我也不确定会不会出问题!如果不放心可以直接跳到第六步!)
打开安装IDF的路径里的python所在文件夹,可以看到python解释器放在了这里
espressif——>tools——>idf-python——>3.8.7 作者:老闲渔 https://www.bilibili.com/read/cv16677064/ 出处:bilibili
然后在地址栏输入“cmd”,按下回车,可直接在当前路径下打开命令提示符
经常 报失败 错误,解决办法
输入命令更新pip:python -m pip install --upgrade pip -i https://pypi.douban.com/simple
然后输入:cd Scripts 以进入下一级目录
最后将cmd关闭
以上是为了更新pip,防止下一步IDF插件报错,同时将pip换为国内源,加快下载速度
测试代码编写编译调试,下载
可以直接运行的代码
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_log.h"
#include "driver/gpio.h"
// #include "led_strip.h"
#define GPIO_OUTPUT_IO_0 18
#define GPIO_OUTPUT_IO_1 19
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_OUTPUT_IO_0) | (1ULL<<GPIO_OUTPUT_IO_1))
static void led_test(void)
{
/* Set the GPIO level according to the state (LOW or HIGH)*/
gpio_config_t io_conf = {};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
}
void app_main(void)
{
int cnt=0;
led_test();
printf("Hello world!\n");
while (1)
{
vTaskDelay(1000 / portTICK_RATE_MS);
gpio_set_level(GPIO_OUTPUT_IO_0|GPIO_OUTPUT_IO_1, cnt % 2);
cnt++;
}
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
for (int i = 100; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}
感谢作者 作者:老闲渔 的分享 https://www.bilibili.com/read/cv16677064/ 出处:bilibili