You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Arduino Nicla Voice BLE连接反复断开问题求助(毕业设计)

Arduino Nicla Voice BLE连接后立即断开循环问题

我们开发的关键词识别设备仅含Arduino Nicla Voice板和电池,当前遇到的问题是:程序上传后设备进入等待连接状态,但手机连接时串口日志显示连接后立即断开,该循环持续至手机配对超时。

已尝试的排查步骤:

  • 更新设备固件
  • 更换官方示例程序测试
  • 使用nRF Connect工具连接,问题依旧
  • 尝试官方手册中的BLE代码,故障未解决

参考代码

#include "NDP.h"
#include "Nicla_System.h"
#include <ArduinoBLE.h>

BLEService wordService("180D"); 
BLEUnsignedCharCharacteristic wordRecognitionChar("2A37", BLERead | BLENotify); 

const bool lowestPower = false;

void ledBlueOn(char* label) {
  if (!lowestPower) {
    if (strcmp(label, "NN0:si_sacha") == 0) {
      nicla::leds.begin();
      nicla::leds.setColor(blue);
      delay(200);
      nicla::leds.setColor(off);
      Serial.println(label);

      int wordRecognitionResult = 1;  // Assuming "si_sacha" is recognized
      wordRecognitionChar.writeValue(wordRecognitionResult);
    }
  }
  nicla::leds.end();
}

void setup() {
  Serial.begin(115200);
  nicla::begin();
  nicla::disableLDO();
  nicla::leds.begin();

  NDP.onError([]() {});
  NDP.onMatch(ledBlueOn);
  NDP.onEvent([]() {});
  Serial.println("Loading synpackages");
  Serial.println("This is a custom flash for sacha model");
  NDP.begin("mcu_fw_120_v91.synpkg");
  NDP.load("dsp_firmware_v91.synpkg");
  NDP.load("ei_model.synpkg");
  Serial.println("Packages loaded");
  NDP.getInfo();
  Serial.println("Configure mic");
  NDP.turnOnMicrophone();
  NDP.interrupts();

  nicla::leds.end();

  if (lowestPower) {
    NRF_UART0->ENABLE = 0;
  }

  if (!BLE.begin()) {
    Serial.println("Starting BLE failed!");
    while (1)
      ;
  }

  BLE.setLocalName("Sacha");
  wordService.addCharacteristic(wordRecognitionChar);
  BLE.setAdvertisedService(wordService);
  BLE.addService(wordService);

  BLE.advertise();
  Serial.println("- Bluetooth device active, waiting for connections...");
}

void loop() {
  uint8_t command = 0xFF;

  while (Serial.available()) {
    command = Serial.read();
    if (command == 'f') {
      Serial.println("Interrupts disabled");
      NDP.noInterrupts();
    } else if (command == 'o') {
      Serial.println("Interrupts enabled");
      NDP.interrupts();
    }
  }

  BLEDevice central = BLE.central();

  // Check if a central device is connected
  if (central) {
    Serial.print("- Connected to central: ");
    Serial.println(central.address());
    nicla::leds.setColor(green);

    // Wait for the central device to disconnect
    while (central.connected()) {
      delay(200);
    }

    // The central device has disconnected, print the message
    nicla::leds.setColor(off);
    Serial.print("- Disconnected from central: ");
    Serial.println(central.address());
  }

  delay(100);
}

串口日志

Loading synpackages
This is a custom flash for sacha model
Packages loaded
dsp firmware version: 19.2.0
package version: Model generated by Edge Impulse
pbi version: 3.2.3-0
num of labels: 4
labels: NN0:no_sacha, NN0:noise, NN0:si_sacha, NN0:unkown
total deployed neural networks: 1
Configure mic
- Bluetooth device active, waiting for connections...
NN0:si_sacha
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b
- Connected to central: 7e:95:54:e7:d5:2b
- Disconnected from central: 7e:95:54:e7:d5:2b

预期正常行为

设备应保持BLE连接状态,识别到关键词"si_sacha"时向手机发送信号。项目临近截止,急需解决思路。


解决思路

  1. 检查BLE服务UUID冲突:代码中使用的180D是官方心率服务UUID,可能导致手机端服务解析异常触发断开。更换为自定义UUID(如12345678-1234-1234-1234-1234567890AB格式)测试。
  2. 优化BLE连接循环逻辑:当前loop()中每次都会调用BLE.central(),连接后进入的while(central.connected())循环里仅用delay(200),可能导致BLE栈无法及时处理手机端的通信请求。将delay替换为BLE.poll(),确保BLE事件正常处理:
    while (central.connected()) {
      BLE.poll();
      delay(50);
    }
    
  3. 排查电源稳定性:仅用电池供电时,可能存在电压波动导致BLE模块复位。尝试用USB供电测试,排除电源问题;若必须用电池,检查电池输出电压是否稳定在3.3V±5%范围内。
  4. 禁用不必要的功耗优化:代码中nicla::disableLDO()可能影响BLE模块供电稳定性,注释该行后测试。
  5. 检查BLE特征权限:确保手机端有读取/通知权限,尝试将特征权限改为BLERead | BLENotify | BLEWrite(临时测试),排除权限问题。

内容的提问来源于stack exchange,提问作者Alfredo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 14:36:02