Hi. I am building currently a weather station based on few sensors and ESPHome. I use BME680 as temperature, humidity and pressure sensor (and many others, as it deliveres) and AS5600 magnetometer as sensor for wind direction. Both are connected by I2C.
Lately I managed to solder everything together and put it on the pole in the garden. The BME started with no problems. The AS5600 gets discovered in logs with address 0x36, but later sends no data, and there is no communication with sensor. Logs say:
[10:00:40.854][D][esp-idf:000]: E (2693632) i2c.master: I2C hardware NACK detected
[10:00:40.863][D][esp-idf:000]: E (2693635) i2c.master: I2C transaction unexpected nack detected
[10:00:40.866][D][esp-idf:000]: E (2693643) i2c.master: s_i2c_synchronous_transaction(945): I2C transaction failed
[10:00:40.883][D][esp-idf:000]: E (2693648) i2c.master: i2c_master_execute_defined_operations(1366): I2C transaction failed
I really have no idea what is going on. If there was any problem with cables it would not be discovered, am I right?
I2C is not designed for 3m wiring.
Best option would be to locate esp next to sensors, ~20cm .
If not possible, consider active terminator like LTC4311.
If you want to play with your actual setup, add 3k3 external pullups, use twisted pair cable, both data lines paired with GND.
Try lower i2c frequency and higher timeout.
Allright then, I will think about the active terminator and adding pullups, if that won’t work, I will have to hang the box higher (although I don’t like this idea, as I planned to have it down the pole just to have an opportunity to do some fixes or change the batteries if need be).
Thanks for your advices.
Also make sure you use the latest esphome version. There have been some fixes to i2c lately.
Knowing the risks I did have success with 2.5m twisted pair wiring on an optical rain sensor, so I hope that will do the trick for you too. I made no extra precautions, but I have no idea what the internals of my rain sensor did to improve my success rate. It is a well designed industrial piece.
They will, but tend to keep wet longer. Also they degrade over time. My piece of kit is rather expensive, but very fast responding and has a level 0-7. The one I have does not have mm’s (I have a tipping bucket too) but that isn’t fast enough to save my awning from getting wet. I own the RG-9:
Well, gentlemen. I have to congratulate you for the diagnosis. I put 4,7kohm pullups and now I have data. Thank you.
It turned out one pullup on the data line is enough.
Nice you got it working!
But remember it’s very fragile. Fine for wind sensor, but don’t do wiring like that if reliability is absolutely needed.
I2C was designed for device to device communication on same PCB or few cm wired connections.