Device : nRF52840-QIAA
Version : Arduino Bootloader (SAM-BA extended) 2.0 [Arduino:IKXYZ]
Board Info : VID:0x2341 PID: 0x805A SN: CDA138793EC6FD8B
Windows 10 x64 Pro w/Arduino IDE 2.1.1
Nano 33 BLE Sense (original version)
Mbed OS Nano 4.0.2
HTS221 1.0.0
LPS22HB 1.0.2
Me: 30+ years dev; Java, C, C++; Arduino newbie
The sketch below is giving weird results. Immediately after upload it produces output like this:
Temp 70.372017 Humidity 0.000000 Pressure 1000.557129
Temp 70.288048 Humidity 0.000000 Pressure 1000.584473
Temp 70.372017 Humidity 0.000000 Pressure 1000.564453
Temp 70.372017 Humidity 0.000000 Pressure 1000.572510
Temp 70.455978 Humidity 0.000000 Pressure 1000.540771
The temp seems correct, but the actual humidity can't be zero. If I unplug the Nano's USB cable from the computer and plug it back in immediately, it now produces
Temp 84.118660 Humidity 38.283401 Pressure 1000.611572
Temp 84.152115 Humidity 38.531342 Pressure 1000.556641
Temp 84.285934 Humidity 38.373867 Pressure 1000.557617
Now the humidity seems about right, but the temp is 10 degrees F too high. Doing the same thing again results in:
Temp 32.000000 Humidity 0.000000 Pressure 1002.580322
Temp 32.000000 Humidity 0.000000 Pressure 1002.611084
Temp 32.000000 Humidity 0.000000 Pressure 1002.608887
Huh?
Left unplugged overnight, when I plugged it in this morning I get
Temp 80.338264 Humidity 46.100307 Pressure 1002.602295
Temp 80.405174 Humidity 45.999790 Pressure 1002.613525
Temp 80.371719 Humidity 46.096954 Pressure 1002.633545
The humidity is about right, but the temp is 5 F too high.
Then I re-uploaded the sketch with no changes, and now I get:
Temp 82.278648 Humidity 22.521841 Pressure 1002.542480
Temp 82.278648 Humidity 22.533716 Pressure 1002.513184
Temp 82.379013 Humidity 22.462463 Pressure 1002.545410
Temp is a bit higher, but I'd attribute that to the nano warming up, but the humidity dropped from 46% (about right) to 22%.
Is my Nano defective? If not, what am I doing wrong?
Here's the complete sketch:
#include <Arduino_HTS221.h>
#include <Arduino_LPS22HB.h>
int i=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
HTS.begin();
BARO.begin();
}
void loop() {
// put your main code here, to run repeatedly:
float temp = HTS.readTemperature(FAHRENHEIT);
float hum = HTS.readHumidity();
float press = BARO.readPressure(MILLIBAR);
char buffer[100];
sprintf(buffer, "Temp %f Humidity %f Pressure %f\n", temp, hum, press);
Serial.print(buffer);
delay(2000);
}