After initializing of the I2C bus with
from machine import Pin,I2C
i2c = (id=-1,scl=Pin(22),sda=Pin(21))
where the id parameter defines the I2C bus:
devices = i2c.scan()
This will return a Python list with the addresses of all connected devices. The rest of the program is a question of print formatting.
This is an extremely relevant exercise because it shows typical work that must be done during an IoT project. Often code from other authors can be found on the Internet (e.g. github) but often you find problems with this. Maybe it is
After having uploaded mysht30.py I simply copy the first example to a Python script and modify the import statement:
and this is what I see when running it:
Well, this does not look good! So, let's have a look if the SHT30 is found on the I2Cbus. This is the code found in the sht30 README.md:
and here is the result:
This looks good but ... When I take the SHT30 off the triple base, I still get the same result which is much less good! Looking into the mysht30.py code I see that by default pin 5 is used for SCL and pin 4 for SDA, which is not correct for our board! Now we have 2 options:
With this change I see the Is connected: True if the SHT30 is connected and Is connected: False if I remove it.
Let's try the measurement script again:
Different, but not much better!
Let's try to send a reset command with a little script, not using the sht30 driver:
with this result:
This tells me that start() and stop() are not supported by the I2C driver on the ESP32. Looks like the I2C start and stop conditions have been integrated into the writeto() and readfrom() methods! Let's just remove those two calls:
As you can see, the reset now works without errors. And since we are at it, let's try to make a measurement without passing through the SHT30 class:
with this result:
Now that we know how to read and write the SHT30 using the ESP32 I2C driver, we can make the necessary corrections in the SHT30 class. After the change all the code snippets in the README.md file should work.
First I made a table with all functions the SHT30 offers and their command codes. I also checked which functions are implemented in the above SHT30 driver. See SHT30NopI2CTemperatureAndHumiditySensor for details about the development of the driver.
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
crcError.png | r1 | manage | 24.7 K | 2020-05-18 - 10:48 | UliRaich | |
![]() |
i2cWrongPins.png | r1 | manage | 21.6 K | 2020-05-18 - 11:22 | UliRaich | |
![]() |
sht30BusError.png | r1 | manage | 17.2 K | 2020-05-18 - 12:38 | UliRaich | |
![]() |
sht30Check.png | r1 | manage | 7.3 K | 2020-05-18 - 11:22 | UliRaich | |
![]() |
sht30CmdOk.png | r1 | manage | 71.2 K | 2020-05-18 - 13:19 | UliRaich | |
![]() |
sht30CmdTest-1.png | r1 | manage | 41.6 K | 2020-05-18 - 20:09 | UliRaich | |
![]() |
sht30CmdTest.png | r1 | manage | 41.6 K | 2020-05-18 - 20:07 | UliRaich | |
![]() |
sht30CmdV2.png | r1 | manage | 80.7 K | 2020-05-18 - 20:19 | UliRaich | |
![]() |
sht30Connected.png | r1 | manage | 12.3 K | 2020-05-18 - 11:22 | UliRaich | |
![]() |
sht30Init.png | r1 | manage | 26.4 K | 2020-05-18 - 12:33 | UliRaich | |
![]() |
sht30Meas.png | r1 | manage | 9.8 K | 2020-05-18 - 13:20 | UliRaich | |
![]() |
sht30MeasOk.png | r1 | manage | 6.6 K | 2020-05-18 - 13:22 | UliRaich | |
![]() |
sht30NotSupported-1.png | r1 | manage | 19.8 K | 2020-05-18 - 20:09 | UliRaich | |
![]() |
sht30Reset.png | r1 | manage | 3.6 K | 2020-05-18 - 13:02 | UliRaich |