Measure air pressure via bluetooth

Hello,

I am running this code to measure air pressure via bluetooth and powering the Nano BLE 33 with 3.7v battery, when I remove while (!Serial) from the code I can see the bluetooth name at the device list but I cannot connect to the BLE to read the data? any idea what is going on here

#include <ArduinoBLE.h>
#include <Arduino_LPS22HB.h>

// Create a custom BLE service
BLEService pressureService("180F"); // Custom BLE service UUID

// Create a BLE float characteristic for the pressure data
BLEFloatCharacteristic pressureCharacteristic("2A6D", BLERead | BLENotify);

void setup() {
Serial.begin(9600);
while (!Serial);

// Initialize the pressure sensor
if (!BARO.begin()) {
Serial.println("Failed to initialize pressure sensor!");
while (1);
}

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

// Set the local name for the BLE device
BLE.setLocalName("Nano33BLE");

// Set up the BLE service and characteristic
BLE.setAdvertisedService(pressureService);
pressureService.addCharacteristic(pressureCharacteristic);
BLE.addService(pressureService);

// Start advertising the BLE service
BLE.advertise();

Serial.print("Peripheral device MAC: ");
Serial.println(BLE.address());
Serial.println("Waiting for connections...");
}

void loop() {
// Wait for a BLE central device to connect
BLEDevice central = BLE.central();

if (central) {
Serial.print("Connected to central MAC: ");
Serial.println(central.address());

while (central.connected()) {
  // Read the pressure value in kPa
  float pressure = BARO.readPressure();

  // Update the BLE characteristic with the pressure value
  pressureCharacteristic.writeValue(pressure);

  // Print the pressure value for debugging purposes
  Serial.print("Atmospheric Pressure = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  delay(1000);  // Wait 1 second before sending the next reading
}

Serial.print("Disconnected from central MAC: ");
Serial.println(central.address());

}
}

You must put code and errors in < CODE > blocks. This helps you by making the code readable. This is what your code must look like:

#include <ArduinoBLE.h>
#include <Arduino_LPS22HB.h>

// Create a custom BLE service
BLEService pressureService("180F"); // Custom BLE service UUID

// Create a BLE float characteristic for the pressure data
BLEFloatCharacteristic pressureCharacteristic("2A6D", BLERead | BLENotify);

void setup() {
  Serial.begin(9600);
  while (!Serial);
  // Initialize the pressure sensor
  if (!BARO.begin()) {
    Serial.println("Failed to initialize pressure sensor!");
    while (1);
  }
  // Initialize BLE
  if (!BLE.begin()) {
    Serial.println("Starting BLE failed!");
    while (1);
  }
  // Set the local name for the BLE device
  BLE.setLocalName("Nano33BLE");
  // Set up the BLE service and characteristic
  BLE.setAdvertisedService(pressureService);
  pressureService.addCharacteristic(pressureCharacteristic);
  BLE.addService(pressureService);
  // Start advertising the BLE service
  BLE.advertise();
  Serial.print("Peripheral device MAC: ");
  Serial.println(BLE.address());
  Serial.println("Waiting for connections...");
}

void loop() {
  // Wait for a BLE central device to connect
  BLEDevice central = BLE.central();
  if (central) {
    Serial.print("Connected to central MAC: ");
    Serial.println(central.address());
    while (central.connected()) {
      // Read the pressure value in kPa
      float pressure = BARO.readPressure();
      // Update the BLE characteristic with the pressure value
      pressureCharacteristic.writeValue(pressure);
      // Print the pressure value for debugging purposes
      Serial.print("Atmospheric Pressure = ");
      Serial.print(pressure);
      Serial.println(" kPa");
      delay(1000);  // Wait 1 second before sending the next reading
    }
    Serial.print("Disconnected from central MAC: ");
    Serial.println(central.address());
  }
}

Describe what you expect to see and your observations.

What are you using for the central device?