mauriciobarroso / sht4x

ESP-IDF component for SHT40, SHT41 and STH45 temperature and relative humidity sensors
MIT License
1 stars 0 forks source link

Where to get the header file "i2c_bus.h" #1

Open JL1946 opened 10 months ago

JL1946 commented 10 months ago

Would like to use your library in my application... I find that it is well done and clearly annotated... However, I cannot find the include file "i2c_bus.h" in the esp-idf repo... Please add to your repo, or indicated where to get it from...

thank you

mauriciobarroso commented 10 months ago

Hi @JL1946 sorry for the lack of instructions on the use of the component. The i2c_bus.h file is part of a component named i2c_bus found here: https://github.com/mauriciobarroso/i2c_bus.git

The libraries sht4x and i2c_bus work together, the following code show how they must be used.

#include "i2c_bus.h"
#include "sht4x.h"

i2c_bus_t i2c_bus;
sht4x_t sht41;

void app_main(main) {
    /* Initialize I2C bus */
    i2c_bus_init(&i2c_bus,      /* I2C bus instance */
        I2C_NUM_0,      /* I2C port number */
        I2C_BUS_SDA_PIN,    /* I2C SDA gpio number */
        I2C_BUS_SCL_PIN,    /* I2C SCL gpio number */
        false,              /* I2C SDA pullup resistor */
        false,              /* I2C SCL pullup resistor */
        400000));           /* I2C frequency */

    /* Initialize SHT4x */
    sht4x_init(&sht41,      /* SHT4x instance */
        &i2c_bus,       /* I2C bus instance pointer */
        SHT41_I2C_ADDR_44,  /* I2C device address */
        NULL,           /* Use default I2C bus read funciton */
        NULL);          /* Use default I2C bus read funciton */

    /* Get and print temperature and humidity */
    float temp, hum;

    sht4x_measure_high_precision(&sht41, &temp, &hum);

    printf("Temperature: %f, Humidity: %f", temp, hum);
}
JL1946 commented 10 months ago

thank you very much... I do have another question... could you advise on how to implement an SHT4x and mcp23008 port expander (address 0x20) together on the same i2c bus? I am working with both devices and am using the NSBum mcp23008 library (https://github.com/NSBum/esp32-mcp23008.git)... thanks again for your prompt response...

mauriciobarroso commented 10 months ago

I would have to write an mcp23008 library compatible with i2c_bus. It's not something too complex, but for now I don't have enough time.