Skip to content

02 Obstacle ESP32 electronics

KlausMu edited this page Mar 25, 2021 · 3 revisions

I realised a similar project with an Arduino Uno. With the Arduino there was no need to use addtional pullups or an RC circuit. It seems the ESP32 is much more sensitive and not as robust as an Arduino Uno.

Pullups for I2C

Without additional pullups I2C communication is not reliable and stable. See https://github.com/espressif/arduino-esp32/issues/741#issuecomment-570756878

The ESP32's pullups are very weak, 50k to 100k ohm. Unless you want to run the i2c interface at 10khz you will need lower value resistors as pullups. With a 3.3v bus( the operating voltage of the ESP32) you should use a 3.3k ohm, at 100khz and a 2.4k ohm at 400khz.

Measurement of fan tacho signal

Getting a valid and proper tacho signal was a pain. I tried several combinations of pullup resistors and RC circuits. The values I found worked with three different fans (standard CPU fan and Noctua fan). So maybe these values are fan independent. Interesting: with a 3.3 kΩ pullup it did not work at all, I had to use a 10 kΩ pullup. See https://esp32.com/viewtopic.php?f=19&t=13679&start=10#p54049

From what I can see, your issue may very well be that the ESP32 is triggering on noise induced by the regulation of the fan; adding a R in the line probably creates a RC-filter in combination with the implicit capacitance of your wiring and the ESP32 pin. Can you try removing the resistor and adding a capacitor of, say, 1nF from the tacho output to ground? In combination with the pullup, this sort-of makes the RC network more explicit and should filter out the spikes in a more deterministic way.

With an oscilloscope you can see the difference between using an RC circuit and not.

Tacho signal without RC circuit, only pullup


Even the oscilloscope hardly cannot correctly determine the frequency of the signal. Correct value (with RC circuit) would be something like 38.5 Hz.

Tacho signal with RC circuit


Much cleaner signal, stable at least for the oscilloscope. Oscilloscope measured 38.5 Hz (*60/2=1155 rpm), whereas ESP32 measured 1260 rpm at the same time. This 10% difference is probably because of the still not very clean signal.

5V for fan pwm and tacho vs. 3.3V for ESP32

The ESP32 is powered with 3.3V and the I/O pins are not 5V-tolerant.

Normally a 4-wire fan would expect a 5V pwm signal, but in my tests the 3.3V from the ESP32 were always enough. If it is not enough for your fan, you could use a level shifter, please see here.

Something similiar seems to hold for the tacho signal of 5V, which never caused any problem to the 3.3V input of the ESP32. In the picture from the oscilloscope above (yellow signal) you can see that signal voltage never goes above 3.3V.

PWM signal provided by ESP32


25 kHz pwm signal frequency, duty 95/255 = 37.2%