Skip to content
/ SHTC3 Public

Mbed library for SHTC3 humidity & temperature sensor

License

Notifications You must be signed in to change notification settings

pilotak/SHTC3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SHTC3

Framework Badge mbed

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

{
  "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);
    }
}

About

Mbed library for SHTC3 humidity & temperature sensor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages