Hello everyone,
I wrote this code for the 33 BLE Sense, utilising its HTS221 sensor and streaming the data over BLE. However, when this code is uploaded, the regular COM port of the Nano disappears. However, when I double click RESET and the bootloader appears, the COM port for it appears and I upload the Blink sketch. Could someone please help me fix it?
#include <ArduinoBLE.h>
#include <Arduino_HTS221.h>
BLEService HTS221service("0000181a-0000-1000-8000-00805f9b34fb"); // BLE LED Service
float tempC = HTS.readTemperature();
float humidity = HTS.readHumidity();
BLEFloatCharacteristic Temp("00002a1f-0000-1000-8000-00805f9b34fb", BLERead | BLENotify);
BLEFloatCharacteristic Humidity("00002a6f-0000-1000-8000-00805f9b34fb",BLERead | BLENotify);
void setup() {
// put your setup code here, to run once:
BLE.begin();
Serial.begin(9600);
pinMode(LEDB,OUTPUT);
if (!BLE.begin()) {
Serial.println("BLE failed to Initiate");
delay(500);
while (1);
}
BLE.setLocalName("HTS221 Measurement");
BLE.setAdvertisedService(HTS221service);
HTS221service.addCharacteristic(Temp);
HTS221service.addCharacteristic(Humidity);
BLE.addService(HTS221service);
Temp.writeValue(tempC);
Humidity.writeValue(humidity);
BLE.advertise();
Serial.println("BLE device is now active, waiting for connections...");
}
void loop() {
// put your main code here, to run repeatedly:
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
digitalWrite(LEDB,LOW);
}
while (central.connected()) {
Serial.println("Temperature = ");
Serial.print(tempC);
Serial.print(" °C");
Temp.writeValue(tempC);
Serial.println("Humidity = ");
Serial.print(humidity);
Serial.print(" %");
Humidity.writeValue(humidity);
}
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
digitalWrite(LEDB,HIGH);
}