2019-03-05 12:45:36 -05:00
|
|
|
//
|
2020-11-27 05:33:55 -05:00
|
|
|
// FILE: SHT31_async.ino
|
2019-03-05 12:45:36 -05:00
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:33:55 -05:00
|
|
|
// VERSION: 0.0.2
|
|
|
|
// PURPOSE: demo async interface
|
|
|
|
// URL: https://github.com/RobTillaart/SHT31
|
2019-03-05 12:45:36 -05:00
|
|
|
|
|
|
|
#include "Wire.h"
|
|
|
|
#include "SHT31.h"
|
|
|
|
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
2020-11-27 05:33:55 -05:00
|
|
|
uint32_t cnt;
|
2019-03-05 12:45:36 -05:00
|
|
|
|
|
|
|
SHT31 sht;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("SHT31_LIB_VERSION: \t");
|
|
|
|
Serial.println(SHT31_LIB_VERSION);
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
sht.begin(0x44);
|
|
|
|
Wire.setClock(100000);
|
2020-11-27 05:33:55 -05:00
|
|
|
|
2019-03-05 12:45:36 -05:00
|
|
|
uint16_t stat = sht.readStatus();
|
|
|
|
Serial.print(stat, HEX);
|
2020-11-27 05:33:55 -05:00
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
sht.requestData();
|
|
|
|
cnt = 0;
|
2019-03-05 12:45:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2020-11-27 05:33:55 -05:00
|
|
|
if (sht.dataReady())
|
2019-03-05 12:45:36 -05:00
|
|
|
{
|
2020-11-27 05:33:55 -05:00
|
|
|
start = micros();
|
|
|
|
bool success = sht.readData(); // default = true = fast
|
|
|
|
stop = micros();
|
|
|
|
sht.requestData(); // request for next sample
|
|
|
|
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.print("\t");
|
|
|
|
if (success == false)
|
|
|
|
{
|
|
|
|
Serial.println("Failed read");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Serial.print(sht.getTemperature(), 1);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.print(sht.getHumidity(), 1);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println(cnt);
|
|
|
|
cnt = 0;
|
|
|
|
}
|
2019-03-05 12:45:36 -05:00
|
|
|
}
|
2020-11-27 05:33:55 -05:00
|
|
|
cnt++; // simulate activity
|
2019-03-05 12:45:36 -05:00
|
|
|
}
|
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
// -- END OF FILE --
|