首页 > 其他分享 >esp32笔记[1]-blink闪灯

esp32笔记[1]-blink闪灯

时间:2023-01-27 03:22:06浏览次数:52  
标签:led -- esp32 blink 闪灯 idf GPIO LED

硬件平台

开发板:ESP32 DEVKIT V1
主控模块:ESP WROOM-32

获取例程

git clone -b v4.4 --recursive https://gitee.com/EspressifSystems/esp-idf.git

例程在esp-idf/examples/get-started/blink
修改例程中的IO口,要不然灯是不会闪的
blink_example_main.c

/* Blink 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 "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "led_strip.h"
#include "sdkconfig.h"

static const char *TAG = "example";

/* 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 CONFIG_BLINK_GPIO
#define BLINK_GPIO 2
static uint8_t s_led_state = 0;

#ifdef CONFIG_BLINK_LED_RMT
static led_strip_t *pStrip_a;

static void blink_led(void)
{
    /* If the addressable LED is enabled */
    if (s_led_state) {
        /* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */
        pStrip_a->set_pixel(pStrip_a, 0, 16, 16, 16);
        /* Refresh the strip to send data */
        pStrip_a->refresh(pStrip_a, 100);
    } else {
        /* Set all LED off to clear all pixels */
        pStrip_a->clear(pStrip_a, 50);
    }
}

static void configure_led(void)
{
    ESP_LOGI(TAG, "Example configured to blink addressable LED!");
    /* LED strip initialization with the GPIO and pixels number*/
    pStrip_a = led_strip_init(CONFIG_BLINK_LED_RMT_CHANNEL, BLINK_GPIO, 1);
    /* Set all LED off to clear all pixels */
    pStrip_a->clear(pStrip_a, 50);
}

#elif CONFIG_BLINK_LED_GPIO

static void blink_led(void)
{
    /* Set the GPIO level according to the state (LOW or HIGH)*/
    gpio_set_level(BLINK_GPIO, s_led_state);
}

static void configure_led(void)
{
    ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
    gpio_reset_pin(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
}

#endif

void app_main(void)
{

    /* Configure the peripheral according to the LED type */
    configure_led();

    while (1) {
        ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
        blink_led();
        /* Toggle the LED state */
        s_led_state = !s_led_state;
        vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
    }
}

macOS搭建ESP-IDF环境(docker)

[https://blog.csdn.net/skb666/article/details/122007521]

安装编译环境

#获取docker镜像
docker pull espressif/idf:v4.4
#简化指令
alias esp-idf='docker run --rm --privileged -v $PWD:/project -w /project -it espressif/idf:v4.4 bash -c'
#使用示例
#esp-idf "idf.py set-target esp32"
#编译blink
docker run --name=espidf --privileged -v $PWD:/project -w /project -d espressif/idf:v4.4 /bin/sh -c "while true; do sleep 1; done"
docker exec -it espidf bash
##进入容器
cd ./proj_blink/blink
source /opt/esp/idf/export.sh
idf.py set-target esp32
#idf.py menuconfig
idf.py build
exit



宿主机安装烧录工具

#安装esp烧入工具
python3 -m pip install esptool -i https://pypi.tuna.tsinghua.edu.cn/simple
#擦除原有程序(改成自己的串口号,可能要sudo)
ls /dev/cu*
esptool.py --chip esp32 --port /dev/cu.usbserial-0001 erase_flash
#烧入bin文件(注意匹配你的 bin文件名、串口号、flash大小与速率、传输波特率等)
cd ./proj_blink/blink/build
esptool.py --chip esp32 --port /dev/cu.usbserial-0001 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x1000 bootloader/bootloader.bin 0x10000 blink.bin 0x8000 partition_table/partition-table.bin


效果


标签:led,--,esp32,blink,闪灯,idf,GPIO,LED
From: https://www.cnblogs.com/qsbye/p/17068485.html

相关文章

  • 合宙ESP32S3 CameraWebServe 测试demo
    合宙ESP32S3CameraWebServe合宙ESP32S3CameraWebServe测试,我们需要一个OV2640的摄像头模组用来采集图像传输给ESP32的,这里使用的OV2640是之前安信可十周年的白嫖的。现......
  • 合宙ESP32S3 Demo
    合宙刚出了一款ESP32S3开发板,依旧邮票孔。趁着活动19.9入手了2块,挺不错的,看了网上视频片段lvgl8可以跑到60+。blink开发板拿到手之后是默认的闪灯程序。下面创建platfo......
  • 《安富莱嵌入式周报》第299期:IAR发布嵌入式软开发基础问题PDF,树莓派单片机运行Verilog
    往期周报汇总地址:http://www.armbbs.cn/forum.php?mod=forumdisplay&fid=12&filter=typeid&typeid=104 视频版:https://www.bilibili.com/video/BV1xW4y137bv 1、I......
  • Oracle DBLINK 简单使用
     oracle在进行跨库访问时,可以通过创建dblink实现,今天就简单的介绍下如果创建dblink,以及通过dblink完成插入、修改、删除等操作     首先了解下环境:在tnsnames.o......
  • ESP32-C3 CORE 开发板,接口摸底
    合宙的ESP32-C3CORE开发板有经典版(含CH343转串口芯片)和简约版(USB直接拉通芯片),设备管理器中显示的串口号不同:        下载2个版本的线路图,D4-GPIO......
  • ESP32中断的使用
    定时器中断硬件中断attachInterrupt(pin,ISR,mode);pin管脚号ISR中断处理函数mode触发中断的模式,可以使用的值有。LOW低电平触发CHANGE管脚电平变化......
  • OpenOCD + DAP-LINK 调试ESP32的失败经历(2)
    背景https://www.cnblogs.com/liteng0305/p/17018299.html上次使用乐鑫编译好的OpenOCD失败,可能是因为没有开启CMSIS-DAP支持,手动开启编译试一下平台UbuntuLinux5.4.......
  • ESP32 IDF V5.0 编译环境
    方法:环境搭建工具一键安装:下载链接:https://dl.espressif.com/dl/esp-idf/  可以选择离线安装方式和在线安装方式,建议:采用离线安装的方式下载离线安装包之后点击安装......
  • ESP32 I2C 总线主模式通信程序
    一、概述这里主要是记录ESP32中进行I2C通行的基本程序,也可以说是I2C总线驱动程序,当然这里只是作为主模式,从模式我还没需要这个需求,以后有机会贴上。此笔记的主要目......
  • esp32 cam
    https://blog.csdn.net/weixin_43935402/article/details/125590294 ,esp32cam从安装、烧录到成为webcam详细教程前言:本教程仅适用于ESP32-CAM开发板且带下载主板的......