这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » 【ArduinoGigaR1WiFi】BLE控制

共1条 1/1 1 跳转至

【ArduinoGigaR1WiFi】BLE控制

菜鸟
2026-02-08 14:24:09     打赏

         板载的蓝牙+WiFi模块(村田LBEE5KL1DX-883)芯片是CYW4343W,规格是WiFi4(IEEE 802.11n)和蓝牙5.1(BE/EDR+BLE双模),这里STM32H747XIhostCYW4343WRCP射频协处理器,各自的控制通道不一样,WLANSDIO v3BluetoothHCI,其中BLE就是UART7来下发HCI命令的,

WiFi模块.PNG

试了下mbed的例程包括Firmata->StandardFirmataBLE并没有适配Giga R1 WiFi,需要自己区定义HAL,尝试了一下报很多错误,这里想起来ArduinoBLE本身就有BLE库,于是导入之后用BLE成功添加GATT数据库、广播并建立连接,

LED.PNG


代码如下:

void setup() {
  Serial.begin(9600);
  while (!Serial);
 
  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);
 
  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");
 
    while (1);
  }
 
  // set advertised local name and service UUID:
  BLE.setLocalName("Arduino Giga R1 Wifi");
  BLE.setAdvertisedService(ledService);
 
  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);
 
  // add service
  BLE.addService(ledService);
 
  // set the initial value for the characteristic:
  switchCharacteristic.writeValue(0);
 
  // start advertising
  BLE.advertise();
 
  Serial.println("BLE LED Peripheral");
}
 
void loop() {
  // listen for Bluetooth® Low Energy peripherals to connect:
  BLEDevice central = BLE.central();
 
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
 
    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, LOW);         // will turn the LED off
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, HIGH);          // will turn the LED on
        }
      }
    }
 
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}





关键词: BLE    

共1条 1/1 1 跳转至

回复

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