64 lines
1.1 KiB
Arduino
Raw Normal View History

2019-02-18 14:01:41 +01:00
//
// FILE: SHT31_I2Cspeed
// AUTHOR: Rob Tillaart
2020-11-27 11:33:55 +01:00
// PURPOSE: testing the performance at different I2C speeds
// URL: https://github.com/RobTillaart/SHT31
2019-02-18 14:01:41 +01:00
2021-05-28 13:45:10 +02:00
2019-02-18 14:01:41 +01:00
#include "Wire.h"
#include "SHT31.h"
2021-01-29 12:31:58 +01:00
#define SHT31_ADDRESS 0x44
2019-02-18 14:01:41 +01:00
uint32_t start;
uint32_t stop;
SHT31 sht;
2021-05-28 13:45:10 +02:00
2019-02-18 14:01:41 +01:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("SHT31_LIB_VERSION: \t");
Serial.println(SHT31_LIB_VERSION);
Wire.begin();
2021-01-29 12:31:58 +01:00
sht.begin(SHT31_ADDRESS);
2019-02-18 14:01:41 +01:00
Wire.setClock(100000);
2020-11-27 11:33:55 +01:00
2019-02-18 14:01:41 +01:00
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
2020-11-27 11:33:55 +01:00
Serial.println();
2019-02-18 14:01:41 +01:00
}
2021-05-28 13:45:10 +02:00
2019-02-18 14:01:41 +01:00
void loop()
{
for (uint32_t I2Cfreq = 100000; I2Cfreq < 900000; I2Cfreq += 50000)
{
Serial.print(I2Cfreq/1000);
Wire.setClock(I2Cfreq);
test();
}
}
void test()
{
start = micros();
sht.read(true); // default = true/fast slow = false
stop = micros();
Serial.print("\t");
Serial.print(stop - start);
Serial.print("\t");
2020-11-27 11:33:55 +01:00
Serial.print(sht.getTemperature(), 1);
2019-02-18 14:01:41 +01:00
Serial.print("\t");
2020-11-27 11:33:55 +01:00
Serial.println(sht.getHumidity(), 1);
2019-02-18 14:01:41 +01:00
delay(100);
2020-11-27 11:33:55 +01:00
}
2021-05-28 13:45:10 +02:00
2020-11-27 11:33:55 +01:00
// -- END OF FILE --
2021-12-28 12:31:55 +01:00