[SOLVED] ESP32 WROOM 32U WiFi unstable

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

[SOLVED] ESP32 WROOM 32U WiFi unstable

Postby roleez » Fri May 24, 2024 8:55 pm

Hi everyone!

I've made a multi-channel temperature measuring device with an ESP32-WROOM-32E (4MB) microcontroller. The measurements work fine, but the connection to the WiFi AP is very unreliable. Sometimes it connects almost immediately after powering on, sometimes it takes several minutes, and sometimes it doesn't connect at all. I've tried everything and can't figure out the solution to this problem.

(I also received information that the C8-C9 capacitors should be placed as close to the MCU as possible. I did that, but it didn't change anything...)

Here's a very simple program in Platform.IO (Arduino framework) that I use to test the WiFi, and the described phenomenon occurs.
What I've observed is that if the device is plugged into the computer's USB port and hasn't connected to the AP, it connects when I open its serial port (e.g., Putty, RealTerm, ...).
Has anyone encountered something like this?

Code: Select all

#include <Arduino.h>
#include <WiFi.h>
#include <driver/adc_common.h>
const char *ssid = "xxx";
const char *password = "xxx";
uint32_t ind = 0;

void setup() {
   setCpuFrequencyMhz(240);
   adc_power_off();
   btStop();
   Serial.begin(115200);
   delay(3000);
   pinMode(LED_BUILTIN, OUTPUT);
   WiFi.mode(WIFI_STA);
   WiFi.setTxPower(WIFI_POWER_19_5dBm);
   WiFi.disconnect(true, true);
   delay(100);
   WiFi.begin(ssid, password);
   Serial.print("Connecting to WiFi ..");
   while (WiFi.status() != WL_CONNECTED) {
     Serial.println(ind);
     delay(1000);
     if (ind > 20) {
       WiFi.disconnect();
       digitalWrite(LED_BUILTIN, HIGH);
       delay(300);
       digitalWrite(LED_BUILTIN, LOW);
       ESP.restart();
       //WiFi.disconnect(true, true);
       //WiFi.begin(ssid, password);
       //ind = 0;
     }
     ind++;
   }
   Serial.println(WiFi.localIP());
   Serial.println("WiFi connected");
}
void loop() {
  if ( WiFi.isConnected() ) digitalWrite(LED_BUILTIN, HIGH);             
  delay(100);                    
  digitalWrite(LED_BUILTIN, LOW);
  delay(2000);                    
  Serial.println("LED");
}
Here's the schematic: https://drive.google.com/file/d/1BQ6gUQ ... SfbdxAHpRZ
And a detail of how the ESP32 is on the PCB: https://imgur.com/a/r0Vq9S1
I've already soldered a 33uF capacitor very close to pin 2, but C9 is still relatively far (40mm).

What am I missing? :roll:

Thank you! (My English is poor...)
Last edited by roleez on Tue Jun 04, 2024 9:00 am, edited 1 time in total.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby lbernstone » Sat May 25, 2024 4:39 am

Does it work reliably in a minimal sketch? You have a lot of power draw in there. Extra capacitors can keep the voltage from dipping, but if the current draw is more than the AM1117 can supply, then the WiFi cannot initialize.

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby roleez » Sat May 25, 2024 7:35 am

It works well and stably in a minimal sketch (e.g. LED flashing only).
Are you thinking that the 10 uF capacitors with the AMS1117 might be low?

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby roleez » Sat May 25, 2024 7:57 am

"The linked minimal example doesn't work completely. At startup, it displays: '[WiFi] WiFi Status: 0' (20x) and doesn't connect. Then I pressed the EN (RST) button, and after a few connection attempts, it connected to the WiFi."

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby roleez » Sat May 25, 2024 8:35 am

build_flags = -DCORE_DEBUG_LEVEL=5 (platformio.ini)

(20 times, after flashing):
...
[WiFi] WiFi is disconnected
[ 3284][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: gentoom, BSSID: 18:e8:29:fb:75:08, Reason: 15
[ 3285][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 3292][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
[ 3300][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi Reconnect Running
[ 3308][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
...
and after button pressing:
...
[WiFi] WiFi is disconnected
[WiFi] WiFi is disconnected
[WiFi] WiFi is disconnected
[ 1201][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: xxx, BSSID: 18:e8:29:fb:75:08, Reason: 4
[ 1202][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 1209][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 4 - ASSOC_EXPIRE
[ 1215][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi Reconnect Running
[ 1224][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[ 1300][V][WiFiGeneric.cpp:355] _arduino_event_cb(): STA Connected: SSID: gentoom, BSSID: 18:e8:29:fb:75:08, Channel: 1, Auth: WPA2_PSK
[ 1301][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[ 1327][V][WiFiGeneric.cpp:369] _arduino_event_cb(): STA Got New IP:192.168.3.135
[ 1328][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 1331][D][WiFiGeneric.cpp:996] _eventCallback(): STA IP: 192.168.3.135, MASK: 255.255.255.0, GW: 192.168.3.1
[WiFi] WiFi is connected!
[WiFi] IP address: 192.168.3.135
...

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby roleez » Sat May 25, 2024 11:20 am

What I noticed is that if no serial port program is connected (e.g., PuTTY, RealTerm, ...), then when I press the EN (RST) button, nothing happens. But as soon as there is a program open on the serial port, the EN button works. That is, it can be restarted.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 WROOM 32U WiFi unstable

Postby lbernstone » Sat May 25, 2024 9:32 pm

roleez wrote:
Sat May 25, 2024 7:35 am
It works well and stably in a minimal sketch (e.g. LED flashing only).
Are you thinking that the 10 uF capacitors with the AMS1117 might be low?
I am thinking that your board has a high power requirement. If all those I2C devices are active, along with the UART adapter, this may be more than your power supply can handle. Capacitors hold very small amounts of energy, and are intended to balance the voltage rather than compensate for a weak supply. An 1117 typically only provides 800mA. The ESP32 needs at least 400mA to initialize the WiFi. Lower quality (no-name) components will have lower performance. This is why I ask if a minimal sketch reliably works. Make sure to initialize your WiFi early in the process before the other devices power up. Do not turn off devices that are already off thinking that this will save you power. It takes time, and is more likely to activate them and leave them in standby rather than off.

roleez
Posts: 6
Joined: Fri May 24, 2024 8:31 pm

Re: [SOLVED] ESP32 WROOM 32U WiFi unstable

Postby roleez » Tue Jun 04, 2024 9:02 am

The solution ended up being:

* the 470R resistors in the EN and IO0 branches had to be removed and short-circuited
* The 100 nF capacitor in branch IO0 had to be removed. (this is important)

Who is online

Users browsing this forum: No registered users and 56 guests