Mbed library for SHTC3 humidity & temperature sensor
SHTC3
Mbed library for SHTC3 humidity & temperature sensor
Example
#include "mbed.h"
#include "SHTC3.h"
SHTC3 sht(PB_9, PB_8);
int main() {
if (!sht.init()) {
printf("Init failed\n");
return 0;
}
while (1) {
uint16_t raw_temp, raw_humidity;
if (sht.read(&raw_temp, &raw_humidity)) {
printf("Temperature: %f*C (%u), humidity: %f%% (%u)\n", sht.toCelsius(raw_temp), raw_temp,
sht.toPercentage(raw_humidity), raw_humidity);
} else {
printf("Read failed\n");
}
ThisThread::sleep_for(2s);
}
}
If you don’t see float numbers in the console output, you need to turn on the support of float for printf
json { "target_overrides": { "*": { "platform.minimal-printf-enable-floating-point": true, "platform.minimal-printf-set-floating-point-max-decimals": 6 } } }
Example passing I2C object
#include "mbed.h"
#include "SHTC3.h"
I2C i2c(PB_9, PB_8);
SHTC3 sht;
int main() {
if (!sht.init(&i2c)) {
printf("Init failed\n");
return 0;
}
while (1) {
uint16_t raw_temp, raw_humidity;
if (sht.read(&raw_temp, &raw_humidity)) {
printf("Temperature: %f*C (%u), humidity: %f%% (%u)\n", sht.toCelsius(raw_temp), raw_temp,
sht.toPercentage(raw_humidity), raw_humidity);
} else {
printf("Read failed\n");
}
ThisThread::sleep_for(2s);
}
}