RobTillaart / SHT31

Arduino library for the SHT31 temperature and humidity sensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SHT31 library with Arduino-ESP32 v2.0.5

oscarbaselga opened this issue · comments

commented

Hi Rob,

I recently installed your library for my ESP32 T-Beam which I am building with the arduino-esp32 v1.0.6 (from this url). Everything works fine!
However, I decided to update the arduino-esp32 version to 2.0.5 and same code does not work.
This is the conflicting code itself:

SensorX::SensorX() {
    Wire.begin();
    bool sht_begin = sht.begin(SHT31_ADDRESS);
    sht.reset();
    Wire.setClock(100000);
}

When commenting sht (declared as SHT31 sht;) calls, the rest of the code continues working.

I am using SHT31 v0.3.4 and TinyWireM v1.1.0.

Any help?

Hi Oscar,

Thanks for the issue, I'm rather busy at the moment so it can take a few days before diving into this.

Is there any error message?

commented

Thanks for your quick response Rob!

No, there is no error message. The expected behavior is to print a debug message but it is not appearing. What is happening is that my ESP32 is interrupted by the watchdog:

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13160
load:0x40080400,len:3036
entry 0x400805e4

When commenting sht (declared as SHT31 sht;) calls, the rest of the code continues working.

This remark is ambiguous as sht is used multiple times.

Which line is commented?

Note: I have no hardware to setup an equivalent, so I depend on your testing.

commented

I was referring to these lines: bool sht_begin = sht.begin(SHT31_ADDRESS); and sht.reset(); of the previous code.
The rest of the code is independent from SHT31 library, as it only prints some debug messages.

Can you create a minimal sketch that fails? As I have not enough clues yet.

I am using packages\esp32\hardware\esp32\1.0.6 in my tests (and I need to keep that config )

commented

My fault!! It is already fixed. I do not know the reason but moving this code...

Wire.begin();
bool sht_begin = sht.begin(SHT31_ADDRESS);
sht.reset();
Wire.setClock(100000);

...out of the constructor, it works properly.
It is weird that with arduino-esp32 v1.0.6 worked but not with v2.0.5.

Thank you for your support, I will remove this issue after you read it so as not to mess up the repository.

Read on the Arduino forum long ago that code in the constructor has the risk that not all hardware is initialized when constructor is executed and can cause unwanted side effects (aka crash). So initializing a variable to 42 is ok, but checking complexer IO e.g. I2C depends on when the Wire constructor is executed.

Satisfied with the library? Missing things?
Otherwise you may close the issue.