0

作为参考,我使用的是 Arduino Nano 33 BLE Sense 板。

目前,我可以让 nrFToolbox 应用程序将板识别为蓝牙设备,但仅此而已。我希望能够使用该应用程序来获取有关温度的数据并显示它。

#include <Arduino_LPS22HB.h> //Pressure sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoLPS22HB
#include <Arduino_HTS221.h>  //Temperature sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoHTS221
#include <ArduinoBLE.h>      //Bluetooth LE sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoBLE


// Service for the BLE module, using a 128-bit UUID.
BLEService TestService("32BC370F-88AF-4928-B8AB-9B56902FA670");

//TODO: BLE temperature characteristic

//TODO: BLE humidity characteristic

//TODO: BLE pressure characteristic

void setup() {
// put your setup code here, to run once:
    Serial.begin(9600); //Initialize the serial connection
    while(!Serial); //Will pause until a serial connection is established.

    if (!BARO.begin() ) { //Initialize the barometer
    Serial.println("Unable to initialize the barometer, stopping.");
    while (1);
    }
    if (!HTS.begin() ) { //Initialize the Temperature & Humidity sensor
        Serial.println("Unable to initialize the temp/humidity sensor, stopping.");
        while (1);
    }
    if (!BLE.begin() ) { //Initialize the bluetooth module
        Serial.println("Unable to initialize the bluetooth module, stopping");
        while (1);
    }


    /* Set a local name for the BLE device
    This name will appear in advertising packets
    and can be used by remote devices to identify this BLE device
    The name can be changed but maybe be truncated based on space left in advertisement packet
    */
    BLE.setLocalName("TestDevice");
    BLE.setAdvertisedService(TestService); // add the service UUID



}

void loop() {
// put your main code here, to run repeatedly:
    Serial.print("Temperature: ");
    Serial.print(HTS.readTemperature(FAHRENHEIT));
    Serial.print(" -- Humidity: ");
    Serial.print(HTS.readHumidity() );
    Serial.print(" -- Pressure: ");
    Serial.println(BARO.readPressure() );
    delay(1000);
}
4

0 回答 0