User Tools

Site Tools


esp8266:firmware-programming

Programming and Reflashing the ESP8266 ESP-01

Instructions tested on April 2017, may be outdated! - The following instructions require technical skills and assume that you are using my LELESP dev board (or a similar one)

Testing the connection

I connected the module to my PC through the FTDI cable. At this point, I wanted to start talking to the ESP. For that, a terminal emulator like picocom or the standard screen command will do the job. First, your board might talk at any of several baud rates. The ones to try first are 9600 and 115200 (it depends on the version of the firmware running onboard).

Please note that most recent ESP firmwares require Carriage-Return-and-New-Line (\n\r - ASCII 10 13) line endings. Hence, you need press followed by Ctrl-J to send a command. However, picocom can be easily configured to send a linefeed after each carriage return. So you can run picocom as follows.

picocom -b 115200 /dev/ttyUSB0 --omap crcrlf

and you are ready to send your first commands!

If your serial transmission rate is correct, try typing “AT”: it should echo the characters as you type them and should return an “OK”. And you are now ready to start working with the ESP8266.

AT

OK

AT+GMR
AT version:0.25.0.0(Jun  5 2015 16:27:16)
SDK version:1.1.1
Ai-Thinker Technology Co. Ltd.
Jun 23 2015 23:23:50


AT+RST

OK

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x40100000, len 1396, room 16 
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4 
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4 
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

���(�SQS�(RQ�)HT�)SHHHC���r�ù�
Ai-Thinker Technology Co. Ltd.

invalid


AT+CWMODE?
+CWMODE:2

OK

AT+CWMODE=1

OK

AT+CWLAP
+CWLAP:(4,"FASTWEB-1-T4oittrFQO6h",-85,"f0:84:2f:4d:62:08",6)
+CWLAP:(3,"Vodafone-25253631",-89,"00:24:89:ae:1b:f2",7)
+CWLAP:(0,"Vodafone-WiFi",-90,"00:24:89:ae:1b:f4",7)
+CWLAP:(2,"NoFlyZone",-61,"68:72:51:02:e0:17",9)
+CWLAP:(4,"WIND-WiFi-C7BE",-79,"64:a6:51:00:c7:be",11)
+CWLAP:(3,"Vodafone-30083995",-80,"90:35:6e:7b:a0:b8",12)

OK
AT+CIPSTAMAC?
+CIPSTAMAC:"18:fe:34:da:c4:5b"

OK

Note the noise when you reset the device: some typical bootup messages are sent at 76800, . But there should be a ”ready“ message at the selected baud rate if your UART Rx is wired correctly.

So, ESP8266 boots up into the serial modem mode, and you can communicate with it using a set of AT commands (historically AT commands are based on the Hayes Command Set). Have a look at a list of the AT Commands supported by ESP8266 for more information on the commands shown above.

Upgrading the firmware

Esptool.py is a tool that can be used to install/upgrade firmware onto ESP-XX modules. It is a Python-based, open source, platform independent, utility to communicate with the ROM bootloader in Espressif ESP8266 ∧ ESP32 chips that was started as an unofficial community project but now is also supported by Espressif.

The latest stable esptool.py release can be installed from pypi via pip or pip3 with

pip install esptool

and used as follows

esptool.py -p /dev/ttyUSB0 -b 115000 write_flash 0x000000 ai-thinker-v1.1.1.bin 
esptool.py v1.3
Connecting.....
Auto-detected Flash size: 8m
Running Cesanta flasher stub...
Flash params set to 0x0020
Writing 1044080 @ 0x0... 55296 (5 %)
...

Wrote 1044480 bytes at 0x0 in 90.6 seconds (92.3 kbit/s)...
Leaving...

Manually assembling a bootable firmware image can be a bit of a pain, but the tool is useful to install official, ready-made AiThinker images.

Moreover, the most recent version of the Espressif firmware cannot run on the ESP-01. A working version of the firmware is ai-thinker-v1.1.1 (download here - md5sum: 26fce93d7fa31fba177da9a4ae171657)

Setup ESP inside the Arduino IDE

First, Arduino IDE needs to be configured to support the ESP module (Arduino version 1.6.4 or higher is required). To install this additional board, as I did for the ATtiny44, follow this step:

  • Open the preferences of the Arduino IDE from File → Preferences
  • Enter the URL http://arduino.esp8266.com/stable/package_esp8266com_index.json into the “Additional Board Manager URLs” field and click OK
  • Select the board from Tools → Board → Boards Manager. Scroll down (or search) and select the ESP8266 board menu; finally, install “ESP8266 platform” (version 2.30 is the latest as of may 2017)
  • From Tools → Board select “Generic ESP8266 Module”

I left untouched all the board settings under Tools and I only checked the upload speed (115200).

ESP Hello World with Arduino IDE

The first program I uploaded was the classic Blink sketch available from the Arduino examples. However, I changed the LED pin from 13 to 2 from 13, since ESP8266-01 has only two GPIO pins: GPIO0 and GPIO2.

void setup() {
  // initialize digital esp8266 gpio 2 as an output.
  pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

I compiled the code, clicked on (and released too early) the Upload button and…

Sketch uses 222,133 bytes (51%) of program storage space. Maximum is 434,160 bytes.
Global variables use 31,508 bytes (38%) of dynamic memory, leaving 50,412 bytes for local variables. Maximum is 81,920 bytes.
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
error: failed reading byte
...
warning: espcomm_send_command: cant receive slip payload data
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

So I kept the Program pressed button on my board, then i pushed Reset button and, finally, tried to upload the program again

Sketch uses 222,133 bytes (51%) of program storage space. Maximum is 434,160 bytes.
Global variables use 31,508 bytes (38%) of dynamic memory, leaving 50,412 bytes for local variables. Maximum is 81,920 bytes.
Uploading 233280 bytes from /tmp/arduino_build_830276/WiFiTelnetToSerial.ino.bin to flash at 0x00000000
................................................................................ [ 35% ]
................................................................................ [ 70% ]
....................................................................             [ 100% ]

The GPIO2 pin was switching periodically from 3.3V to 0V, blinking the attached LED on my dev board!


WARNING You need to enable flash programming when turning on the module. So, if you want to program the ESP8266, follows these steps:

  • turn off the ESP;
  • bring GPIO0 to ground;
  • turn on the ESP;
  • upload the code.

If you are using my board you just have to

  • press (and keep pressed) the program button;
  • push the reset button;
  • upload the code;

In both cases, you can release the push-button as soon as Arduino IDE starts uploading.


esp8266/firmware-programming.txt · Last modified: 2019/02/02 22:07 by admin