mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
67 lines
1.2 KiB
C++
67 lines
1.2 KiB
C++
//
|
|
// FILE: SHT31_isConnected.ino
|
|
// AUTHOR: Rob Tillaart
|
|
// VERSION: 0.1.0
|
|
// PURPOSE: demo (needs 0.2.4 or up)
|
|
// URL: https://github.com/RobTillaart/SHT31
|
|
|
|
|
|
#include "Wire.h"
|
|
#include "SHT31.h"
|
|
|
|
#define SHT31_ADDRESS 0x44
|
|
|
|
uint32_t start;
|
|
uint32_t stop;
|
|
|
|
SHT31 sht;
|
|
uint32_t connectionFails = 0;
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println(__FILE__);
|
|
Serial.print("SHT31_LIB_VERSION: \t");
|
|
Serial.println(SHT31_LIB_VERSION);
|
|
|
|
Wire.begin();
|
|
sht.begin(SHT31_ADDRESS);
|
|
Wire.setClock(100000);
|
|
|
|
uint16_t stat = sht.readStatus();
|
|
Serial.print(stat, HEX);
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
if ( sht.isConnected() )
|
|
{
|
|
start = micros();
|
|
sht.read(); // default = true/fast slow = false
|
|
stop = micros();
|
|
Serial.print(millis());
|
|
Serial.print("\t");
|
|
Serial.print(stop - start);
|
|
Serial.print("\t");
|
|
Serial.print(sht.getTemperature(), 1);
|
|
Serial.print("\t");
|
|
Serial.print(sht.getHumidity(), 1);
|
|
}
|
|
else
|
|
{
|
|
connectionFails++;
|
|
Serial.print(millis());
|
|
Serial.print("\tNot connected:\t");
|
|
Serial.print(connectionFails);
|
|
// sht.reset();
|
|
}
|
|
Serial.println();
|
|
delay(100);
|
|
}
|
|
|
|
|
|
// -- END OF FILE --
|