TPH board inaccurate readings

Hi All I have been playing around with the Autonomo for a bit now and am having a hard time understanding how to get the TPH board readings to be close / accurate. I am very very new to Arduino so i’m sure this is a simple you forgot “x” or call it like “y” type of mistake. I also have tried other library for the TPH board. The adafruit library seemed to be more sporadic.

My TPH board seems to have recorded my house between -38C and 100C in two in a half minuets and between 0.27% and 90% humidity in about the same time frame.

The conditions in my house at the time of readings were no more less 16.6C(62F) and no more than 17.8C(64F) also the humidity in my house is between 40 - 45% These readings are from a device that I trust as accurate and also match the Nest thermostat that I have installed as well.

My Code:

#include <SD.h>
#include <Wire.h>
#include <Sodaq_BMP085.h>
#include <Sodaq_SHT2x.h>
#define dS SerialUSB
#define SD_SS_PIN SS_2
#define ADC_AREF 3.3
#define BATVOLTPIN BAT_VOLT 
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10
int num = 0;

Sodaq_BMP085 bmp;

void setup() {
  // put your setup code here, to run once:
  dS.begin(57600);
  pinMode(LED_BUILTIN, OUTPUT);
  setupTPH();
  if(!SD.begin(CS_SD))
 {
  dS.println("Error: SD card failed to initialise or is missing.");
 }
}
void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);
  String reading = takeTPHReading();
  reading += ", Batt " + String(getRealBatteryVoltageMV());
  num = num + 1;
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
   dataFile.println(reading);
   dataFile.close();
   // print to the serial port too:
   dS.println(reading);
  }
  // if the file isn't open, pop up an error:
else {
  dS.println("error opening datalog.txt");
  dS.println(reading);
}

  digitalWrite(LED_BUILTIN, LOW);
  delay(30000);
}

void setupTPH()
{
  //Initialize the wire protocol for the TPH sensors
  Wire.begin();

 //Initialize the TPH BMP sensor
  bmp.begin();
}

String takeTPHReading()
{
  //Create a String type data record in csv format
  //TempSHT21, TempBMP, PressureBMP, HumiditySHT21
  String data = String(num) + ", Temp " + String(SHT2x.GetTemperature())  + ", ";
  //BMPTemp is commented out, the data will be to long if you also send batt volt.
  data += "Temp " + String(bmp.readTemperature()) + ", ";
  data += "Pressure " + String(bmp.readPressure() / 100)  + ", ";
  data += "Humidity " + String(SHT2x.GetHumidity());

  return data;
}
float getRealBatteryVoltageMV()
{
  uint16_t batteryVoltage = analogRead(BATVOLTPIN);
  return (ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;
}

My data output for fourteen minuets.
0, Temp 18.75, Temp 65.80, Pressure 262, Humidity 56.69, Batt 4158.67
1, Temp 105.75, Temp 11.60, Pressure 945, Humidity 69.92, Batt 4163.41
2, Temp 107.17, Temp -33.00, Pressure 631, Humidity 42.18, Batt 4163.41
3, Temp 59.98, Temp 145.19, Pressure 621, Humidity 42.15, Batt 4163.41
4, Temp 20.83, Temp 98.09, Pressure 875, Humidity 88.17, Batt 4158.67
5, Temp 20.80, Temp 17.79, Pressure 1546, Humidity 43.00, Batt 4158.67
6, Temp 71.30, Temp 17.79, Pressure 984, Humidity 46.45, Batt 4158.67
7, Temp 99.60, Temp 93.50, Pressure 538, Humidity 91.47, Batt 4153.93
8, Temp 27.07, Temp -4.80, Pressure 639, Humidity 52.88, Batt 4153.93
9, Temp 93.60, Temp 32.40, Pressure 1099, Humidity 50.82, Batt 4153.93
10, Temp 30.43, Temp 165.60, Pressure 1331, Humidity 40.56, Batt 4153.93
11, Temp 29.59, Temp 35.00, Pressure 895, Humidity 39.60, Batt 4153.93
12, Temp 101.67, Temp 30.20, Pressure 1485, Humidity 78.96, Batt 4149.19
13, Temp 17.21, Temp -19.20, Pressure 577, Humidity 41.08, Batt 4149.19
14, Temp 72.58, Temp 8.89, Pressure 846, Humidity 70.09, Batt 4149.19
15, Temp 85.22, Temp 168.10, Pressure 42, Humidity 42.02, Batt 4149.19
16, Temp 60.12, Temp 61.79, Pressure 721, Humidity 42.02, Batt 4144.45
17, Temp 20.65, Temp 98.30, Pressure 1790, Humidity 21.75, Batt 4144.45
18, Temp 20.65, Temp 17.50, Pressure 1547, Humidity 0.52, Batt 4144.45
19, Temp -13.35, Temp 17.50, Pressure 984, Humidity 47.43, Batt 4144.45
20, Temp 51.55, Temp 37.90, Pressure 536, Humidity 105.20, Batt 4144.45
21, Temp 28.12, Temp 164.10, Pressure 533, Humidity 32.86, Batt 4144.45
22, Temp 109.82, Temp 34.70, Pressure 171, Humidity 34.22, Batt 4144.45
23, Temp 7.78, Temp 194.80, Pressure 2589, Humidity 68.89, Batt 4134.96
24, Temp 8.31, Temp -22.89, Pressure 943, Humidity 39.45, Batt 4139.70
25, Temp 17.24, Temp -20.89, Pressure 1400, Humidity 0.27, Batt 4144.45
26, Temp 17.03, Temp -12.60, Pressure 293, Humidity 87.95, Batt 4144.45
27, Temp -39.56, Temp 8.50, Pressure 330, Humidity 70.12, Batt 4139.70
28, Temp 107.19, Temp -26.79, Pressure 1438, Humidity 41.98, Batt 4139.70

There is a bug in the library manager from arduino.

Can you download the latest version of both libraries from:
Sodaq_BMP085
Sodaq_SHT2x

Then move it to: documents - Arduino - libraries
And remove the “-master” in the folder name

Jan
SODAQ

Thank you Jan!

That made that TPH board way more accurate my standard deviation is now .2 degrees and humidity is matching my other sensors in the house.

For those using Linux the file location for me was ~/Arduino/libraries/ Not sure if I set that location or if that is a default location.

Hi, I’m having similar problems. I’ve updated the libraries (in ~/Ardnuino/libraries). but I sort of get random values.
When I run the example above (without the SD card stuff), I get:
1, Temp 100.52, Temp 7.50, Pressure 1306, Humidity 70.71, Batt 3622.83
2, Temp -46.51, Temp 170.80, Pressure 862, Humidity 45.71, Batt 3618.09
3, Temp 60.98, Temp -227.69, Pressure 811, Humidity 45.71, Batt 3622.83
4, Temp 25.85, Temp 92.19, Pressure 1324, Humidity 21.80, Batt 3622.83
5, Temp 25.84, Temp 20.50, Pressure 963, Humidity 19.08, Batt 3618.09
6, Temp -7.23, Temp 20.50, Pressure 1021, Humidity 60.75, Batt 3622.83
7, Temp 30.28, Temp 170.60, Pressure 615, Humidity 7.30, Batt 3622.83
8, Temp 47.03, Temp 64.69, Pressure 890, Humidity 109.53, Batt 3622.83
9, Temp -29.31, Temp 65.00, Pressure 263, Humidity 110.89, Batt 3622.83
10, Temp 116.93, Temp -36.29, Pressure 1930, Humidity 19.58, Batt 3618.09
11, Temp 116.79, Temp 196.80, Pressure 715, Humidity 41.96, Batt 3622.83
12, Temp -10.12, Temp 197.80, Pressure 79, Humidity 63.54, Batt 3618.09

I tried some further debugging. When I only read the BMP sensor it works:

#include <Wire.h>
#include <SPI.h>

//SODAQ Mbili libraries
#include <Sodaq_BMP085.h>
#include <Sodaq_SHT2x.h>

//The delay between the sensor readings
#define READ_DELAY 1000

//Data header
#define DATA_HEADER "TimeDate, TempSHT21, TempBMP, PressureBMP, HumiditySHT21"

//TPH BMP sensor
Sodaq_BMP085 bmp;

void setup() 
{
  //Initialise the SerialUSB connection
  SerialUSB.begin(9600);
  
  //Initialise sensors
  setupSensors();
  
  //Echo the data header to the SerialUSB connection
  SerialUSB.println(DATA_HEADER);
}

void loop() 
{
  //Create the data record
  String dataRec = createDataRecord();
  
  //Echo the data to the SerialUSB connection
  SerialUSB.println(dataRec);
 
  //Wait before taking the next reading
  delay(READ_DELAY);
}

void setupSensors()
{
  //Initialise the wire protocol for the TPH sensors
  Wire.begin();
  
  //Initialise the TPH BMP sensor
  bmp.begin();

}


String createDataRecord()
{
  //Create a String type data record in csv format
  //TimeDate, TempSHT21, TempBMP, PressureBMP, HumiditySHT21
  String data ="";
  data += String(bmp.readTemperature()) + ", ";
  data += String(bmp.readPressure() / 100)  + ", ";

  //data += String(SHT2x.GetTemperature())  + ", ";
  //data += String(SHT2x.GetHumidity());

  return data;
}

Output:

20.79, 1021, 
20.79, 1021, 
20.79, 1021,  
20.79, 1021, 

But when I uncomment the 2 lines to read the SHTx sensor as well (at the bottom of the code), the data from both sensors get corrupted:

185.10, 617, 125.26, 42.24
125.00, 912, -13.51, 116.68
8.60, 1788, -12.74, 19.19
207.10, 827, -11.43, 18.61
44.59, 860, 45.05, 19.10
62.59, 1866, 98.87, 59.34
205.30, 217, 41.26, 97.66

Any ideas on what is going on?

Again really new to this Arduino thing but the SPI.h call where is that being used? I was reading that SPI was for serial deices but SerialUSB is something different if i am reading that right. Check your files in the SHT2 directory this is what i see on my computer.

md5sum ~/Arduino/libraries/Sodaq_SHT2x/src/*

bd1459cfbc497b3738d092be020bde0f  Sodaq_SHT2x.cpp
d606a949d588ec82f38d0b8752bd5760  Sodaq_SHT2x.h

If they dont match I would overwrite the files from git https://github.com/SodaqMoja/Sodaq_SHT2x/tree/master/src

Found and solved the problem. Thnx!. It appeared I fixed the Sodaq_SHT2x.* files in the wrong location.

Please can someone help me?
I’m a windows user and new to autonomo.
I changed the library Sodaq_SHT2x from Documents location
to the program files. I still have the same result " random values"
with the test file “ReadSHT2x”.

\Documents\Arduino\libraries
Is the place where the libraries have to be installed.

Can you download the latest version from:

Unzip the files, remove the “-master” in the name
And move it to \Documents\Arduino\libraries

Do this for both the BMP and SHT2x libraries.

Jan

Problem solved :smiley:!!
thanks Jan !!!

The best way to download from Github is to go the “releases” page of the specific library, say

https://github.com/SodaqMoja/Sodaq_SHT2x/releases

And then click on the zip or tar.gz link of the selected version (latest/newest version is a good choice).

Only if really want the latest and greatest you can click on the “download ZIP” (in which case you must remove “-master” from the file name.