RobTillaart / SHT2x

Arduino library for the SHT2x series temperature and humidity sensors including SHT20, 21, 25.
MIT License
19 stars 5 forks source link

Wrong values reported due to incorrect I2C pin configuration on current ESP32 Arduino API #9

Closed jannvck closed 2 years ago

jannvck commented 2 years ago

In the current ESP32 Arduino API the TwoWire.begin() method takes two int arguments where in your implementation two uint8_t arguments are provided which results in incorrect I2C pin configuration and wrong sensor measurement values reported on ESP32. Specifying int8_t arguments works as the underlying HAL initialisation method takes those.

See the begin() method in Wire.cpp. See also the i2cInit method in esp32-hal-i2c.h.

Suggested solution: The constructor should be changed from bool begin(const uint8_t dataPin, const uint8_t clockPin) to bool begin(const int8_t dataPin, const int8_t clockPin)

RobTillaart commented 2 years ago

Thanks for this issue.
I will fix it asap

RobTillaart commented 2 years ago

As the ESP32 1.0.6 package defines

    bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus

I will fix it to

bool begin(const int dataPin, const int clockPin)

Rationale is that I call Wire.begin() so I match that interface.

RobTillaart commented 2 years ago

Develop branch created with fix. plus a fix for the getEIDB()

RobTillaart commented 2 years ago

@jannvck Do you have time to confirm the develop branch is working for you? (I got no compile error)

jannvck commented 2 years ago

Thank you for the quick fix! I can confirm the develop branch is working for me. The sensor reports proper values now. I have not tested getEIDB(), though.

RobTillaart commented 2 years ago

Thanks for verifying, I will merge a.s.a.p