# WiFi problem on Mega + WiFi R3 ATmega2560 + ESP8266

I've got 2 "Mega + WiFi R3 ATmega2560 + ESP8266" (link) and both have same issue when trying to use the ESP chip.

Hope someone can point me toward something else to try in order to get them working properly.

Context

I'm able to flash the ESP chip using Arduino IDE or PlatformIO. Dip switch need to be : 5, 6 and 7 ON to flash, and only 5 and 6 to debug through serial.

I've tried using different boards (Generic ESP8266 module, Wemos D1 R2 & mini, Node MCU) as well as different flash mode (DIO, QIO), crystal frequency (26 Mhz, 40 Mhz), CPU frequency (80 Mhz, 160 Mhz)

They all flash correctly without any error and I can get my serial output.

It's written ESP8266EX on the ESP chip. And I've tried with or without an antenna plugged on the board.

Problem

The problem I got on both of them is huge instability when using wifi. I cannot connect to them when they are in AP mode, they drop immediately.. And I cannot connect to or see my own wifi network from the Mega's ESP.

The same script and flashing config used on other ESPs devices work as expected (see [output other ESP board] below). I've tried on WeMos and NodeMCU devices.

But with the mega+wifi, it only see between 0 and 2 access point that are at a greater distance and weaker signal than my own wifi ([output mega+wifi] below).

Question

I don't have any clue on what can cause such a different result on device from same family (ESP/espressif). As if there was some sort of setting that need to be changed on those ESPs.

Any help or insight would be truly appreciated.

[code]

#include "ESP8266WiFi.h"

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

// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

Serial.println("Setup done");
}

void loop() {
Serial.println("scan start");

// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
}
}
Serial.println("");

// Wait a bit before scanning again
delay(5000);
}


[output other ESP board]

scandone
scan done
8 networks found
1: 412 Precondition Failed (-67)*
2: VIDEOTRON1547 (-90)*
3: BELL275 (-94)*
4: BELL558 (-72)*
5: C-PC_Network (-88)*
6: BELL387 (-90)*
7: EBOX-4229 (-94)*
8: VIDEOTRON6825 (-80)*

scan start
scandone
scan done
11 networks found
1: 412 Precondition Failed (-63)*
2: VIDEOTRON1547 (-88)*
3: BELL681 (-90)*
4: BELL275 (-90)*
5: VIDEOTRON0442 (-90)*
6: BELL558 (-71)*
7: BELL602 (-90)*
8: IKA COIFFURE (-90)*
9: C-PC_Network (-87)*
10: EBOX-4229 (-87)*
11: BELL387 (-90)*

scan start
scandone
scan done
7 networks found
1: 412 Precondition Failed (-65)*
2: BELL681 (-88)*
3: VIDEOTRON1547 (-88)*
4: EBOX-4229 (-88)*
5: BELL387 (-87)*
6: BELL558 (-71)*


[output mega+wifi]

SDK:2.2.1(cfd48f3)/Core:2.4.1/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1)
bcn 0
del if1
usl
mode : sta(2c:3a:e8:26:36:13)
wifi evt: 8
Setup done
scan start
scandone
scan done
1 networks found
1: BELL558 (-69)*

scan start
scandone
scan done
1 networks found
1: BELL387 (-88)*

scan start
scandone
scan done
no networks found

scan start
scandone
scan done
1 networks found
1: BELL387 (-87)*


[erasing flash]

PS \tool-esptoolpy> python .\esptool.py -p COM10 erase_flash
esptool.py v2.3.1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 14.2s
Hard resetting via RTS pin...

• try to erase the flash of the esp8266 with esptool and then upload a sketch from IDE. choose Generic esp8266 as a board – Juraj Jun 13 '18 at 6:57
• I did it using python .\esptool.py -p COM10 erase_flash and that didn't changed anything. Output added to the question. – Remi Jun 13 '18 at 10:47

I had this problem. On Robotdyn D1 mini the esp8266 flash erase did help. On Robotdyn D1 R2 only the flashing of the AT firmware with Espressif Flash Download Tool restored the esp8266. After then the sketches from IDE had working WiFi.

There are some settings of the Espressif basic esp8266 libraries (SDK) saved on flash and there is some incompatibility between SDK versions. The Flash Download Tool creates right esp settings binary and flashes it to right address on flash.

• ESP8266_AT_Bin_V1.6.2 ? and then at or at_sdio ? and how do I know the right addresses to use? – Remi Jun 13 '18 at 11:55
• "at". addresses depend on the size of the flash and are listed in the readme file – Juraj Jun 13 '18 at 12:16
• Thanks. Just flashed it and even with direct AT command, on only sees very few wifi network AT+CWMODE? +CWMODE:2 OK AT+CWMODE=3 OK AT+CWMODE? +CWMODE:3 OK AT+CWLAP +CWLAP:(2,"CHANTAL-PC-Network",-77,"00:26:5a:d1:c9:96",11,162,0,5,3,7,1) – Remi Jun 13 '18 at 12:36
• AT+GMR AT version:1.6.2.0(Apr 13 2018 11:10:59) SDK version:2.2.1(6ab97e9) compile time:Jun 7 2018 19:34:26 Bin version(Wroom 02):1.6.2 – Remi Jun 13 '18 at 12:38
• and can you connect to your network (CWJAP) ? – Juraj Jun 13 '18 at 13:55

You state you "cannot connect to them when they are in AP mode" but I do not see AP configured in your code.

// ESP AP Server
// must be min 8 chars or will not work
const char *APName = "MYESP8266";
const char *APPass = "MYPASS123";
// start the access point server
WiFi.softAP(APName, APPass);
webServer.on("/", doRoot);
// start server
webServer.begin();

// In LOOP
// keep checking to see if someone connects to device
webServer.handleClient();


Regarding the mega-wifi-r3-atmega2560-esp8266 I am unsure how these work, is the code being flashed to the ESP chip or to the Arduino chip and ESP is in AT mode?

• For the AP mode, I tried with the example provided here : arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/… I simply cannot connect to the AP (when I'm able to see it) even if I'm only 1 foot away from the board. – Remi Jun 13 '18 at 11:38
• Do you get an error after typing in the password? – Brian Moreau Jun 13 '18 at 12:43
• Try making the password all caps – Brian Moreau Jun 13 '18 at 12:43
• No, from computer is says "can't connect to network" and from my phone the AP simply disappear. The same code work perfectly on other boards. Seems more like core firmware issue. – Remi Jun 13 '18 at 13:02
• If it goes off then most likely the code is crashing and ESP rebooting – Brian Moreau Jun 13 '18 at 13:25