Ai-WB2-32S gpio驱动RGB灯

本文详细介绍了在LinuxUbuntu环境下,通过BL60XSDK编写的GPIO驱动程序来控制RGB灯的全过程,包括创建目录、编写Makefile、proj_config.mk文件,以及编译和烧录步骤。
摘要由CSDN通过智能技术生成


前言

本期博客介绍使用库编写gpio驱动RGB灯。
如果想要使用下面流程,请先查看Linux Ubuntu下烧录固件的过程,点击此链接进行查看

一、具体流程

第1步 进入目录

cd ~/Ai-Thinker-WB2/applications/get-started
创建目录gpio
图一

第2步 进入gpio目录并创建如下文件/目录

图二

第3步 编写Makefile文件(代码如下)

#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := gpio
PROJECT_PATH := $(abspath .)
PROJECT_BOARD := evb
export PROJECT_PATH PROJECT_BOARD
#CONFIG_TOOLPREFIX :=

-include ./proj_config.mk

ifeq ($(origin BL60X_SDK_PATH), undefined)
BL60X_SDK_PATH_GUESS ?= $(shell pwd)
BL60X_SDK_PATH ?= $(BL60X_SDK_PATH_GUESS)/../../..
$(info ****** Please SET BL60X_SDK_PATH ******)
$(info ****** Trying SDK PATH [$(BL60X_SDK_PATH)])
endif

COMPONENTS_BLSYS   := bltime blfdt blmtd bloop loopadc looprt loopset
COMPONENTS_VFS     := romfs

INCLUDE_COMPONENTS += freertos_riscv_ram bl602 bl602_std newlibc hosal mbedtls_lts lwip vfs yloop utils cli blog blog_testc coredump
INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK)
INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS)
INCLUDE_COMPONENTS += $(COMPONENTS_VFS)
INCLUDE_COMPONENTS += $(PROJECT_NAME)

include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk

第4步编写proj_config.mk文件(代码如下)

#
#compiler flag config domain
#
#CONFIG_TOOLPREFIX :=
#CONFIG_OPTIMIZATION_LEVEL_RELEASE := 1
#CONFIG_M4_SOFTFP := 1

#
#board config domain
#
CONFIG_BOARD_FLASH_SIZE := 2

#firmware config domain
#

#set CONFIG_ENABLE_ACP to 1 to enable ACP, set to 0 or comment this line to disable
#CONFIG_ENABLE_ACP:=1
CONFIG_BL_IOT_FW_AP:=1
CONFIG_BL_IOT_FW_AMPDU:=0
CONFIG_BL_IOT_FW_AMSDU:=0
CONFIG_BL_IOT_FW_P2P:=0
CONFIG_ENABLE_PSM_RAM:=1
#CONFIG_ENABLE_CAMERA:=1
#CONFIG_ENABLE_BLSYNC:=1
#CONFIG_ENABLE_VFS_SPI:=1
CONFIG_ENABLE_VFS_ROMFS:=1
CONFIG_EASYFLASH_ENABLE:=0

CONFIG_SYS_APP_TASK_STACK_SIZE:=4096
CONFIG_SYS_APP_TASK_PRIORITY:=15

CONFIG_FREERTOS_TICKLESS_MODE:=0
CONFIG_SYS_VFS_ENABLE:=1
CONFIG_SYS_VFS_UART_ENABLE:=1
CONFIG_SYS_AOS_CLI_ENABLE:=0
CONFIG_SYS_AOS_LOOP_ENABLE:=1
CONFIG_SYS_BLOG_ENABLE:=1
CONFIG_SYS_DMA_ENABLE:=0
CONFIG_SYS_USER_VFS_ROMFS_ENABLE:=0
CONFIG_BL602_USE_ROM_DRIVER:=1
CONFIG_BT_CENTRAL:=1
CONFIG_BT_OBSERVER:=1
CONFIG_BT_PERIPHERAL:=1
CONFIG_BT_STACK_CLI:=1
CONFIG_BT_WIFIPROV_SERVER:=1
CONFIG_WIFI:=0

CONF_ENABLE_COREDUMP:=1

LOG_ENABLED_COMPONENTS:=blog_testc hosal loopset looprt bloop gpio

第5步 编写README.md文件(代码如下,该文件不参与执行)

# Blink Example

## Example Output

As you run the example, you will see the log :


Booting Ai-WB2 Modules...
------------------------------------------------------------
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Oct  8 2022
Build Time: 15:42:26
------------------------------------------------------------

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
[         0][INFO: hal_boot2.c: 282] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
[         0][INFO: hal_boot2.c:  82] ======= PtTable_Config @0x4200d158=======
[         0][INFO: hal_boot2.c:  83] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
[         0][INFO: hal_boot2.c:  89] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
[         0][INFO: hal_boot2.c:  91] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
[         0][INFO: hal_boot2.c:  91] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
[         0][INFO: bl_flash.c: 391] ======= FlashCfg magiccode @0x42049c18=======
[         0][INFO: bl_flash.c: 392] mid 		0x5E
[         0][INFO: bl_flash.c: 393] clkDelay 	0x1
[         0][INFO: bl_flash.c: 394] clkInvert 	0x1
[         0][INFO: bl_flash.c: 395] sector size	4KBytes
[         0][INFO: bl_flash.c: 396] page size	256Bytes
[         0][INFO: bl_flash.c: 397] ---------------------------------------------------------------
[         0][INFO: hal_board.c:1249] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
[         0][INFO: hal_board.c:1257] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0


Note: The color order could be different according to the LED model.

## Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

第6步 进入gpio目录并创建如下文件

图三

第7步 根据原理图编写main.c文件(代码如下)

图四


#include <stdio.h>
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include <bl_gpio.h>

#define GPIO_B_PIN 3
#define GPIO_R_PIN 14
#define GPIO_G_PIN 17

void blink_test(void *param)
{
    bl_gpio_enable_output(GPIO_B_PIN, 0, 0);
    bl_gpio_enable_output(GPIO_R_PIN, 0, 0);
    bl_gpio_enable_output(GPIO_G_PIN, 0, 0);
    while (1)
    {
        bl_gpio_output_set(GPIO_B_PIN, 1);
        vTaskDelay(1000);
        bl_gpio_output_set(GPIO_B_PIN, 0);
        bl_gpio_output_set(GPIO_R_PIN, 1);
        vTaskDelay(1000);
        bl_gpio_output_set(GPIO_R_PIN, 0);
        bl_gpio_output_set(GPIO_G_PIN, 1);
        vTaskDelay(1000);
        bl_gpio_output_set(GPIO_G_PIN, 0);
    }
}

void main(void)
{
    xTaskCreate(blink_test, "blink", 1024, NULL, 15, NULL);
}

第8步 编写bouffalo.mk文件(代码如下)

#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

include $(BL60X_SDK_PATH)/components/network/ble/ble_common.mk

ifeq ($(CONFIG_ENABLE_PSM_RAM),1)
CPPFLAGS += -DCONF_USER_ENABLE_PSRAM
endif

ifeq ($(CONFIG_ENABLE_CAMERA),1)
CPPFLAGS += -DCONF_USER_ENABLE_CAMERA
endif

ifeq ($(CONFIG_ENABLE_BLSYNC),1)
CPPFLAGS += -DCONF_USER_ENABLE_BLSYNC
endif

ifeq ($(CONFIG_ENABLE_VFS_SPI),1)
CPPFLAGS += -DCONF_USER_ENABLE_VFS_SPI
endif

ifeq ($(CONFIG_ENABLE_VFS_ROMFS),1)
CPPFLAGS += -DCONF_USER_ENABLE_VFS_ROMFS
endif

二、编译并烧录

第1步 进入~/Ai-Thinker-WB2/applications/get-started/gpio目录

cd ~/Ai-Thinker-WB2/applications/get-started/gpio

图五

第2步 执行make -j8

图六

第3步 执行make flash p=/dev/ttyUSB0 b=115200(此时模组需要连接到虚拟机)

图七

三 执行结果图

图八
图九
图十

总结

以上就是本期分享的内容,目的为了介绍如何使用库点亮RGB灯,更多资料可从安信可官网上获取。

官方官网:https://www.ai-thinker.com
开发资料:https://docs.ai-thinker.com/
官方论坛:http://bbs.ai-thinker.com
技术支持:support@aithinker.com

  • 21
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,我们可以得知ESP32C3-32S开发板支持WiFi和蓝牙通信,并且可以通过串口通讯发送代码。同时,我们还需要使用霍尔传感器和RGB,并将数据上传到腾讯云。因此,我们需要进行以下步骤: 1. 配置开发环境:根据引用中提供的文献和资料下载,搭建ESP32C3-32S开发环境。 2. 连接硬件:将霍尔传感器和RGB连接到开发板上。 3. 编写代码:使用引用中提供的代码作为基础,编写读取霍尔传感器和控制RGB的代码,并将数据上传到腾讯云。 4. 上传数据到腾讯云:使用腾讯云提供的API,将数据上传到云端。 下面是一个简单的示例代码,用于读取霍尔传感器和控制RGB,并将数据上传到腾讯云: ```c #include <WiFi.h> #include <HTTPClient.h> #include <ArduinoJson.h> const char* ssid = "your_SSID"; const char* password = "your_PASSWORD"; const char* serverName = "your_server_name"; int hallSensorPin = 34; int redLedPin = 32; int greenLedPin = 33; int blueLedPin = 25; void setup() { Serial.begin(115200); pinMode(hallSensorPin, INPUT); pinMode(redLedPin, OUTPUT); pinMode(greenLedPin, OUTPUT); pinMode(blueLedPin, OUTPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); } void loop() { int hallSensorValue = digitalRead(hallSensorPin); int redLedValue = digitalRead(redLedPin); int greenLedValue = digitalRead(greenLedPin); int blueLedValue = digitalRead(blueLedPin); if (hallSensorValue == HIGH) { digitalWrite(redLedPin, HIGH); digitalWrite(greenLedPin, LOW); digitalWrite(blueLedPin, LOW); } else { digitalWrite(redLedPin, LOW); digitalWrite(greenLedPin, HIGH); digitalWrite(blueLedPin, LOW); } String serverPath = "/api/data"; String payload = "{\"hallSensorValue\": " + String(hallSensorValue) + ", \"redLedValue\": " + String(redLedValue) + ", \"greenLedValue\": " + String(greenLedValue) + ", \"blueLedValue\": " + String(blueLedValue) + "}"; Serial.println(payload); if (WiFi.status() == WL_CONNECTED) { HTTPClient http; http.begin(serverName, serverPath); http.addHeader("Content-Type", "application/json"); int httpResponseCode = http.POST(payload); if (httpResponseCode > 0) { String response = http.getString(); Serial.println(httpResponseCode); Serial.println(response); } else { Serial.println("Error on sending POST request"); } http.end(); } else { Serial.println("Error in WiFi connection"); } delay(1000); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值