Yet another AT Commands question - with a twist

The Hardware
Arduino UNO board
ESP8266 -01

The Question
From watching this video....

I learned that anytime you upload a new sketch to the ESP8266, you effectively overwrite the OEM firmware (or programming, whatever) that allows you to issue AT commands.

So if that's true....ALL my ESP8266-01 boards will no longer respond to AT commands. (And that actually appears to be the case. I just wasn't sure why until now.) Apparently, to get the OEM firmware AT commands back I would have to reflash the firmware that came with the ESP8266-01 boards.

What doesn't make sense is that I seem to recall a number of "projects" and "tutorials" that go about issuing AT commands AFTER uploading a sketch pertaining to the tutorial?

That said, Arduino has programming that allows you to execute those same commands using the Arduino Lauguage.

If that's so....where can one find all those AT replacement commands in one neat package?

If all of the above is mistaken, please tell me.

Thanks

Yes, loading Arduino sketches wipes the AT firmware. You can reflash it, but in my view it is more cost effective to just buy another ESP-01 if that is what you need. You have to find the correct firmware for the variant that you are flashing - it's a pain and you have to dig through piles of docs to be able to choose the right files and burn them to the right memory areas of the ESP.

I played with esp-01 a year ago and now the future is this board. "Wemos D1 mini". or the upgraded version of esp8266 devices "esp32".

I strongly recommend wemos d1 mini because you won't have to go through re-flashing and making a circuit just to upload code.Not to mention you only have one pin to use on the esp-01.

The official Espressif AT firmware is here:

You will find the compiled files at bin/at subfolder. I don't know if the source code is buried in that repo somewhere or if it's not open source.

It was a pain to figure out how to flash the ESP8266 with the AT firmware the first time because the manufacturer's documentation doesn't provide a clear set of steps and all the 3rd party tutorials I found were garbage but once you get it working once it's easy after that. I've documented the process here on the forum before:
https://forum.arduino.cc/index.php?topic=466167.msg3208886#msg3208886
that's specific to the ESP8266 shield but I provided an explanation of how you could adapt it to work for any ESP8266 here:
https://forum.arduino.cc/index.php?topic=466167.msg3208887#msg3208887

It would be cool if there was an AT firmware sketch that you could upload using the Arduino IDE.

nathan_ramanathan:
I strongly recommend wemos d1 mini because you won't have to go through re-flashing and making a circuit just to upload code.

I also like the WeMos D1 Mini but quamikazee would be in the exact same situation if they were using one. The primary benefit would be that the WeMos D1 Mini has the USB-serial circuitry on board instead of having to connect an external adapter but obviously quamikazee has already gotten that working. The downside to the CH340 being on board is it will increase the power consumption of the board over the ESP-01. There are actually two different variants of the ESP-01, the 0.5 MB and the 1 MB. The 0.5 MB doesn't have enough flash to contain the latest full OTA firmware updating AT firmware so the 1 MB version is definitely superior.

nathan_ramanathan:
you only have one pin to use on the esp-01.

If you're using the Espressif AT firmware you can't do anything with the pins anyway so it doesn't matter.

Here's an Arduino project over at Instructables.com
Oddly, it clearly directs you to upload a sketch and THEN......use the AT command ?
Throughout the uploaded sketch, it depends on AT commands send automatically.
If the sketch overwrites the ability for the ESP8266 to respond to AT commands, how can this ever work?

Is it that this sketch only uploads to the Arduino and NOT into the ESP8266?

How can this be?

Here's the sketch.....

#include <DHT.h>
#include <DHT_U.h>
#include <stdlib.h>

#define SSID "YourSSID"//your network name
#define PASS "YourPassword"//your network password
#define NIP "184.106.153.149" // thingspeak.com
#define DHTPIN 7 // what pin the DHT sensor is connected to
#define DHTTYPE DHT11 // Change to DHT22 if that's what you have
#define Baud_Rate 115200 //Another common value is 9600
#define GREEN_LED 3 //optional LED's for debugging
#define RED_LED 4 //optional LED's for debugging
#define DELAY_TIME 60000 //time in ms between posting data to ThingSpeak

//Can use a post also
String GET = "GET /update?key=1234567&field1=";
String FIELD2 = "&field2=";

//if you want to add more fields this is how
//String FIELD3 = "&field3=";

bool updated;

DHT dht(DHTPIN, DHTTYPE);

//this runs once
void setup()
{
Serial.begin(Baud_Rate);
Serial.println("AT");

delay(10000);

if(Serial.find("OK")){
//connect to your wifi netowork
bool connected = connectWiFi();
if(!connected){
//failure, need to check your values and try again
Error();
}
}else{
Error();
}

//initalize DHT sensor
dht.begin();
}

//this runs over and over
void loop(){
float h = dht.readHumidity();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(f)) {
LightRed();
return;
}

//update ThingSpeak channel with new values
updated = updateTemp(String(f), String(h));

//if update succeeded light up green LED, else light up red LED
if(updated){
LightGreen();
}else{
LightRed();
}

//wait for delay time before attempting to post again
delay(DELAY_TIME);
}

bool updateTemp(String tenmpF, String humid){
//initialize your AT command string
String cmd = "AT+CIPSTART="TCP","";

//add IP address and port
cmd += NIP;
cmd += "",80";

//connect
Serial.println(cmd);
delay(2000);
if(Serial.find("Error")){
return false;
}

//build GET command, ThingSpeak takes Post or Get commands for updates, I use a Get
cmd = GET;
cmd += tenmpF;
cmd += FIELD2;
cmd += humid;

//continue to add data here if you have more fields such as a light sensor
//cmd += FIELD3;
//cmd += <field 3 value>

cmd += "\r\n";

//Use AT commands to send data
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">")){
//send through command to update values
Serial.print(cmd);
}else{
Serial.println("AT+CIPCLOSE");
}

if(Serial.find("OK")){
//success! Your most recent values should be online.
return true;
}else{
return false;
}
}

boolean connectWiFi(){
//set ESP8266 mode with AT commands
Serial.println("AT+CWMODE=1");
delay(2000);

//build connection command
String cmd="AT+CWJAP="";
cmd+=SSID;
cmd+="","";
cmd+=PASS;
cmd+=""";

//connect to WiFi network and wait 5 seconds
Serial.println(cmd);
delay(5000);

//if connected return true, else false
if(Serial.find("OK")){
return true;
}else{
return false;
}
}

void LightGreen(){
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
}

void LightRed(){
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
}

//if an error has occurred alternate green and red leds
void Error(){
while(true){
LightRed();
delay(2000);
LightGreen();
delay(2000);
}
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

That sketch is uploaded to the Arduino UNO, which is controlling an ESP8266 module that's running the AT firmware. You're not uploading the sketch to the ESP8266.

Serial.println("AT+CWMODE=1");
delay(2000);

Yeah, this is an example of typical lame ESP AT code. It blocks the processor for significant lengths of time, instead of using non-blocking serial communications and reading responses from the ESP. Clunky and error prone.

The instructable does not upload a new sketch to the 8266. It is a sketch for the Arduino, which then talks AT commands to a stock ESP8266 board.

There are several ways to use an ESP8266:

  • Originally, it comes with firmware that is a sort of TCP/IP "modem" that you can configure with AT commands, and send data, over the serial port. This is what happened first.
  • You can load new firmware into the ESP8266 that runs, say, a Lua interpreter. Or python. Then you can send Lua/Python/whatever programs (which are text) to it 'somehow', and run them. This came along a bit more recently.
  • You can run a compiler that generates native ESP8266 code and upload that to the chip. An Arduino "core/board package" has been implemented that allows the Arduino IDE to create native code. This replaces any other firmware that might be on the 8266, each time you upload.

aarg:

Serial.println("AT+CWMODE=1");

delay(2000);

Could you give me specific examples of how these AT commands could be replaced with Arduino code?
Seeing how it's done might help me understand the process so I can study it.

Serial.println("AT") (This simply checks to see if the communications channel is ready)

AT+CWMODE=1 (returns the mode of operation of the device)

String cmd = "AT+CIPSTART="TCP","" (starts a TCP connection)

So if the ESP8266 no longer recognizes or responds to AT commands, how can you accomplish the same things just using the Arduino language?

If you have previously overwritten the OEM firmware with sketches, is it even possible to flash it back to firmware that will respond to AT commands.

Seems that every tutorial i've seen (and I've looked at a TON of them now), they all seem predicated on you being able to issue AT commands to be able to flash them with firmware that will respond to AT commands.

In other words, the SDK firmware uploads will update older firmware to never firmware, but if you have ever uploaded any type of Arduino sketch, that ESP8266 is done in terms of ever being able to go back to any firmware that will respond to AT commands.

As someone above put it......your best bet is to just buy another ESP8266.

Sort of a circular problem with no solution?

The AT firmware has an OTA update feature that allows you to update to the latest stable version of the AT firmware using an AT command. To use that feature you must already have the AT firmware installed and also you must have the version of the firmware installed that contains that feature (you can install a version without the OTA feature to allow the firmware to fit on the ESP8266 modules with 0.5 MB of flash). To make things more complicated, there are actually two flavors of the AT firmware. One is from Espressif, the manufacturer of the ESP8266 IC. The other is from AI-Thinker, the manufacturer of the ESP8266 modules. I have not found good documentation of the AI-Thinker firmware and I only use the Espressif firmware so I don't know what the OTA behavior of the AI-Thinker firmware is. However, the ESP8266 modules typically ship with the AI-Thinker AT firmware on them. For this reason I always flash the AT firmware to my ESP8266 when I want to use them with AT commands even if they already have AT firmware on them because I want to use the firmware that is reasonably well documented. For a beginner I would not recommend doing that unless they have a good reason since it just adds one more chance for confusion.

If you want to flash the AT firmware files to the ESP8266 from your computer using one of the flashing tools it doesn't make any difference what firmware was previously loaded on the ESP8266 since it will just be erased. There are plenty of tutorials that describe the flashing process. I'm really surprised you haven't seen any, including the links I posted in my previous reply.

pert:
The AT firmware has an OTA update feature that allows you to update to the latest stable version of the AT firmware using an AT command. To use that feature you must already have the AT firmware installed and also you must have the version of the firmware installed that contains that feature (you can install a version without the OTA feature to allow the firmware to fit on the ESP8266 modules with 0.5 MB of flash). To make things more complicated, there are actually two flavors of the AT firmware. One is from Espressif, the manufacturer of the ESP8266 IC. The other is from AI-Thinker, the manufacturer of the ESP8266 modules. I have not found good documentation of the AI-Thinker firmware and I only use the Espressif firmware so I don't know what the OTA behavior of the AI-Thinker firmware is. However, the ESP8266 modules typically ship with the AI-Thinker AT firmware on them. For this reason I always flash the AT firmware to my ESP8266 when I want to use them with AT commands even if they already have AT firmware on them because I want to use the firmware that is reasonably well documented. For a beginner I would not recommend doing that unless they have a good reason since it just adds one more chance for confusion.

If you want to flash the AT firmware files to the ESP8266 from your computer using one of the flashing tools it doesn't make any difference what firmware was previously loaded on the ESP8266 since it will just be erased. There are plenty of tutorials that describe the flashing process. I'm really surprised you haven't seen any, including the links I posted in my previous reply.

"Seen any"?
I think I've seen them all. I'm sure I've been through 50 different flash processes at this point.
I'm having a hard time finding links or YouTube videos I haven't already watched or tried.
I can't recall any that didn't at some point need to use AT commands....even if just to check communications between the ESP8266 and Serial to USB device or Arduino.

This tutorial https://www.allaboutcircuits.com/projects/update-the-firmware-in-your-esp8266-wi-fi-module/
has a bunch of info and steps that use AT commands, but none are actually necessary to update the firmware.
All you really need is the Flash Download Tool, a serial connection to the ESP, and the proper dance of the RESET and BOOT connections (described elsewhere on that page.)
(this is essentially the process to invoke the ESP8266 serial bootloader. I believe that the WeMos-like boards include some circuitry to make this more automatic and upload their bare sketches, so essentially if you can load arduino sketches, you could also re-load the Expressif firmware and return a module to its AT-command accepting state.)

quamikazee:
I can't recall any that didn't at some point need to use AT commands....even if just to check communications between the ESP8266 and Serial to USB device or Arduino.

Well of course it's a good idea to send a test AT to the ESP8266 after you get done flashing it just to check if it actually worked (it should respond OK). But that doesn't mean you need the AT firmware installed to flash the firmware.

Just tried this......

*the RX, TX, GND lines of the USB-serial adapter to the ESP8266. Ground GPIO0. Power the ESP8266.
*Plug in the USB-serial chip to your computer.
*Select the correct COM port in the "Flash Download Tool".
*In the SpiFlashConfig section, check the SpiAutoSet checkbox
*In the Download Path Config section, make sure all checkboxes on the left side are unchecked
*Click the START button.
*After a little while you should see text appear in the "DETECTED INFO" box.

Lots of nice blinking green, red and blue lights......but never the resulting information....always fails.

This again is with a known working ESP8266 because I can still get it fired up just fine as a WiFi server or AP if I reflash it with the proper sketch.

I think Im running out of options. Probably spent over 100 hours in the last week trying to get this to work. Can't keep doing this. Something's obviously wrong. Can't imagine I've made 20+ trial setups all with the wrong connections.

CAREFULLY checked Baud rates, tried ALL the combinations. Checked, double checked, then triple checked schematics. Have honestly tried 10-20 different approaches from various sources.
Used a quality CC/CV regulated power supply to power the ESP8266....

My conclusion is that it's simply not possible to flash some ESP8266 devices back to OEM firmware.

Someone wise said it's much better to forego all this nonsense and just buy new ESP8266 and do NOT ever upload sketches to them. I can see now the wisdom in that philosophy. I have a half dozen arriving next week. Most will be specially marked - to never upload a sketch to it.

Apparently the issues I encounter are not unique.....

Update: for those long enduring...weary travelers who've also been down this arduous road....

I downloaded numerous older versions of the ESP8266 Download Tool

After trying half a dozen older versions....ONE worked. I have absolutely NO CLUE why ONE older version of the download tool would work and not all the others including the latest and ones from two years ago.

THE only version of ESP8266 Download Tool that worked for me is/was v 3.4.1
https://github.com/boseji/ESP-Store/blob/42f8f8c6167978342cc346c02d74c3af46ae2a6b/tools/flash_download_tools_v3.4.1_win.zip

Again...NO CLUE ON EARTH why THAT version alone would work.

But here is the elusive information I was seeking....

flash vendor:
E0h : N/A
flash devID:
4014h
QUAD;8Mbit
crystal:
26 Mhz

And I also finally got the MAC addresses which I verified and were correct.

So this begs an enormous question......
WHY would only a certain (older) version of the ESP8266 Download Tool work?

Anyway.....
Using the information finally gathered in the output (8Mbit), I went to Expressif and found the necessary information for that flash size

http://espressif.com/en/support/download/documents?keys=&field_type_tid[]=14

GETTING STARTED --> ESP8266 AT Instruction Set (uh oh...there's that "AT" again)

Anywho.....needed to reboot my computer.....

After doing so I can once again NOT connect to the ESP8200 with the EXACT same parameters, connection etc

So that once in a lifetime connection appears to have been a fluke.

Can't repeat the connection.

What I get now is......

Connecting....
*********************
pic path: ./RESOURCE/IDLE_S.bmp
************************
raise in device connect
chip sync error.
baudrate sync fail ... retry...

(repeat)(repeat)(repeat)...forever.....

You might be inclined to say that I have the baudrate settings wrong.....but actually they are checked, checked again and re-checked to be the same in device manager for the COM port in question AND in the setting for the DOWNLOAD TOOL

Look at this....it "tried" to flash, but couldn't handle the speed of 115200

Odd...you have no choice but to flash at 115200...but then the flasher complains it's too fast.

Maybe my FTDI 232 can't handle those speeds?

I often want to try lower speeds in the Download Tool but the lowest speed available is 115200
Is there any what to change that?

What versions of the Download Flash Tool allow speeds below 115200?