Circuitpython: SHTC3 sensor won't stay awake through a soft reset of ESP32-S2

Created on 13 Dec 2020  路  4Comments  路  Source: adafruit/circuitpython

There has been a fix for the SHTC3 not coping with a soft reset: https://github.com/adafruit/Adafruit_CircuitPython_SHTC3/pull/3. But this problem persists on the ESP32-S2 (I'm using a FeatherS2). The code below works fine on a Feather M0 Express.

My code:
```import board
import busio
import time

import adafruit_shtc3

i2c = busio.I2C(board.SCL, board.SDA)
sht = adafruit_shtc3.SHTC3(i2c)
while True:
print(sht.temperature)
time.sleep(1)

Running on this Feather:

print(os.uname())
(sysname='esp32s2', nodename='esp32s2', release='6.1.0', version='6.1.0-beta.2
on 2020-12-03', machine='FeatherS2 with ESP32S2')


Outputs this:

25.48
25.52
25.57

I press ctrl+s and it then outputs:

Code done running. Waiting for reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 8, in
File "adafruit_shtc3.py", line 89, in __init__
ValueError: No I2C device at address: 70
```

bug circuitpython api

All 4 comments

Hi, saw your comments on my PR, so just dropping in my 2 cents.

Does it behave differently with another I2C device?
When I was testing originally on SAMD21 I through I noticed different behaviour between busio.I2C and board.I2C - not properly closing/opening the I2C bus after soft reset. Could this be similar?

I don't have an S2 to test with unfortunately :(

Hi. That's a really good point, I haven't tried another I2C device on it yet. I'll give it a go and get back to you!

This appears to be another problem due to adafruit_bus_device-in-core. The pure Python version first tries a zero byte write to probe for the presence of a device at an address, though if that is not possible (when is it not possible?) it also tries a 1-byte read:

        try:
            self.i2c.writeto(self.device_address, b"")
        except OSError:
            # some OS's dont like writing an empty bytesting...
            # Retry by reading a byte
            try:
                result = bytearray(1)
                self.i2c.readfrom_into(self.device_address, result)
            except OSError:
                raise ValueError("No I2C device at address: %x" % self.device_address)

The core version only tries the 1-byte read, and the SHTC3 doesn't like it:

    uint8_t status = common_hal_adafruit_bus_device_i2cdevice_readinto(self, (uint8_t*)bufinfo.buf, 1);
    if (status != 0) {
        common_hal_adafruit_bus_device_i2cdevice_unlock(self);
        mp_raise_ValueError_varg(translate("No I2C device at address: %x"), self->device_address);

In the core, we should use the probe function in the common hal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

No1089 picture No1089  路  31Comments

deshipu picture deshipu  路  44Comments

kattni picture kattni  路  49Comments

dhalbert picture dhalbert  路  122Comments

dhalbert picture dhalbert  路  25Comments