Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHTC3 sensor won't stay awake through a soft reset of ESP32-S2 #3821

Closed
laurastephsmith opened this issue Dec 13, 2020 · 5 comments
Closed
Assignees
Labels
bug circuitpython api espressif applies to multiple Espressif chips
Milestone

Comments

@laurastephsmith
Copy link

There has been a fix for the SHTC3 not coping with a soft reset: adafruit/Adafruit_CircuitPython_SHTC3#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 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 <module>
  File "adafruit_shtc3.py", line 89, in __init__
ValueError: No I2C device at address: 70
@Cybot101
Copy link

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 :(

@laurastephsmith
Copy link
Author

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!

@jepler jepler self-assigned this Dec 14, 2020
@tannewt tannewt added this to the 6.x.x - Bug Fixes milestone Dec 15, 2020
@jepler
Copy link
Member

jepler commented Dec 23, 2020

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);

@tannewt
Copy link
Member

tannewt commented Dec 23, 2020

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

@dhalbert dhalbert added the espressif applies to multiple Espressif chips label Mar 31, 2021
@dhalbert dhalbert modified the milestones: 6.x.x - Bug Fixes, 7.0.0 Mar 31, 2021
@jepler
Copy link
Member

jepler commented Jul 15, 2021

@laurastephsmith Please re-test and let us know if this is still a problem for you. We believe it was fixed by #3936.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug circuitpython api espressif applies to multiple Espressif chips
Projects
None yet
Development

No branches or pull requests

5 participants