This is an old revision of the document!
Table of Contents
Espressif Systems ESP8266
The Espressif Systems ESP8266 is used in cheap WiFi modules. It embeds an Xtensa LX3 CPU.ESP8266 boards named ESP-XX come with at least 1/2 megabyte of SPI flash for program storage.
Pinout
ESP-01
U0TXD 2 1 GND CHIP_EN 4 3 GPIO2 EXT_RSTB 6 5 GPIO0 VDD 8 7 U0RXD Component side with antenna to right
Power
A well regulated power supply is suggested. An LD1117 3V3 has been tested and works well.
3V3 ---------- VDD 3V3 ---10K---- CHIP_EN GND ---------- GND
AT firmware update
The default AT firmware can be updated using ESPTool.
wget "http://wiki.kewl.org/downloads/v0.9.2.2 AT Firmware.bin" esptool.py --port /dev/ttyUSB0 write_flash 0x000000 "v0.9.2.2 AT Firmware.bin" Connecting... Erasing flash... Writing at 0x0007ef00... (100 %) Leaving...
AT console
The updated AT firmware uses 9600 baud by default, the original is 115200.
3V3 UART ESP-XX ======== ====== RX -- 470R -- U0TXD TX -- 470R -- U0RXD GND ---------- GND
picocom -b 9600 --omap crcrlf /dev/ttyUSB0 AT+RST ... [System Ready, Vendor:www.ai-thinker.com] AT+GMR 0018000902 OK AT+CWMODE=1 OK AT+CWLAP +CWLAP ...
The commands above reset the device, set its mode of operation and scan for access points.
NodeMcu
NodeMcu is a LUA interpreter than runs on the ESP-XX chip. It can be used to communicate over the network and control the GPIOs.
We will use ESPTool to install NodeMcu for esp8266.
git clone https://github.com/nodemcu/nodemcu-firmware git reset --hard fb967dd8a2c8282e146626642bf24e8c90cdbcd0 cd nodemcu-firmware/pre_build/0.9.5 esptool.py --port /dev/ttyUSB0 write_flash 0x000000 nodemcu_20150127.bin esptool.py v2.0-beta2 Connecting.... Detecting chip type... ESP8266 Uploading stub... Running stub... Stub running... Attaching SPI flash... Configuring flash size... Auto-detected Flash size: 512KB Flash params set to 0x0000 Compressed 395836 bytes to 267867... Wrote 395836 bytes (267867 compressed) at 0x00000000 in 23.5 seconds (effective 134.7 kbit/s)... Hash of data verified. Leaving... Hard resetting...
Build 20150212 firmware can be found in pre_build/latest/nodemcu_latest.bin
NodeMcu console
A regular console at 9600 baud is used to communicate with NodeMcu. The same connection scheme as per the AT console (above) is used.
picocom -b 9600 /dev/ttyUSB0 NodeMCU 0.9.5 build 20150127 powered by Lua 5.1.4 lua: cannot open init.lua > gpio.mode(3, gpio.OUTPUT) > gpio.write(3, gpio.HIGH) > gpio.write(3, gpio.LOW)
In the above we set GPIO0 to an output, set it high, then set it low.
NodeMcu pins
pin | GPIO | ESP-01 |
---|---|---|
0 | 16 | |
1 | 5 | |
2 | 4 | |
3 | 0 | 5 |
4 | 2 | 3 |
5 | 14 | |
6 | 12 | |
7 | 13 | |
8 | 15 | |
9 | 3 | |
10 | 1 | |
11 | 9 | |
12 | 10 |
Although the ESP-01 only has 2 GPIOs, NodeMcu has I2C support and a circuit such as this can extend its capabilities.
Tasmota
Tasmota is firmware providing support for various devices attached to an ESP8266. It has both and HTTP (web) and MQTT interface.
It was primarily designed for SONOFF power switches but can be used with any device to give an MQTT enabled WIFI temperature monitor, for example.
Here is an example seession for a SONOFF basic switch.
Backup factory firmware.
esptool.py --port /dev/ttyUSB0 read_flash 0x00000 0x100000 image1M.bin
Write tasmota firmware.
esptool.py --port /dev/ttyUSB0 write_flash -fs detect -fm dout 0x0 sonoff-basic.bin
Now an example session with the D1 Mini Lite.
Read MAC address.
esptool.py -p /dev/ttyUSB0 read_mac esptool.py v2.6-beta1 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: xx:xx:xx:xx:xx:xx Uploading stub... Running stub... Stub running... MAC: xx:xx:xx:xx:xx:xx Hard resetting via RTS pin...
Backup flash.
esptool.py -p /dev/ttyUSB0 -b 115200 read_flash 0 0x100000 FIRMWARE.BIN esptool.py v2.6-beta1 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: xx:xx:xx:xx:xx:xx Uploading stub... Running stub... Stub running... 1048576 (100 %) 1048576 (100 %) Read 1048576 bytes at 0x0 in 92.8 seconds (90.4 kbit/s)... Hard resetting via RTS pin...
Erase flash.
esptool.py --port /dev/ttyUSB0 erase_flash esptool.py v2.6-beta1 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: xx:xx:xx:xx:xx:xx Uploading stub... Running stub... Stub running... Erasing flash (this may take a while)... Chip erase completed successfully in 4.1s Hard resetting via RTS pin...
Write tasmota firmware.
esptool.py --port /dev/ttyUSB0 write_flash -fs detect -fm dout 0x0 sonoff.bin esptool.py v2.6-beta1 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8285 Features: WiFi, Embedded Flash MAC: 60:01:94:b1:1b:ea Uploading stub... Running stub... Stub running... Configuring flash size... Auto-detected Flash size: 1MB Compressed 501424 bytes to 343631... Wrote 501424 bytes (343631 compressed) at 0x00000000 in 30.3 seconds (effective 132.5 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin...