#include "aht.h" #include "hardware/i2c.h" #include "pico/stdlib.h" static const uint8_t AHT_MEASURE[3] = {0xAC, 0x33, 0x00}; void getAHTData(double *t, double *h) { uint8_t result[6]; uint32_t temperature; uint32_t humidity; i2c_write_blocking(i2c_default, AHT_ADDR, AHT_MEASURE, 3, false); // trigger measurement // now we must delay ~100ms sleep_ms(100); i2c_read_blocking(i2c_default, AHT_ADDR, result, 6, false); // read 6 bytes back humidity = (result[1] << 12) | (result[2] << 4) | (result[3] & 0xF0) >> 4; temperature = (result[3] & 0x0F) << 16 | (result[4] << 8) | result[5]; *t = (((double)temperature / 1048576.0f) * 200.0f) - 50.0f; *h = ((double)humidity / 1048576.0f) * 100.0f; return; }