Hi, everyone . . . I’m back! Sorry for posting [AGAIN] but I have a simple sketch that is (in my little world) supposed to send BLE signals to an app on my phone but I cannot even see the signals in a 3rd party app like Light Blue or nRF Connect. Would someone with more talent in this field than I please look this over and point out what is probably obvious? Thank you so much!
#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"
Adafruit_BME280 bme;
BLEService bmeService(SERVICE_UUID);
BLEStringCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify, 100);
BLEStringCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify, 100);
BLEStringCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify, 100);
void setup() {
Serial.begin(9600);
while (!Serial);
if (!bme.begin()) {
Serial.println("Could not find BME280 sensor, check wiring!");
while (1);
}
if (!BLE.begin()) {
Serial.println("Failed to start BLE!");
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()) {
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;
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(String(temperature));
humidityCharacteristic.writeValue(String(humidity));
pressureCharacteristic.writeValue(String(pressure));
delay(1000);
}
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
It might work if you set the address of the BME280.
In my environment, your sketch works fine with BLE_Hero, BluetootLE, BLE_Scanner but not with LightBlue and nRF_Connect.
if (!bme.begin(0x76)) { // setting BME280 address
These are the first few lines of my void setup() code:
Serial.begin(9600);
while (!Serial);
Serial.println("I'm alive!!!!");
if (!bme.begin(0x76)) {
Serial.println("Could not find BME280 sensor, check wiring!");
while (1);
}
The sketch compiles and loads but I don’t see anything in my serial monitor which makes me think something is not quite right, code-wise.
Have you checked the address of your BME280 using I2C Scanner?
Check the port number before opening the Serial Monitor.
Try this, it also works with nRF_Connect.
BLE_BME280.zip (1023 Bytes)
Greetings (good morning),
Well, that was a unique senior moment. Last night, I couldn’t get the sketch to run. Now, in the morning, I must have corrected something. I can now see the device name (Psychrometer), and data readouts for the temperature, humidity, and pressure in my nRF Connect but it displays a UUID instead of the characteristic’s string name (i.e. “Temperature.”)
Please look at my nRF Connect screenshot and tell me, if you can, what is necessary to broadcast the string names.
Hi there,
Pretty sure that’s only (custom Char)if you use the Recognised service UUID, The environmental UUID,
Afaik.
HTH
GL PJ
Baby steps for my aching head, please;). Are we speaking about the limitations of 3rd party apps to read the string associated with a UUID or am I not even sending such data in the first place?
I would have stuck with the 0x181A shortcuts but I need to use string names that are not provided (dry air density, for instance). Is there a null or “fill-in-the-blank” shortcut character that can be assigned a string name?
The bottom line requirement is for my MIT App Inventor app to detect and display the information that I am now sending but it is not there quite yet.
Hi there,
I use MIT AI2 , use this tech to get your names and UUID’s and Chars fixed up.
HTH
GL PJ
https://www.professorcad.co.uk/appinventortips#BleUuids
Hi, PJ
I apologize for emailing you directly (senior moment). I will repeat my plea here for the benefit of all who may read. I have an Arduino sketch (previously reviewed) that proves itself with nRF Connect but fails to connect to my MIT App Inventor program. As I am mostly running in circles, I was hoping that you might look the following images over at your convenience and maybe discern why I am not picking up the signals that my nRF Connect sees? I appreciate the links you sent regarding the basics of the MIT App Inventor but this is as far as I can get on my own and it just isn’t happening (yet;). Everything seems to match but something is missing from the secret sauce.
I am pasting the screenshot of the app (the easy to build part;) and the block program to the best of my understanding. Were I to be able to actually build an App Inventor app that read BLE data from my device, I am 95% there, as I can re-create the blocks repeatedly as needed.