Greetings, All
I have a functioning Arduino IDE sketch using an ESP32C3 and a BME280. When I start the sketch, it is waiting for a start signal or handshake. I am using nRF Connect to initiate the process. When I press “Connect” in nRF Connect, the sketch comes to life, printing the temperature, humidity, and atmospheric pressure to the serial interface. It quickly connects to my nRF Connect but I am unable to decode the data. I have tried “Hex,” “Signed Integer,”, “Unsigned Integer,” etc to no avail. The numbers I get on my nRF Connect readout do not correlate to the data.
I am including my .ino sketch and screenshots from nRF Connect. I circled the data outputs in red. If someone could tell me why I am not seeing the data I expect (temp, humidity, pressure) in nRF Connect, I would really appreciate it. I have been spinning my wheels on this for a week but I have to defer to the community on this one. Thank you.
#include <ArduinoBLE.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BLE_NAME "Psychrometer"
#define SERVICE_UUID "19B10000-E8F2-537E-4F6C-D104768A1214"
#define TEMPERATURE_UUID "19B10001-E8F2-537E-4F6C-D104768A1214"
#define HUMIDITY_UUID "19B10002-E8F2-537E-4F6C-D104768A1214"
#define PRESSURE_UUID "19B10003-E8F2-537E-4F6C-D104768A1214"
// Create BME280 sensor object
Adafruit_BME280 bme;
BLEService bmeService(SERVICE_UUID);
BLEFloatCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify);
BLEFloatCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify);
BLEFloatCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify);
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("Failed to start BLE!");
while (1);
}
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
BLE.setLocalName(BLE_NAME);
BLE.setAdvertisedService(bmeService);
bmeService.addCharacteristic(temperatureCharacteristic);
bmeService.addCharacteristic(humidityCharacteristic);
bmeService.addCharacteristic(pressureCharacteristic);
BLE.addService(bmeService);
temperatureCharacteristic.writeValue(0);
humidityCharacteristic.writeValue(0);
pressureCharacteristic.writeValue(0);
BLE.advertise();
Serial.println("BLE peripheral is now active");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
while (central.connected()) {
// Read actual sensor values
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0; // Convert Pa to hPa
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
temperatureCharacteristic.writeValue(temperature);
humidityCharacteristic.writeValue(humidity);
pressureCharacteristic.writeValue(pressure);
delay(1000);
}
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}