ESP32 I2C power/distance problem?

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

ESP32 I2C power/distance problem?

Postby antonyc » Wed Mar 21, 2018 9:25 am

Hi everyone,

I've got 2 I2C devices, an ADS1115 ADC and BH1750 Light sensor.

I did a test circuit using a breadboard (whtout pullups) and it all worked as expected. However, now I put the circuit in place, the Light Sensor doesn't work. I've taken away the ADS1115, and the BH1750 still doesn't work. The only difference which I can from my breadboard circuit and this one is that the light sensor in situ is 3m away from the ESP32.

I've added in 3.9k pullups and it's still the same.

Has anyone got any ideas?

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 I2C power/distance problem?

Postby antonyc » Wed Mar 21, 2018 9:55 am

I've just done some more tests and I can confirm that the BH1750 is working, and that it works when the wires are short.

Why would it work for a Nano but not for the ESP32??!?

Hexman64
Posts: 16
Joined: Wed Mar 14, 2018 3:03 pm

Re: ESP32 I2C power/distance problem?

Postby Hexman64 » Wed Mar 21, 2018 1:43 pm

I was told that 3.3V systems should use 2.2k pullups on the I2C bus, means 2k2 from SCL to 3.3V and another 2k2 from SDA to 3.3V. (4.7k for 5V systems like the Nano).
I added 2k2 on my esp32, which somehow made the I2C bus work, more or less.

Another thing is that my bus stops working randomly, especially when WiFi is running (or maybe when time intensive operations take place), but in my case I can find out when that happened and Wire.reset() the I2C bus.
See the last section of: https://esp32.com/viewtopic.php?f=2&t=3390

My last info is that I'm not alone having esp32 I2C problems, see:
https://github.com/espressif/arduino-esp32/issues/659
https://github.com/espressif/arduino-esp32/issues/839

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 I2C power/distance problem?

Postby antonyc » Wed Mar 21, 2018 5:02 pm

Hi Hexman,

Thanks for your reply...

I read that 4.7k is best for 5v, and from that I just guessed that 3.3v would need a little lower, hence my 3.9k resistor guess, but now you mention it, I'll use 2.2k. I have two of them taped to the project, ready to put in after my tests.

Anyway, I've since got this thing working, but without understanding. Since I posted this thread, I've since tested the module close again, and it worked... So then I decided to wire it up to the long wire again, and that now works! The sensor is still on the same 3m wire, but physically closer to the ESP32. It hasn't been routed through the wall this time. So now I'm thinking that the distance isn't the problem - it's noise?

In my case, the wire goes up the wall, then along it, it goes behind an electrical panel and through a hole, to it's case which is outside.

I'm going to try shielding it with aluminium foil.

chegewara
Posts: 2174
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32 I2C power/distance problem?

Postby chegewara » Wed Mar 21, 2018 5:33 pm

Or you can try to connect logic analyzer close to the sensors and see if signal can be read and decoded with it.

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 I2C power/distance problem?

Postby antonyc » Wed Mar 21, 2018 7:38 pm

Ok, an update...

I don't know what is going on here, but that particular sensor cannot work with ESP32 over 3m, it only works with Arduino that way.

I've used another sensor of the same model, and the new sensor does work with ESP32 over the 3m...

What the hell?!?!

Hexman64
Posts: 16
Joined: Wed Mar 14, 2018 3:03 pm

Re: ESP32 I2C power/distance problem?

Postby Hexman64 » Wed Mar 21, 2018 9:06 pm

Strange. Component tolerances? That would mean your working sensor is very close to non-working.

I had a similar situation on the SPI bus. Two devices worked on the breadboard, then on a 3m cable the closer one did not. I'd say that the sum of all cables on the bus influences the whole communication.
Maybe a shielded ethernet cable works. Drilled (wound? What's the word...), shielded, laughing at I2C speed.

Observe the data you get from I2C devices. I can nearly reproduce an I2C bus error by accessing the Wifi webserver on that ESP32. Do you get strange values - how is it after a Wire.reset() ?

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: ESP32 I2C power/distance problem?

Postby tele_player » Thu Mar 22, 2018 12:36 am

The word you are looking for is ‘twisted’.

Modern Ethernet cables use twisted pairs, with differential signaling, to achieve high rates.

Ordinary I2C doesn’t use differential signaling. For long runs, differential transceivers are available for I2C.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: ESP32 I2C power/distance problem?

Postby Archibald » Thu Mar 22, 2018 12:58 am

It looks like you can slow down the I²C using Wire.setClock(clockFrequency). The clock frequency is in Hz. I think that may solve the problem.

antonyc
Posts: 20
Joined: Thu Dec 07, 2017 12:24 pm

Re: ESP32 I2C power/distance problem?

Postby antonyc » Thu Mar 22, 2018 9:30 am

Hexman64 wrote:Strange. Component tolerances? That would mean your working sensor is very close to non-working.

I had a similar situation on the SPI bus. Two devices worked on the breadboard, then on a 3m cable the closer one did not. I'd say that the sum of all cables on the bus influences the whole communication.
Maybe a shielded ethernet cable works. Drilled (wound? What's the word...), shielded, laughing at I2C speed.

Observe the data you get from I2C devices. I can nearly reproduce an I2C bus error by accessing the Wifi webserver on that ESP32. Do you get strange values - how is it after a Wire.reset() ?
Ok, yes, my problem is the same. I woke up this morning, and the whole bus is broken. I haven't used the logic analyser on it yet.

I'm already using twisted pair. I'm thinking of wrapping the ethernet cable in aluminium foil and grounding it, to see if that helps.

Antony...

Who is online

Users browsing this forum: No registered users and 59 guests