I'm running a program (with Arduino framework) on ESP8266, which polls data over WiFi once an hour. The polled data is displayed on 2x OLED displays (via I2C), and then the (software) PWM is adjusted to drive RGB Leds on a matching color. In between the data polls, the ESP8266 sits executing a delay(1h).
Problem:
After executing from hours to days, at a random point in time, my prototype freezes. The displays are not updated, and the PWM (RGB color) remains unchanged. I have 6 prototypes in my house, so it's easy to see when one has stopped updating.
Remarks:
a) The circuit doesn't heat up, or otherwise signal any clear issue.
b) The RGB color remains still, which means the PWM remains in execution.
c) The other prototypes run ok, with the same program, which should eliminate possibility for faulty code. I've also diagnosed there are no memory leaks.
d) Once frozen, and I quickly power off and on the ESP8266, the OLED displays don't come back to life. I need to wait for some time, which I assume indicates there's current somewhere which needed to discharge first.
e) Upon first boot, I collect and store the WiFi credentials to EEPROM. It's more an exception, but twice I've had those wiped out upon a reboot after a freeze.
I've also probed the circuit with my oscilloscope and couldn't see spikes or other fluctuation in the voltage levels. But as this goes outside my expertise, I wouldn't exclude the possibility.
Circuit:
AMS1117 converting 5V to 3.3V for the ESP8266. Before V(in) I've tried 10uF to 20uF tantalum caps. After V(out) I've tried 100uF (up to 1000uF) electrolytic caps. (Should probably try 1uF ceramic in parallel with the electrolytic?) Then, I've tested with a few different 5V supplies to ensure the issue wasn't on that end.
3x 2N7000 MOSFETs to drive 4x RGB Leds with the PWM. I started off without gate resistors, adding first 10ohm, and gradually up to 300ohm. I believe they slightly improved the stability, but this might be just a placebo.
Because my 2x OLED Displays share the same I2C address, I have 2x 2N7000 MOSFETs to control which one receives the I2C SCK signal. Similar to above, I started off without gate resistors gradually adding it up to 300ohm. (What I forgot to draw in the schematic is 10k pull-ups on both the OLEDs' SCK lines.)
Then, 10k pull-ups for RST, EN, and Gpio0, and 10k pull-down for Gpio15.
Remarks:
a) The MOSFETs add some capacitance on the I2C SCK line, but it should be on the safe side. While the SDA line doesn't have that capacitance, I guess it may add some offset.
b) My program is running in "debug" mode, writing out on the Serial RX/TX which are floating on my prototypes. Not sure if that may add some issues.
Other:
My first prototypes were without gate resistors on the MOSFETs. Interestingly, the one ESP8266 that has been executing flawlessly now for almost 2 months is from this batch.
I noticed Gpio0 can't produce 0V Low, but gives about 1.7V. Later, I connected the MOSFET gate to Gpio13 instead. With my first prototypes, a 10k pull-up on Gpio2 also seemed to destabilize the prototype (although, I'm not sure it was only that).
IMPORTANT:
The setup runs flawlessly from a development board to breadboard with jumper cables. The problems are only when I move to a protoboard with soldered and shorter (in length) connections. (The development board has also a slightly different set of components.)
Overall, more than fixing the problem, I'm interested in understanding it - as I'm doing this to learn electronics. But after banging my head to ChatGPT, books, and all other material for a month, I've come to conclude I needed someone to help me out.
I believe the answers lie in somewhere around these two observations:
- With a quick reboot, the OLED displays don't come to life.
- On a breadboard the setup runs smooth (and allows for that quick reboot).
