Replies: 6 comments 10 replies
-
Please enclose code into lines with three backticks |
Beta Was this translation helpful? Give feedback.
-
ok, I added that and now it does a machine.reset() twice but still it is not able to access the i2c slave again after that. MPY: soft reboot Going to sleep... rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) i2c must be somehow messed up after deep sleep... How can I rectify the mess if even a hardware reset will not do it? |
Beta Was this translation helpful? Give feedback.
-
Ok, I tested a little more and it does not seem to be a problem of deep sleep. Even when I just press the reset button on the ESP32 board, reading the HTU21 fails, only when I start the program from Thonny by clicking the play button (run the current script) the program reads the HTU21, very strange. |
Beta Was this translation helpful? Give feedback.
-
Ok, I found this https://forum.micropython.org/viewtopic.php?t=12508 i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=100000) # Correct I2C pins for ESP32-WROOM
i2c.scan()
htu = htu21df.HTU21DF(i2c) and now it works after a hard reset and a deep sleep reset... I'll try the tip with the i2c clear robert-hh suggested tomorrow, that would be more efficient if it works, because scanning the whole i2c bus consumes certainly more time (energy) than >=9 clock cycles and a SDA high in a deep sleep scenario. |
Beta Was this translation helpful? Give feedback.
-
Ok, I added the i2c_clear function and this seems to do the trick as well: import network
import espnow
import time
import machine
import wifi
from machine import Pin, I2C
from micropython_htu21df import htu21df
def i2c_clear():
SCL = Pin(22, Pin.OUT)
SDA = Pin(21, Pin.OUT)
SDA.value(0)
time.sleep_us(2)
SDA.value(1)
for n in range(10):
SCL.value(0)
time.sleep_us(2)
SCL.value(1)
time.sleep_us(2)
SCL.value(0)
SDA.value(0)
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=400000) # Correct I2C pins for ESP32-WROOM
# i2c.scan() # this is needed to fix error message after hardware reset...
i2c_clear()
htu = htu21df.HTU21DF(i2c)
sta, ap = wifi.reset() # DeepSleep: Reset wifi to AP off, STA on and disconnected
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF) # Or network.AP_IF
sta.config(channel=1) # Wifi loses config after lightsleep()
sta.active(True)
sta.disconnect() # For ESP8266
e = espnow.ESPNow()
e.active(True)
peer = b'\x0c\xb8\x15\xd6\x2d\x10' # MAC address of peer's wifi interface
e.add_peer(peer) # Must add_peer() before send()
e.send(peer, "Starting...test")
# print(f"Temperature: {htu.temperature:.2f}°C")
print(f"Humidity: {htu.humidity:.2f}%")
print("")
# e.send(peer, f"HTU21d Temp: {htu.temperature:.2f}")
e.send(peer, f"HTU21d Hum: {htu.humidity:.2f}")
# e.send(peer, "testmessage")
e.active(False)
sta.active(False) # Disable the wifi before sleep
print('Going to sleep...')
machine.deepsleep(10000) # Sleep for 10 seconds then reboot This still is very odd, running just the HTU21 with i2c and deep sleep works without the clear, but if I include espnow it needs the clear function to work... Thanks Uli |
Beta Was this translation helpful? Give feedback.
-
toggeling SDA to 0 seems to be necessary, for me only this works: def i2c_clear():
SCL = Pin(22, Pin.OPEN_DRAIN, value=1)
SDA = Pin(21, Pin.OPEN_DRAIN, value=1)
SDA(0)
time.sleep_us(2)
SCL(1)
for n in range(10):
SCL(0)
time.sleep_us(2)
SCL(1)
time.sleep_us(2) Uli |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
first post here and a beginner at micropython...
I'm trying to use espnow to send HTU21 sensor data (ESP32-WROOM-Dev board) to a peer (also a ESP32-WROOM-Dev board) and at startup the HTU21 data arrives as expected on the peer side. But after going to deep sleep and coming back the i2c communication seems to have trouble to talk with the HTU21 sensor, the espnow communication works after the deepsleep (I can see a text message arriving at the peer), but not the i2c value:
HTU21 Sensor side:
MPY: soft reboot
Temperature: 22.63°C
Going to sleep...
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_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:2
load:0x3fff0030,len:4728
load:0x40078000,len:14888
load:0x40080400,len:3368
entry 0x400805cc
Traceback (most recent call last):
File "main.py", line 27, in
File "/lib/micropython_htu21df/htu21df.py", line 78, in temperature
OSError: [Errno 19] ENODEV
MicroPython v1.22.0 on 2023-12-27; Generic ESP32 module with ESP32
Type "help()" for more information.
Peer:
MPY: soft reboot
b'\x0c\xb8\x15\xc3\x88\x08' b'Starting...'
b'\x0c\xb8\x15\xc3\x88\x08' b'HTU21d Temp: 22.63'
b'\x0c\xb8\x15\xc3\x88\x08' b'Starting...'
Receiver side code:
Sensor-Code:
On both ESP32-WROOM boards is software version ESP32_GENERIC-20231227-v1.22.0.bin installed.
Any help would be appreciated
Uli
Beta Was this translation helpful? Give feedback.
All reactions