Temp, Humidity, & Pressure data via BLE and Serial

Hi All,

Am working on a script that will use a Arduino Nano 33 BLE to share air temp, humidity, & pressure sensor data via BLE radio (functions as a BLE peripheral) and/or via serial cable. Would appreciate your insights.

Am able to pull and print regularly refreshed data air temp, humidity, & pressure sensor data via serial cable.

My assumption is that by using a sensor delay I can get regularly refreshed sensor data ... this assumption is valid with respect to serial terminal visible data. Do not know if this is a valid assumption for BLE data

Am able to see the Arduino as well as air temp (2A6E), humidity (2A6F), & pressure (2A6D) characteristics (but not the associated data) on the Bluefruit, nRFconnect, and LightBlue BLE smartphone apps with the serial terminal open. Would like to have the data visible and readable on the app without having to translate hex

My assumption is that I have a coding issue and that this is resulting in a inability to see the data on the BLE smartphone apps

float temperature = HTS.readTemperature();                  // read HTS221 temp & humidty sensor for BLE
  float humidity    = HTS.readHumidity();
  float tempF = (temperature*(1.8))+32;
  tempCharacteristic.writeValue(temperature);                 // advertise temperature (2A6E) via BLE
  humidCharacteristic.writeValue(humidity);                   // advertise humidity (2A6F) via BLE 
  
  // https://www.arduino.cc/en/Reference/ArduinoBLEBLECharacteristicwriteValue
  // https://www.arduino.cc/en/Reference/ArduinoBLEBLECharacteristicreadValue    
  // https://www.arduino.cc/en/Reference/ArduinoBLEBLEDescriptorread

Apparently there is a 9,000 character limit per post.

Full code is located here on GitHub

TemperaturePressureHumidity_BLE

Hi surfnm

First of all, I have code for this specific purpose, however, it cannot connect to BLE without opening the Serial Monitor. I will link it down below. It also uses the SPS30 particulate matter sensor. But I would like to ask a doubt first: How did you connect the Sense to BlueFruit Connect? I am dying to know.

surfnm:
My assumption is that by using a sensor delay I can get regularly refreshed sensor data ... this assumption is valid with respect to serial terminal visible data. Do not know if this is a valid assumption for BLE data

You should not use delay as a general principle. On most Arduino's delay() stops your sketch and wastes processor cycles, on the Arduino Nano 33 BLE it uses sleep. So, you can use delay in instances where you want to save power. But when you use a communication stack you cannot sleep while you want the stack to work.

Have a look at the BlinkWithoutDelay example on how to execute parts of your code periodically or my example (see link below).

File -> Examples -> 02.Digital -> BlinkWithoutDelay

surfnm:
Am able to see the Arduino as well as air temp (2A6E), humidity (2A6F), & pressure (2A6D) characteristics (but not the associated data) on the Bluefruit, nRFconnect, and LightBlue BLE smartphone apps with the serial terminal open.

Your sketch does not update the characteristics, only the local variable. (see my example)

surfnm:
Would like to have the data visible and readable on the app without having to translate hex

These apps are generic. Some decode known characteristics, but only when they are in the right format.

Have a look at an Environmental Sensing Service example I have posted in the following post. Reply #3

A central for decoding is in reply #6.

Thanks for the code share Guntas !

Guntas:
How did you connect the Sense to BlueFruit Connect? I am dying to know.

I used the Installation and Setup | Bluefruit LE Connect tutorial from Adafruit to get the app up and running. Hopefully this will work for you as well

Thanks for the code shares Klaus_K !

Klaus_K:
You should not use delay as a general principle. On most Arduino's delay() stops your sketch and wastes processor cycles, on the Arduino Nano 33 BLE it uses sleep. So, you can use delay in instances where you want to save power. But when you use a communication stack you cannot sleep while you want the stack to work.

Klaus_K:
Your sketch does not update the characteristics, only the local variable. (see my example)

Greatly appreciate all the insights, am working on updating my script/sketch