In order to make a device that consumes the minimum power, I needed to power the sensors by enabling a pin from the ESP32, so when I enter in deep sleep mode, the sensors stop being powered and I save a critical amount of energy. Among the different sensors, I have an I2C device, that works perfectly the first time after a reset (when I guess the instruction of setting up the I2C bus according to the pinout definition takes place).
However, after any of the recoveries of a deep sleep, the I2C device is no longer there to be read (despite the power on the sensor feeding line having been recovered). Here is my code
I’ve had similar issues and they’ve often related to connections and/or power supply. And maybe power demand spikes on boot from sleep.
As first steps (if you haven’t already), I would:
Test with your best quality power supply and cables
Triple check all of your connections and consider soldering them if they aren’t already.
How long are your cables/wires to sensors? Test with short ones.
After some of those checks there are a few tricks I’ve seen people try like tinkering with delays, wire.begins and sensor setup priorities on boot. With what seems to be varying success.
My understanding is that a wake from deep sleep should be the same as a restart of the esp. However I agree with @Mahko_Mahko that there may be some timing it power issues.
Thanks for the tips @Mahko_Mahko, the circuit is all on a single PCB with good connections and short traces between uC and sensors. So I am 99.9% confident it is not a hardware issue: I monitored the boot peak in both scenarios (on a cold start and after returning from a deep sleep) and show almost the same value.
I am quite interested in your mention of a wire.begins instruction that could be set on boot, but I don’t see any ‘action’ like that to be set. Maybe with a lambda function?
esphome:
name: device
on_boot:
priority: 1000
then:
??? instruction for initializing the I2C bus ???
Thanks for the link, seems to be something quite similar to what I intend. I tried to update mine in remote, but I guess the battery just run out. Will try later on and keep you posted.
I’ve noticed that in this old thread, and I’d like to provide an explanation and an example to help those who may be experiencing the same issue.
The function Wire.begin() is used to initialize I2C communication in ESP8266 or ESP32-based devices, like the ones we use with ESPHome. In the context of the on_boot block, it’s used to ensure that I2C communication is operational from the device’s boot, allowing its later use.
For Wire.begin() to work correctly, it’s necessary to load the corresponding component to handle I2C communication in ESPHome. This is achieved by configuring the I2C component in our YAML configuration file.
Here’s an example of how to configure the I2C component for an ESP32-S2 board in ESPHome:
yaml
# Example configuration for ESP32-S2
i2c:
sda: 8
scl: 9
scan: true
id: bus_a
With this configuration, the I2C component will initialize I2C communication on pins 8 and 9 (SDA and SCL respectively) when the device boots up.
I hope this explanation and example are helpful for those experiencing issues with Wire.begin() and I2C communication in ESPHome. If you have any additional questions, feel free to ask!