I have an interesting failure mode with BMP280’s as well as QMC5883L’s - Occasionally I get serial comms failure, and I have to fully power-cycle the ESP32, to cycle power to the sensors - This comms failure tends to happen about once a week, and also occurs with most ESPHome firmware flashes as well. My stop-gap idea would be to add a mosfet to one of the I/O pins to allow the ESP to toggle power to the sensors and re-establish comms. Is it possible to trigger such an action automatically upon comms errors? Maybe with say… 3 retries within a minute before giving up? This would also allow for cycling power to the sensors upon ESP reboot, assuming the pin can default to off at low-level boot, then toggle on before the initial communication occurs. Any thoughts on this?
You should inspect your problem better to answer that. Does one sensor fail or the i2c bus freezes? What do you get on esphome logs? Do you get nan or frozen output?
You should first follow what @Karosm said and figure out your real problem.
However, you probably don’t need a mosfet for control. Each BMP/E 280 and QMC5883L draws less than 1mA, which is well within the capability of an output pin.
I get a comms failure and that repeats throughout the logs until full power cycle of the sensor; unsure if the software stack in ESPHome doesn’t attempt a reconnect/re-initialize or if the sensor gets into a hung state due to invalid data on the bus, but the error persists across reboots and I have to power-cycle the actual sensor(s) to get them to reconnect.
Unfortunately I don’t currently have a log example to give you the exact error, as the sensor appears to be functional for the moment. It’s been an on-and-off issue for well over a year and I’ve not had a lot of motivation to fully document it lately.
If I can just drive the sensors off an I/O pin, what YAML config would I need to have that pin be “off” during initial boot-up, and toggle on once booted, before the serial initialization and after-boot sensor initialization? Maybe with a software-toggleable switch option once booted?
Also the reason for a MOSFET is the ESP32 is 3.3V TTL, I’m powering sensors with 5V off the board’s USB input due to the ~10 foot (shielded in case that helped) CAT6 run I need to bring it to my gas meter. Figured voltage drop would be prohibitive otherwise.
Well, that likely explains why you are having issues. Both sensors use i2c for communication, which stands Inter-Integrated Circuit. That means the expectation is they are connected by PCB traces on the order of centimeters in length and not meters. That is not to say it can’t be done, but it will come with challenges.
The sensors draw very little current, so I doubt the cable resistance is much of an issue.
If you are using this with the magnetometer for measuring your gas meter, that typically uses a high data rate. You should use a conditioner or just put the esp32 outside next to the meter.
In addition to above, your I2C lines are pulled up to 5V by both modules and like you know Esp32 doesn’t appreciate that (3.3V TTL).
Fair enough; I’ll try switching to 3.3V and see if that helps; as far as i2c however - you can for sure run up to 100 feet if you use an active terminator. I’m running shielded CAT6 for the line, and 10 feet is fine for that. People using the same project are running up to 25 feet pretty reliably.
Here is a good discussion of the limits and the reason for them.
People often drive faster than the speed limit and never have a problem until the time it is a problem.
Maybe other people haven’t had an issue with longer lengths, but clearly your project isn’t running reliably. Just because it worked on someone else’s setup doesn’t mean it will work on yours when you are clearly operating in areas that are well outside of supported.
What speed are you running i2c at?
What error rate is acceptable to you?
It’s not clear to me if you use one?
Is your shield grounded? Are you taking advantage of multiple twisted pairs, data/gnd?
I’m not currently using an active terminator, and that’s honestly a great suggestion. I may end up re-wiring for one.
Shield is grounded on one end only, (ESP side, I believe it’s left floating on the sensor side) and I’m using colored wires with all white pairs of the twisted-pair bundle also grounded. All 4 white wires are bonded together at both ends and connected to ground for both the ESP as well as the sensor boards. I just realized, that means ground may have 4x the noise on it in having done so, but also much lower resistance for ground reference. Interesting. Honestly I think that’s what the project I’m replicating, advised. I’ll have to revisit. I do wonder if that helps or hurts in my case, but I did try to make efforts to reduce the problems I might have before getting here.
Sounds good.
Welp… my terminator boards showed up, so I’ll probably start with one of those; something changed recently and the sensors won’t come back at all after multiple power cycles; my best guess is the cold (It’s below freezing where I live for the first time this season) is doing something funky and changing the conditions of the wiring just enough to fail out consistently. I’ll update in a few days when I get around to modifying and trying that; has to be done pretty much in-situ outside, due to how I routed the cable through a tiny crack in the foundations to get to the meter. (I rent so all of my addons have to be non-destructive).
Bad soldering (cold joints) is often affected by temperature drop…
That’s a good point! I believe I did a good job, (used liquid flux and high quality solder with an accurate, good quality 90W soldering iron, but I’ll give you a mistake could have still been made) - Sometime maybe this week I’ll add the i2c terminator and see if that fixes my problem