GY-63_MS5611/libraries/SHT31/examples/SHT31_isConnected/SHT31_isConnected.ino

77 lines
1.4 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: SHT31_isConnected.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo (needs 0.2.4 or up)
// URL: https://github.com/RobTillaart/SHT31
2021-05-28 07:45:10 -04:00
2021-01-29 06:31:58 -05:00
#include "Wire.h"
#include "SHT31.h"
#define SHT31_ADDRESS 0x44
uint32_t start;
uint32_t stop;
SHT31 sht;
uint32_t connectionFails = 0;
2021-05-28 07:45:10 -04:00
2021-01-29 06:31:58 -05:00
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();
}
2021-05-28 07:45:10 -04:00
2021-01-29 06:31:58 -05:00
void loop()
{
if ( sht.isConnected() )
{
start = micros();
2021-09-20 05:41:38 -04:00
bool b = sht.read(); // default = true/fast slow = false
2021-01-29 06:31:58 -05:00
stop = micros();
2021-09-20 05:41:38 -04:00
int error = sht.getError();
uint16_t stat = sht.readStatus();
2021-01-29 06:31:58 -05:00
Serial.print(millis());
Serial.print("\t");
Serial.print(stop - start);
Serial.print("\t");
2021-09-20 05:41:38 -04:00
Serial.print(b, HEX);
Serial.print("\t");
Serial.print(error, HEX);
Serial.print("\t");
Serial.print(stat, HEX);
Serial.print("\t");
2021-01-29 06:31:58 -05:00
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();
2021-09-20 05:41:38 -04:00
delay(1000);
2021-01-29 06:31:58 -05:00
}
2021-05-28 07:45:10 -04:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-28 06:31:55 -05:00