Setting up ESP32 S3 N16R8 struggles connecting to wifi

I’m still fairly new to esp but I’ve read through every relevant source on the subject and can’t get it work, I’ve tried 3 of my boards and some seem to work better than others but still not really. I don’t get any errors and my serial monitor and RGB works as a wifi status indicator, but it rarely connects, I just get WL_Disconnected (6).

My ini :

[env:esp32]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
lib_deps = adafruit/Adafruit NeoPixel@^1.15.1
board_build.arduino.memory_type = qio_opi
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 16MB
board_upload.max_size = 16777216
board_build.extra_flags =
  -DBOARD_HAS_PSRAM

My Code:

#include <Arduino.h>
#include <WiFi.h>
#include <Adafruit_NeoPixel.h>
#define LED_PIN    48
#define NUM_LEDS   1

Adafruit_NeoPixel rgbLED(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
uint16_t hue = 0;


const char* WIFI_SSID = "LavaLiteGuest";
const char* WIFI_PASSWORD = "pass";
#define WIFI_TIMEOUT_SMS 60000 // Timeout for WiFi connection in milliseconds
//a0:85:e3:e6:8d:74
void connectToWifi(void * parameters) {
    WiFi.disconnect(); // Ensure we start with a clean state
    Serial.println("Connecting to WiFi...");
    WiFi.mode(WIFI_STA);
    delay(1000); // Allow time for Serial to initialize
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

    unsigned long startAttemptTime = millis();

    while(WiFi.status() != WL_CONNECTED ) {//&& millis() - startAttemptTime < WIFI_TIMEOUT_SMS
        Serial.println(WiFi.status());
        Serial.print(".");
        if(WiFi.status() == WL_CONNECT_FAILED){
            rgbLED.setPixelColor(0, rgbLED.Color(0, 0, 255)); // Blue
        }
        else if(WiFi.status() == WL_NO_SSID_AVAIL){
            rgbLED.setPixelColor(0, rgbLED.Color(255,255, 0)); // Yellow
        }
        else {
            rgbLED.setPixelColor(0, rgbLED.Color(255, 0, 0)); // Red
        }
       
        rgbLED.show();
        delay(100);
        rgbLED.setPixelColor(0, rgbLED.Color(0, 0, 0)); // Off
        rgbLED.show();
        delay(100);
        
    }
    if(WiFi.status() != WL_CONNECTED) {
        Serial.println("Failed to connect to WiFi within timeout.");
    } else {
        Serial.println("Connected to WiFi!");
        Serial.print("IP Address: ");
        Serial.println(WiFi.localIP());
        rgbLED.setPixelColor(0, rgbLED.Color(0, 255, 0)); // Green
        rgbLED.show();
        Serial.println(millis());
    }
}



void setup(){
    Serial.begin(115200);
    
    rgbLED.begin();
    rgbLED.show(); // Initialize all pixels to 'off'

    xTaskCreatePinnedToCore(
        connectToWifi, // Function to be called
        "ConnectToWifi", // Name of the task
        10000, // Stack size in bytes
        NULL, // Parameter passed to the task
        1, // Task priority
        NULL, // Task handle
        1 // Core ID
    );
    

}

void loop() {
  // Your main code here
  Serial.println(WiFi.status());
  delay(1000); // Delay for demonstration purposes
}

I know its not a typo on the wifi creds since it has connected to my hotspot and router, I’m at a loss.

The xtask was a last ditch effort from chat GPT but i have tried it without that

Your code crashes right at the end of the connectToWifi() funciton as a task must not return!

Your code is way too complex if you’re new to this!

Don’t let A.I. generate code for you. A good starting point to learn about the ESP32 is Getting Started with the ESP32 Development Board | Random Nerd Tutorials

Try a simpler code like this:

#include <Arduino.h>
#include <WiFi.h>

const char* WIFI_SSID     = "LavaLiteGuest";
const char* WIFI_PASSWORD = "pass";

void setupWiFi() {
    Serial.print("Connecting Wifi");
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(100);
    }
    Serial.println("connected");
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
}

void setup() {
    Serial.begin(115200);
    setupWiFi();
}

void loop() {
}

To drive the on board rgb led, no external library is needed!
Remove that library and use the builtin function neopixelWrite() (Arduino 2.x) or rgbLedWrite() (Arduino 3.x)

I’ll give that a try this evening, I have tried that simple code though, I just built upon it for troubleshooting, thanks.


Unfortunately, still the same result on 2 of my boards after 10 minutes, no connection on either my home router or hotspot on 2.4 GHZ.

Did you try a wifi scan sketch?

Yep, and interestingly they are there at the top

Double check the password. Make sure it is at least 8 characters long. (That might be the reason)

Can confirm, my phone has an 8 char minimum, i also removed any special characters and numbers to make it simple

And checked for extra spaces haha, my router also has a MAC addr block list but its not on there but wanted to use my phone to to be sure.

How many ESPs do you have, and do they all have this problem?
I don’t think the problem is with the ESPs…

I have 3, when first testing the 2 that I didn’t solder the rgb seemed to have more success so I thought it might be a power draw issue as mentioned other forums where they are powering servos but you’re right, it doesn’t seem to be that.

You could turn things around and operate the ESP as an access point. You can then use your smartphone to display the RSSI strength of the access point and try to connect to the ESP…

#include <Arduino.h>
#include <WiFi.h>

const char* WIFI_SSID     = "MYESP32AP";
const char* WIFI_PASSWORD = "MYESP32AP";

void setupWiFi() {
    Serial.print("Connecting Wifi");
    WiFi.softAP(WIFI_SSID, WIFI_PASSWORD);
}

void setup() {
    Serial.begin(115200);
    setupWiFi();
}

void loop() {
}

I don’t see the MYESP32AP as an option on my phone but i also tried and it also wouldnt manually connect

I dont have much undertanding of the .ini is there something in there that could be an issue or maybe the board selected? Im still using the same one as mentioned above

No, the content of the platformio.ini is fine and matches the board.

Unfortunately I have no clue what’s going on.
I am wondering why the ESP’s access point doesn’t show up on your smartphone.

Oh man, well I appreciate the help, Ill followup if i ever find a solution.

1 Like

I GOT IT, thanks to an amazon customer review that suggested (though counterintuitive) reducing the wifi transmission power. That was all that was needed; now it connects instantly. Code below:

ini:
[env:esp32]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
lib_deps = adafruit/Adafruit NeoPixel@^1.15.1

cpp:
#include <Arduino.h>
#include <esp_wifi.h>
#include <WiFi.h>

const char* WIFI_SSID = “SSID”;
const char* WIFI_PASSWORD = “Pass”;

void setupWiFi() {
Serial.print(“Connecting Wifi”);
WiFi.mode(WIFI_STA);

// Set max TX power to 40 (~20 dBm)
esp_wifi_set_max_tx_power(40);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    neopixelWrite(RGB_BUILTIN, 0, 0, 255);  // Blue blink to show connecting
    delay(100);
    neopixelWrite(RGB_BUILTIN, 0, 0, 0);    // Off
    delay(100);
}

Serial.println("\nConnected!");
neopixelWrite(RGB_BUILTIN, 0, 255, 0);
Serial.print("IP: ");
Serial.println(WiFi.localIP());

}

void setup() {
Serial.begin(115200);
setupWiFi();
}

void loop() {
// You can add code here to do something after connecting
}

Also for future readers, one customer comment said to “never use the usbc marked COM” and to use the usb for RTOS maked usb, I don’t know how to make that one work wit the serial monitor, I used the COM one just fine.

I am glad you found the solution. Just wondering whats going on.Looks like your boards are of poor quality. I had similar issues with a ESP32-S3 fake module where the PCB antenna was of poor quality.
I remember there is a way to fix the antenna by soldering a short piece of wire to a specific point.

If you want to use the Serial object on the builtin USB use the build flag 'ARDUINO_USB_CDC_ON_BOOT=1`.
Search this forum, there are a lot of posts about this topic! ESP32-S3 native USB interface and Serial Monitor missing first messages - #10 by sivar2311