这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » esp32S3与手机蓝牙通信调试过程

共5条 1/1 1 跳转至

esp32S3与手机蓝牙通信调试过程

菜鸟
2026-07-13 07:53:09   被打赏 35 分(兑奖)     打赏

产品概述

 

Adafruit 5691ESP32S3 Reverse TFT Feather) 是美国Adafruit公司推出的Feather规格物联网开发板,集成ESP32S3无线模组、1.14英寸反向安装TFT彩屏,专为面板安装与带屏IoT原型设计,支持Arduino/CircuitPython双开发环境。

二、核心参数

- 主控:ESP32S3Xtensa LX7双核,240 MHz),4 MB Flash + 2 MB PSRAM + 512 KB SRAM

- 无线:WiFi 802.11 b/g/n2.4 GHz)、Bluetooth 5.x BLE,模组带FCC/CE认证。

- 显示:1.14英寸IPS TFT240×135像素,反向安装(背面出线)。

- 接口:STEMMA QTI²C)、原生USBGPIO排针,预留3个按键位置。

- 供电:3.3 V,支持USB/电池供电,Feather标准尺寸(51×23 mm)。

三、产品特点

 ESP32-S3 REVERSE TFT FEATHER

1. 反向屏幕设计:TFT屏装在板背,适配面板嵌入安装,正面可贴面板/外壳。

2. 大容量存储:4 MB Flash+2 MB PSRAM,支持CircuitPython大程序与图像缓存。

3. 即插即用生态:STEMMA QT免焊传感器扩展,Adafruit IO云平台无缝对接。

4. 双编程支持:Arduino IDECircuitPython,适合入门到进阶开发。

5. 无线一体化:WiFi+BLE双模,覆盖IoT数据传输与蓝牙近场通信场景。

四、测评内容

   本次测评将使用开发板与手机蓝牙进行通讯,编写通信程序,出现缺少库文件,引入错误:

image.png 

lib中找到对应文件夹或者文件COPYesp32s3对应目录下,如图所示:

image.png


image.png 

在调试过程中遇到很多问题比如:这个错误 TypeError: unexpected keyword argument 'notify' 表明你使用的 adafruit_ble 库版本中,Uint16Characteristic(或父类 Characteristic)的构造函数‌不接受‌ notify 作为关键字参数。

在较新版本的 adafruit_ble 中,‌通知(Notify)功能是通过 properties 参数控制的‌,而不是单独的 notify=True 标志。

修正方案

请移除 notify=True 参数,并确保 properties 中包含 Characteristic.NOTIFY

修改服务定义代码

将你的 CustomHeartRateService 类修改为如下形式:简化版(推荐,兼容性最好)

如果权限参数也导致问题,最稳妥的写法是‌只保留必要参数‌:

class CustomHeartRateService(adafruit_ble.Service):

    uuid = StandardUUID(0x180D)

    # 仅指定 UUID properties

    measurement = Uint16Characteristic(

        uuid=StandardUUID(0x2A37),

        properties=Characteristic.NOTIFY

    )

    location = Uint8Characteristic(

        uuid=StandardUUID(0x2A38),

        properties=Characteristic.READ

    )

为什么这样改?

properties 参数:在 BLE 协议中,特征值的属性(Properties)决定了它支持的操作(如 READ, WRITE, NOTIFY, INDICATE)。adafruit_ble 库通过 properties=Characteristic.NOTIFY 来告知底层栈该特征值支持通知,从而自动创建 CCCD(客户端配置描述符)。

notify 参数:这是旧版库或某些其他 BLE 库(如 bleak Arduino 库)的用法,在当前的 adafruit_ble 中已不再作为构造函数的独立参数存在。

image.png 

完整代码如下:

import time

import adafruit_ble

from adafruit_ble.advertising.standard import ProvideServicesAdvertisement

from adafruit_ble.services.standard.device_info import DeviceInfoService

from adafruit_ble.uuid import StandardUUID

from adafruit_ble.characteristics import Characteristic

from adafruit_ble.characteristics.int import Uint16Characteristic, Uint8Characteristic

 

# 定义自定义心率服务

class CustomHeartRateService(adafruit_ble.Service):

    uuid = StandardUUID(0x180D)

    

    measurement = Uint16Characteristic(

        uuid=StandardUUID(0x2A37),

        properties=Characteristic.NOTIFY

    )

    

    location = Uint8Characteristic(

        uuid=StandardUUID(0x2A38),

        properties=Characteristic.READ

    )

 

# 1. 初始化 BLE

ble = adafruit_ble.BLERadio()

 

# 2. 创建服务

hr_service = CustomHeartRateService()

dis = DeviceInfoService(

    software_revision=adafruit_ble.__version__,

    manufacturer="Adafruit Industries"

)

 

 

# 3. 创建广播包

advertisement = ProvideServicesAdvertisement(hr_service, dis)

advertisement.complete_name = "ESP32-S3-HR"

 

# 4. 启动广播

ble.start_advertising(advertisement)

print("正在广播心率服务... 名称: ESP32-S3-HR")

 

while True:

    # 等待连接

    while not ble.connected:

        pass

    

    print("已连接!")

    

    # 模拟发送心率数据

    bpm = 60

    while ble.connected:

        # 直接赋值给特征值

        hr_service.measurement = bpm

        

        print(f"发送心率: {bpm} BPM")

        

        bpm += 1

        if bpm > 100:

            bpm = 60

            

        time.sleep(1)

        

    # 断开后重新广播

    ble.start_advertising(advertisement)

    print("断开连接,重新广播...")

 

最后终于将心率数据从esp32s3端发送至手机蓝牙接收,下图是手机调试接收数据界面:

image.png 

总结:主要是编译器版本兼容性不好,很多错误需要使用AI辅助才能找到,对初学者不友好,能不能在兼容性上进行改进?





关键词: 蓝牙    

高工
2026-07-13 09:45:13     打赏
2楼

屏幕能显示吗?


菜鸟
2026-07-13 13:02:53     打赏
3楼

当然能用


管理员
2026-07-16 13:17:36     打赏
4楼

这种过程性分享对有类似需求的开发者非常有帮助


院士
2026-07-19 10:46:53     打赏
5楼

谢谢分享。


共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]