Which IDE is used to program ESP8266

ESP8266 and ESP8285 Module Instructions

The WiFi monitor monitors the availability of a web server and shows the status with a colored LED (source code)
← Home On this page you will find everything you need to know to get started in order to build and program your own WLAN-enabled devices with these chips.

The ESP8266 and ESP8285 chips from the Chinese manufacturer Espressif are 32-bit microcontrollers with an integrated Wi-Fi interface. Their firmware is based on Adam Dunkels' Lightweight IP stack. Numerous handy modules with these microchips are sold.

Usually the small ESP modules are sold with what is known as "AT firmware", which makes it possible to use them in a similar way to analog modems or Bluetooth modules. The serially connected microcontroller then sends commands to the module to establish connections and transfer data. In my book Introduction to Electronics with Microcontrollers, I showed how to build a small web server to remotely control a lamp in this way.

But you can also have your own programs run directly through the ESP chip. More on this below. With prices starting at 1.50 €, the ESP modules are a very inexpensive network connection for handicrafts.

Datasheets: ESP8266, ESP8285

Technical specifications

  • Power supply:
    • Voltage: 2.8 to 3.6 volts1
    • Average: 80 mA
    • When sending: 430 mA
    • Deep sleep: 25 µA
  • Interfaces:
    • SPI, I²S, 2 · UART (the second can only output)
    • 11 programmable I / O pins max. 12 mA
    • 1 analog input 0 to 1 V with 10 bit resolution
  • Storage:
    • 80 kbytes of RAM
    • 32 kbyte cache
    • ESP8266: max. 16 MByte external flash, of which max. 1 MByte for code
    • ESP8285: 1 Mbyte Flash internal
    • The basic firmware occupies around 30 kB of RAM and 260 kB for flash
  • Network:
    • Wi-Fi 802.11 b / g / n 2.4 GHz with WPA / WPA2 PSK
    • IPv4, since SDK 2.0 and Arduino Core 2.5.0 also IPv6
    • UDP and TCP, maximum 5 simultaneous connections
    • Broadcasts are not supported
    • Throughput: 150 to 300 kByte / s in both directions2
    • Latency: 4 to 10 ms2
    • Soft AP for up to 4 clients3
1) The minimum voltage depends on the flash memory. 2.8 volts always work. Some modules even run at 2.5 volts.
2) When the radio channel is free. Latencies of up to 200 ms are normal on heavily used radio channels.
3) The ESP8266 has no router function. In Soft-AP mode, the WLAN clients can only communicate with the ESP, not with each other.

Modules and boards

One piece of information in advance: The CHIP_EN pin is also called CHIP_PU, CH_PD, ENABLE or EN for short.

ESP-01 and ESP-1 module

The ESP-01 module from AI-Thinker is based on the ESP8266. It is sold with 512 kByte (in blue) or 1 MByte (in black) flash memory. The red power LED consumes about 0.5 mA of current, the blue LED is connected to GPIO2. The ESP-1 module from DOIT is based on the ESP8285. It has 1 Mbyte flash memory and a cover for shielding. It only has one blue LED on GPIO2.

The minimum wiring for using the AT firmware looks like this:


Module pinArduino pinSurnamedescription
13RxD (GPIO3)serial input or normal I / O pin
2VCCPower supply 3.3 V 500 mA
30GPIO0Low at start activates firmware upload, must be open for normal start or set to high
4RESETLow = reset
52GPIO2 (TxD1)Is connected to the blue LED that lights up when the level is LOW. Flickers at startup. Must not be pulled to low when starting. Output from the second UART, which can only output.
6CHIP_ENMust be pulled high for the chip to work. Low = Chip Power Down, High = Chip Enabled
7GNDDimensions
81TxD (GPIO1)serial output or normal I / O pin, is connected to the blue LED, flickers when starting, must not be pulled to low when starting

The 8-pole pin header in a 2.54 mm grid is the most striking feature of these modules. This makes them easy to use with a short Remove the flat cable to optimize reception.

GPIO15 is permanently connected to GND. Be careful not to inadvertently program it as an output, as a short circuit can destroy the pin so that the chip no longer starts.

The range of the primitive antenna (conductor loop) is comparable to that of smartphones.

ESP-07 and ESP-12 modules

These modules all come from AI-Thinker. They contain the ESP8266 chip and a flash memory. My personal favorite is the ESP-12F.

The minimum wiring for using the AT firmware looks like this for these modules:


Module pinArduino pinESP namedescription
1RESETLow = reset, see the partial circuit diagrams above
217ADCAnalog input 0 to 1 V.
3CHIP_ENMust be pulled high for the chip to work. Low = Chip Power Down, High = Chip Enabled
416GPIO16In deep sleep mode: output from the wake-up timer
514GPIO14 (SCK)Normal I / O pin or SPI clock
612GPIO12 (MISO)Normal I / O pin or SPI data
713GPIO13 (MOSI)Normal I / O pin or SPI data
8VCCPower supply 3.3 V 500 mA
9Reserved. These pins only exist on the ESP-12E and ESP-12F. They are occupied by the flash memory.
10
11
12
13
14
15GNDCommon ground
1615GPIO15 (CS)Normal I / O pin or SPI chip select, must be pulled to low at start, flickers at start
172GPIO2 (TxD1)Is connected to the blue LED that lights up when the level is LOW. Flickers at startup. Must not be pulled to low when starting. Output from the second UART, which can only output.
180GPIO0Low at start activates firmware upload, must be open for normal start or set to high
194GPIO4Normal I / O pin
205GPIO5Normal I / O pin
213RxD (GPIO3)serial input or normal I / O pin
221TxD (GPIO1)serial output or normal I / O pin, flickers when starting, must not be pulled to low when starting

The connection strips of the ESP-12 modules have a 2 mm grid. The range of the on-board antenna is comparable to that of smartphones. With a good external antenna, the ESP-07 (S) should go even further. The antenna connector is called SMT, U.FL or IPEX. Attention: they come in different sizes!

NodeMCU board

The NodeMCU board consists of an ESP-12 module with voltage regulator and USB-UART interface. The flash memory is 4 megabytes in size. The original NodeMCU board is no longer manufactured, but there are numerous replicas with similar equipment.


Board J2NodeMCU labelArduino pinESP namedescription
1VINPower supply 5 to 9 V 500 mA
2GGNDCommon ground
3RSTRESETHas 12 kΩ pull-up resistor and a button with 470 Ω to GND
4ENCHIP_ENLow = Chip Power Down, High = Chip Enabled, has 12 kΩ pull-up
53VVCCPower supply 3.3 V (input 500 mA or output max. 300 mA)
6GGNDCommon ground
7Reserved. Occupied by the flash memory.
8
9
10
11
12
13Reserved
14
15A017ADCAnalog input for 0 to 3.2 V because with voltage divider 220 kΩ + 100 kΩ
Board J1NodeMCU labelArduino pinESP namedescription
13VVCCPower supply 3.3 V (input 500 mA or output max. 300 mA)
2GGNDCommon ground
3TX (D10)1TxD (GPIO1)Serial output of the ESP connected to the USB-UART via 470 Ω, flickers when starting, must not be pulled to low when starting
4RX (D9)3RxD (GPIO3)Serial input of the ESP connected to the USB-UART via 470 Ω
5D815GPIO15 (CS)Normal I / O pin or SPI chip select, must be low at start, has 12 kΩ pull-down resistance, flickers at start
6D713GPIO13 (MOSI)Normal I / O pin or SPI data
7D612GPIO12 (MISO)Normal I / O pin or SPI data
8D514GPIO14 (SCK)Normal I / O pin or SPI clock
9GGNDCommon ground
103VVCCPower supply 3.3 V (input 500 mA or output max. 300 mA)
11D42GPIO2 (TxD1)Is connected to the blue LED that lights up when the level is LOW. Flickers at startup. Must be high at start. Has 12 kΩ pull-up resistor. Output from the second UART, which can only output.
12D30GPIO0Low at start activates firmware upload, has 12 kΩ pull-up resistor and a button with 470 Ω to GND, flickers at start
13D24GPIO4Normal I / O pin
14D15GPIO5Normal I / O pin
15D016GPIO16Is connected to the blue LED that lights up when low. In deep sleep mode: output from the wake-up timer

In Arduino you can use the NodeMCU labels, but I recommend using the Arduino pin numbers as they correspond to the GPIO numbers of the chip.

You can operate it either at the 3.3V input with 2.8 to 3.6 V, or at the 5 V input with 5 to 9 V, or via the USB cable with about 5 V. A diode prevents current from the 5V input flows to the USB port. The built-in voltage regulator has a maximum power reserve of 300 mA at 5 V input voltage for external expansions. The board is rather unsuitable for battery operation, as it has a quiescent current consumption of around 15 mA.

The board runs more reliably on a breadboard if you remove the reserved pins that lead to the flash memory.

The reset line and GPIO0 can be controlled by the USB-UART. The Arduino IDE activates the firmware upgrade mode fully automatically:

DTRRTSRESETGPIO0
OutOutHighHigh
AAHighHigh
OutALowHigh
AOutHighLow

The two cross-connected transistors in the circuit diagram of the NodeMCU board are responsible for this. Alternatively, you can activate the firmware upgrade mode manually by pressing both buttons and then releasing the reset button first.

Wemos D1 Mini Board

The Wemos D1 Mini Board is available in the following versions:

versionESP chipFlash MByteLED on GPIO2antennaLithium charge controller
Wemos D1 Mini Lite v1ESP82851YesConductor loopNo
Wemos D1 Mini v2ESP-12 module (= ESP8266)4NoConductor loopNo
Wemos D1 Mini v3ESP82664YesConductor loopNo
Wemos D1 Mini Pro v1 (or -16)ESP826616YesCeramic antenna and ext. Antenna connectorNo
Wemos D1 Mini Pro v2ESP826616YesCeramic antenna and ext. Antenna connectorYes

The top four boards have the same dimensions, the last one with the charge controller is a little longer. All versions have a USB-UART (CH-340) and a low-drop voltage regulator. All free I / O pins of the ESP chip are brought out, but not the CHIP_EN pin.

The pin assignment is the same for all Wemos D1 Mini Boards:

Board pinNodeMCU labelArduino pinESP namedescription
1RSTRESETHas a 10 kΩ pull-up resistor and a 100 nF capacitor to GND
2A017ADCAnalog input for 0 to 3.2 V because with voltage divider 220 kΩ + 100 kΩ
3D016GPIO16In deep sleep mode: output from the wake-up timer
4D514GPIO14 (SCK)Normal I / O pin or SPI clock
5D612GPIO12 (MISO)Normal I / O pin or SPI data
6D713GPIO13 (MOSI)Normal I / O pin or SPI data
7D815GPIO15 (CS)Normal I / O pin or SPI chip select, must be low at start, has 10 kΩ pull-down resistance, flickers at start
83V3VCCPower supply 3.3 V (input 500 mA or output max. 50 mA)
95VPower supply 4 to 7 V 500 mA
10GGNDCommon ground
11D42GPIO2 (TxD1)All except Mini v2 have a blue LED that lights up when the level is low. Flickers at startup. Must be high at start. Has 10 kΩ pull-up resistor. Output from the second UART, which can only output.
12D30GPIO0Low at start activates firmware upload, has 10 kΩ pull-up resistance, flickers at start
13D24GPIO4Normal I / O pin
14D15GPIO5Normal I / O pin
15RX (D9)3RxD (GPIO3)Serial input of the ESP connected to the USB-UART via 470 Ω
16TX (D10)1TxD (GPIO1)Serial output of the ESP connected to the USB-UART via 470 Ω, flickers when starting, must not be pulled to low when starting

In Arduino you can use the NodeMCU labels, but I recommend using the Arduino pin numbers as they correspond to the GPIO numbers of the chip.

You can operate it either at the 3.3V input with 2.8 to 3.6 V, or at the 5 V input with 4 to 7 V, or via the USB cable with about 5 V. A diode prevents current from the 5V input flows to the USB port.

Depending on the variant, the quiescent current consumption of the board is between 200 and 300 µA, so that it is conditionally suitable for battery operation. The voltage regulator is just sufficient for the WLAN chip, it may only be subjected to minimal external loads (50 mA at 5 V).

The reset button pulls the reset pin directly to GND without a protective resistor. In addition, the board has the same reset circuit as the NodeMCU board to automatically activate the firmware upgrade mode. The Wemos D1 Mini does not have a "Flash" button.

The analog input A0 is equipped with a voltage divider (220kΩ + 100kΩ) so that voltages up to 3.2 V can be measured.

Documentation from the manufacturer.

Attention: There are bad replicas with insufficient voltage regulators in circulation.

WIFI Kit 8 board

The WIFI Kit 8 (alias Heltec HTIT-W8266 or Wemos TTGO ESP8266) has 4 MByte flash memory and a tiny 0.91 "OLED display with 128x32 pixels. Graphics and 4x21 characters of text can be output on it. The display controller type SSD1306 is connected to the ESP8266 via I²C. The CP2104 chip from Silabs was used for the USB socket.

Many dealers sell these boards with incorrectly labeled pins and incorrect connection diagrams! The following drawings show the correct pin assignment and the connections to the display in brackets:

Upper pin header:

penVersion aVersion Bdescription
1GND
25 VPower supply 5 V 500 mA
33.3VPower supply 3.3 V (input 500 mA or output max. 200 mA)
4GNDCommon ground
5CTSClear-To-Send input from USB-UART, low active
6DTRData terminal ready output from USB-UART, low active
7GPIO5 (SCL)GPIO5Version A: I²C clock to the display with 10 kΩ pull-up resistor
Version B: Normal I / O pin.
8TxD (GPIO1)Serial output of the ESP or normal I / O pin, connected directly to the USB-UART, flickers when starting, must not be pulled to low when starting
9RxD ()Serial input of the ESP, directly connected to the output of the USB-UART, therefore cannot be used as a GPIO.
10RESETHas a 1.2 kΩ pull-up resistor and a button to GND
11GPIO2 (TxD1)GPIO4 (RES)Version A: Normal I / O pin, flickers when starting, must not be pulled to low when starting. Output from the second UART, which can only output.
Version B: Reset signal to the display, low active.
12CHIP_ENMust be high for the chip to work. Has 10 kΩ pull-up resistor. Low = Power Down, High = Enabled

Lower pin header:

penVersion aVersion Bdescription
1GNDCommon ground
25 VPower supply 5 V 500 mA
33.3VPower supply 3.3 V (input 500 mA or output max. 200 mA)
4GNDCommon ground
5GPIO4 (SDA)GPIO0Version A: I²C data to the display with 10 kΩ pull-up resistor.
Version B: Low at start activates firmware upload, has 10 kΩ pull-up resistor and a button to GND, flickers at start
6GPIO0GPIO2 (SDA, TxD1)Version A: Low at start activates firmware upload, has 10 kΩ pull-up resistor and a button to GND, flickers at start.
Version B: SDA signal to the display, flickers when starting, must not be pulled to low when starting. Output from the second UART, which can only output.
7GPIO15 (CS)Normal I / O pin or SPI chip select, must be low at start, has 10 kΩ pull-down resistance, flickers at start
8GPIO13 (MOSI)Normal I / O pin or SPI data
9GPIO12 (MISO)Normal I / O pin or SPI data
10GPIO14 (SCK)GPIO14 (SCL, SCK)Version A: Normal I / O pin or SPI clock.
Version B: I²C clock to the display or SPI clock, with 10 kΩ pull-up resistor
11GPIO16 (RES)GPIO16Version A: Resets the display when the level is low.
Version A + B in deep sleep mode: output from the wakeup timer
12ADCAnalog input for 0 to 3.2 V because with voltage divider 220 kΩ + 100 kΩ.

The information from Heltec matches version A, but is incomplete and incorrect.

In Arduino source code, the pin numbers correspond to the GPIO numbers. You write digitalWrite (2, HIGH) to set the GPIO2 to high. The analog input is called A0 or 17 in Arduino.

Power is supplied either via USB, a 3.3 V power supply or a 5 V power supply. In addition to the ESP chip, the display consumes approx. 30 mA. The built-in voltage regulator has a power reserve of 200 mA for expansions. Since the 5 V connection is directly connected to the USB socket, a 5 V power supply unit should not be used at the same time when using USB.

The board is only suitable for battery operation to a limited extent, as its quiescent current consumption never falls below 6 mA. Below 3.3 V battery voltage, the board fails and then sucks the battery with 80 mA empty until it either breaks or its integrated protection circuit (if present) switches off. When charging, the board gets quite warm, which is bad for the life of the display.

The reset method for automatically activating the firmware upgrade mode corresponds to the NodeMCU board. The two buttons pull the lines RESET and GPIO0 directly to low without protective resistors. The USB-UART is also connected directly to the I / O pins for TxD and RxD, so the RxD pin (= GPIO3) cannot be used for other purposes.

When experimenting on a breadboard, I had extremely poor WiFi reception. I was able to fix the problem by lengthening the connecting legs by 7 mm.

For programming the display, I recommend either my slim OLED class or the SSD1306 and GFX libraries from Adafruit.

One should note the short lifespan of the OLED. At maximum brightness, the brightness of the affected pixels drops significantly after a year.

Power supply

Inadequate power supply is the most common cause of malfunctions and can even destroy the chip. The ESP chip requires a stable power supply between 2.8 and 3.6 volts at 10µA to 430 mA for reliable operation. The voltage may only change slowly within this range. So a fast voltage regulator is required that regulates extreme current fluctuations without becoming unstable.

Finished boards often contain the AMS1117. It is fast and strong, but it has a high quiescent current consumption and requires at least 10mA load. In the sleep and power-down modes there is a risk that the voltage regulator will output too high a voltage due to insufficient load! So I prefer to use the LF33.

Regardless of where the power supply comes from, I strongly recommend soldering a 100 µF capacitor directly to the VCC and GND connections of the ESP module. This is already available on the NodeMCU board.

The power supply lines should be as short as possible and come together in a star shape at a distribution point. This is especially true for GND. Because of the high contact resistance, breadboards are poorly suited for power distribution.

The resistors around the chip should have a maximum of 2.2 kΩ, because high-value resistors are sensitive to radio waves. Metal parts (including conductor tracks) are to be avoided in the vicinity of the antenna, as they impair reception.

Operation on batteries / rechargeable batteries

All boards with a USB interface and voltage regulator are rather unsuitable for long-term operation on batteries, as they consume too much quiescent current. Here, minimal, no-frills modules (like the ESP-12F) are the better choice.

I recommend the following power supply for this:

  • A LiFePO4 cell, directly without a voltage regulator
  • A LiIo or LiPo cell with voltage regulator
  • 4 NiMh cells at least AA size with voltage regulator
  • 4 alkaline primary cells at least AA size with voltage regulator

For batteries up to a maximum of 6 volts, I recommend the voltage regulator

I find the MCP170x less good because it is too tight with its 250 mA. The ESP needs 430 mA at times.

All of the voltage regulators mentioned do not switch off when the input voltage is too low, but instead pass the battery voltage through as far as possible. The above-mentioned loss voltage drops in the process.

If the ESP chip fails due to undervoltage, it continuously consumes approx. 80 mA. Lithium and lead batteries must therefore be equipped with a deep discharge protection. Some lithium batteries already contain such a protective circuit.

Deep sleep mode

In deep sleep mode, the power consumption of the ESP chip (including flash) is around 25 µA. The WLAN connection is interrupted. The RTC (clock) continues to run, but less precisely than in normal operation (typically 2 minutes deviation per day).

With the Arduino Framework activates the deep-sleep mode as follows:

ESP.deepSleep (60000000); delay (100);
As a parameter, you specify in how many microseconds the chip should wake up again. A maximum of 71 minutes is possible. The value 0 lets the chip sleep forever, or until the next hardware reset.

If you use the wakeup timer, the timer output GPIO16 must be connected to the RESET input of the chip as follows:

This will delay and lengthen the reset signal a bit. Take a look at the circuit diagram of your board / module! At least some of these components are likely already in place.

Since the timer is clocked by a temperature-dependent R / C oscillator, the time can deviate by two percent from the target. That doesn't sound like much, but it's 30 minutes a day!

Because the firmware restarts when you wake up, the contents of the RAM are lost. However, the RTC contains 512 bytes of additional memory that survives deep-sleep mode (but not power-down). The first 64 bytes of this, however, are reserved.

Power-down mode

In power-down mode, the chip is completely switched off. There is only a small leakage current of around 15 µA (including flash).

This mode is triggered by a falling edge at the CHIP_EN input, but only after this the firmware has started. If CHIP_EN is pulled to low too early, the chip will consume approx. 2.5 mA!

The rising edge at the CHIP_EN input causes the power-down mode to be exited and the firmware to restart.

Current consumption in reset

While the RESET input is held low, the chip consumes approx. 23 mA. The RESET input is therefore not suitable for saving electricity.

USB-UART cable

For the modules without a USB port, you need a USB-UART cable or adapter to connect it to the PC. It is important that the thing has a 3.3 V level. I always loop 1 kΩ resistors into the signal lines to limit the current if one side has no power supply.

For USB-UART products with an old or counterfeit PL2303 chip, I have a suitable old Windows driver here, because the current driver doesn't like these chips. The driver for the Chinese CH340 and CH341 chips can be downloaded directly from the manufacturer's website.

Connection to 5 V microcontroller

The ESP chip can withstand a maximum of 3.6 V on all pins. The signals from 5 V microcontrollers can be reduced with a voltage divider. In most cases, no further measures are necessary for the other direction:

Most 5 V microcontrollers (e.g. AVR) accept 3.3 V as a valid high level. If you still have to increase the signal level to 5V, you can do it like this, for example:

This circuit works with any ordinary small NPN transistor. There are bidirectional level converters with MOSFET available on the market, which are also suitable.

flash memory

The ESP82xx chip copies its firmware block by block from an external flash memory into its internal RAM. From there the code is then executed. The chip can address up to 16 Mbytes of flash memory, but only use a maximum of 1 Mbyte as program memory. The basic firmware takes up about 260 kB of this.

The ESP8266 supports the following types of access to the flash memory:

  • QIO uses 4 lines for reading and writing
  • QOUT uses 4 lines for reading but only 1 line for writing
  • DIO uses 2 lines for reading and writing
  • DOUT uses 2 lines for reading but only 1 line for writing

Which of the four variants actually work depends on the built-in memory chip. To change, you have to recompile the source code of the firmware.

The ESP8285 has 1 Mbyte Flash internally, which only supports DOUT with 40 MHz. The chip has two more I / O pins free, namely GPIO9 and GPIO10.

When starting, the chip outputs a few diagnostic messages with 74880 baud, even before the firmware is started. In the event of an error, it is worthwhile to display these messages with a terminal program.

performance

In order to get an impression of how strongly the variants of the Flash connection affect the overall performance, I carried out two series of tests. The first series of tests recorded the best response time when receiving + sending of 1 kB each. The second series of tests compares the number of multiplications in a fixed time window.
CPU freq.Flash Freq.Flash modeResponse timeComputing power
160 MHz80 MHzQIO and QOUT4 ms871
DIO and DOUT4 ms870
40 MHzQIO and QOUT4 ms870
DIO and DOUT5 ms870
80 MHz80 MHzQIO and QOUT4 ms435
DIO and DOUT4 ms435
40 MHzQIO and QOUT4 ms434
DIO and DOUT5 ms434
In summary: Flash memory has practically no influence on the speed of code execution.

Upload firmware

The ESP chip contains an unchangeable bootloader, which enables a firmware upgrade via the serial port. This bootloader always starts first during a reset. He expects the following control signals:

Firmware upload:

  • GPIO0 = LOW
  • GPIO15 = LOW
  • GPIO1 (TxD) = do not pull down
  • GPIO2 (TxD1) = do not pull down
Normal start:
  • GPIO0 = HIGH
  • GPIO15 = LOW
  • GPIO1 (TxD) = do not pull down
  • GPIO2 (TxD1) = do not pull down

GPIO1 and GPIO2 must be HIGH when starting, which is done by internal pull-up resistors. The bootloader outputs messages with 74880 baud on both serial ports. After the start, however, all four pins can be used as freely programmable I / O connections. This results in the following useful basic circuit:

To put the ESP chip into firmware upload mode, you have to press both buttons at the same time and then release the reset button first. The ESP chip then expects commands and data from the PC.

The resistor in front of GPIO0 protects against short circuits if the pin is programmed as an output. The wakeup jumper must be connected when using the deep sleep mode with wakeup timer. Many boards have copied the reset circuit from NodeMCU, with which you can save yourself pressing the button. However, it does not always work reliably.

There are numerous graphical programs for uploading the firmware, but they all seem a bit bitchy. I therefore recommend the esptool.py script, which my two firmware packages provided below contain. To run it you have to install Python beforehand. When performing the installation, make sure that it is added to the PATH variable. Then install the library for serial ports by clicking in the CMD window (command prompt) pip install serial enter.

Note on Linux:
With Debian / Ubuntu Linux, however, you install the library with the command sudo apt install python3-serial. It is also called in Linux python3, not python.

With the help of the esptool you can determine the size of the flash memory based on its ID number as follows:

Windows: python esptool.py --port COM6 flash_id Linux: python3 esptool.py --port / dev / ttyUSB0 flash_id
4013512 kByte
40141 Mbyte
40152 Mbytes
40164 Mbytes

The actual upload of a firmware file is done with the command:

python esptool.py --port COM6 write_flash 0x000000 firmware.bin
Don't worry: if the firmware upload fails (for whatever reason), you can just try again. In the event of an error, the bootloader may output helpful messages with 74880 baud.

Original AT firmware

The AT firmware enables the module to be used like a modem. By sending commands to the serial interface, you configure the module, establish connections and transfer data. The module thus serves as a network adapter for a connected microcontroller.

On the page I / O Interface Modules for WLAN I present such an example application, and in the book Introduction to Electronics with Microcontrollers I explain in detail how to do something like this.

The AT firmware sends and receives every 100 ms, a maximum of 2048 bytes per interval.

For modules with only 512 kByte flash memory you have to use the AT firmware 0.50.0.0 from SDK 1.4.0. This is the last version that still fits in there. Since the firmware is divided into several files, you have to install it as follows:

512 kBytepython esptool.py --port COM6 write_flash 0x000000 noboot / eagle.flash.bin 0x040000 noboot / eagle.irom0text.bin 0x03e000 blank.bin 0x07e000 blank.bin 0x07c000 esp_init_data_default.bin

For all larger modules I have secured the reliable AT firmware 1.1.0.0 from SDK 1.5.4. It is installed with the following command:

1 Mbytepython esptool.py --port COM6 write_flash 0x000000 boot_v1.5.bin 0x001000 512 + 512 / user1.1024.new.2.bin 0x0fc000 esp_init_data_default.bin 0x07e000 blank.bin 0x0fe000 blank.bin
2 Mbytespython esptool.py --port COM6 write_flash 0x000000 boot_v1.5.bin 0x001000 512 + 512 / user1.1024.new.2.bin 0x01fc000 esp_init_data_default.bin 0x07e000 blank.bin 0x1fe000 blank.bin
4 Mbytespython3 esptool.py --port COM6 write_flash 0x000000 boot_v1.5.bin 0x001000 512 + 512 / user1.1024.new.2.bin 0x03fc000 esp_init_data_default.bin 0x07e000 blank.bin 0x3fe000 blank.bin

If your AT firmware is older than 0.50.0.0, I recommend upgrading, as previous versions were still quite unstable. The company Espressif provides its AT firmware in the am Directory of the SDK available. There you will also find the text file README.md, which states which files have to be loaded in which position depending on the size of the flash memory.

AT commands

In this chapter I only describe the commands that are important to me. They work at least with AT firmware from version 0.21.0.0 to 3.0.2, maybe also with newer ones. When programming, note that the format of the answers varies slightly depending on the firmware version.

For testing network connections I recommend the command line program Netcat. In addition, you should definitely take a look at the Wireshark program if you are new to it. We recommend the Hammer Terminal, Putty or Cutecom as a terminal program for manual input of the AT commands.

The AT firmware usually communicates at 115200 baud. Some modules are preset to 57600 or 9600 baud. The format for line breaks is CR + LF.

After the hardware reset, the terminal program shows a few unreadable lines, and then "ready". Then you can type in commands. However, if only illegible characters appear, change the baud rate to 74880, then you can read the bootloader error messages.

Commands:

is simply answered with "OK". The command has no other function; it is ideal for testing the serial connection. switches off the echo of the commands. This command can simplify programming and slightly improve speed. With the number 1 you switch the echo on again. For manual testing it is best to leave the echo switched on. Shows the version of the firmware, for example:
AT version: 1.1.0.0 (May 11 2016 18:09:56) SDK version: 1.5.4 (baaeaebb) compile time: May 20 2016 15:06:44 OK
sets that the module should log into an existing WLAN network. triggers a software restart. This is necessary after changing from CWMODE. lists all accessible access points. For example:
+ CWLAP: (4, "EasyBox-4D2D18", - 72, "18: 83: bf: 4d: 2d: b2", 2, -46) + CWLAP: (4, "UPC2827302", - 63, "88: f7: c7: 52: 40: 9d ", 6, -22) + CWLAP: (0," Unitymedia WifiSpot ", -64," 8a: f7: c7: 52: 40: 9f ", 6, -22) + CWLAP: (3, "Pussycat", - 45, "5c: 49: 79: 2d: 5b: cd", 7, -4) OK
AT + CWJAP = "Pussycat", "supersecret"
the module connects to the WLAN network "Muschikatze" and the specified WPA / WPA2 password. This setting is automatically saved permanently and becomes active the next time you restart. The password must be at least 8 characters long! shows the access point to which the module is currently connected. For example:
+ CWJAP: "Pussycat", "5c: 49: 79: 2d: 5b: cd", 7, -60 OK
shows the IP address and MAC address of the module, for example:
+ CIFSR: STAIP, "192.168.0.111" + CIFSR: STAMAC, "5c: cf: 7f: 8b: a9: f1" OK
Sets that the module should allow multiple connections. In this mode, up to 5 simultaneous connections are possible. The following examples all assume that this mode has been activated.
The opposite would be AT + CIPMUX = 0, where the module can only be used as a client and with only one connection. In this case, the channel number is omitted for the commands that follow.

Use AT firmware as TCP server

this command turns the server on so that it accepts connections on port 5000. It can then (depending on the firmware version) accept a maximum of 4 or 5 connections at the same time. Then you could, for example, use Netcat to establish a network connection to this mini-server:
nc 192.168.0.111 5000HelloWorld!

The following messages appear at the serial port of the module:

0, CONNECT + IPD, 0.7: Hello + IPD, 0.8: World!
"0, CONNECT" means that the TCP server has accepted a connection on channel 0. "+ IPD, 0,7:" means that the server on channel 0 received exactly 7 bytes (namely "Hello \ r \ n"). Exactly these 7 bytes follow after the colon. Attention: If the received text does not end with a line break, then the next + IPD message comes directly after it in the same line!
AT + CIPSEND = 0.9 > Welcome!
With this command you send a reply to the computer. The 0 is again the channel number and the 9 is the number of bytes to be sent (maximum 2048). After the module answers with ">", you enter the characters (or bytes) to be sent. The module confirms the sending process after a short time with

According to the documentation, you should wait at least 1 second after this command. In my tests, however, 4 commands per second worked largely reliably.

with this command you close the connection on channel 0. The module answers with

Use AT firmware as TCP client

AT + CIPSTART = 0, "TCP", "mail.stefanfrings.de", 25
Channel 0 establishes a TCP connection to the specified server on port 25. Instead of the host name you can also use an IP address. The answer is for example:
0, CONNECT OK + IPD, 0.96: 220 wp039.webpack.hosteurope.de ESMTP Host Europe Mail Service Sat, 08 Apr 2017 23:37:19 +0200

Since this mail server answers immediately, you will also see a + IPD line directly. The text after the colon is the server's response. Then you can use AT + CIPSEND to send data to the server as described above. The connection is closed with AT + CIPCLOSE.

Use AT firmware for UDP

With the UDP protocol there is no need to establish a connection and thus the limitation to 5 simultaneous connections. You send individual messages to the desired recipients and hope that they will get there quickly. In contrast to TCP, the UDP protocol does not repeat lost packets. It does not even guarantee that all packets will arrive at the recipient in the correct order (this practically never happens in local networks, however).

UDP is easier to program and uses the transmission path more efficiently than TCP. It is particularly suitable for the regular transmission of measured values ​​when individual dropouts can be tolerated (e.g. temperature sensors). Unfortunately, Java scripts in websites cannot use the UDP protocol.

AT + CIPSTART = 0, "UDP", "0", 0.3002.0
After this command, the module can receive UDP messages on port 3002 from any senders. But it cannot send messages. You can use the Netcat program to test:
nc -u 192.168.0.111 3002Let's start!

Whereby you have to enter the IP address of your WLAN module. If you then type something in Netcat to send, the module will signal the receipt of the message with + IPD.

AT + CIPSTART = 0, "UDP", "0", 0.3002.2
The module receives UDP messages on port 3002 from any senders, and it can send back replies with AT + CIPSEND. The replies are always sent to the computer from which a message was last received.
AT + CIPSTART = 0, "UDP", "192.168.0.5", 3001,3002,0
The module can receive UDP messages on port 3002 from any senders. With the AT + CIPSEND command it will send messages to the computer 192.168.0.5 port 3001.

Soft-AP mode

Where there is no WLAN network, the ESP module can set up a small provisional network itself. Up to 4 other devices can then connect to the module, but they cannot see each other. The Soft-AP mode is well suited for connecting ESP modules to one another. I cannot recommend using it with smartphones and laptops, as it works unreliably with many devices. In Soft-AP mode you can reach the WLAN module with the permanently coded IP address 192.168.4.1.
AT + CWMODE = 2AT + CWSAP = "ESP module", "supersecret", 5.3AT + RST
This command sequence activates the Soft-AP mode, and sets the name of the network and the password. The 5 indicates the WLAN radio channel (0-13), and the 3 specifies that WPA2 encryption is used. This setting is automatically saved permanently and becomes active the next time you restart. The password must be at least 8 characters long!

There is also a combined mode (AT + CWMODE = 3), in which the module connects to an existing WLAN network and also creates its own second network.

Programming options

Instead of using the ESP82xx like a modem via AT commands, you can also write your own firmware that runs directly on the microcontroller of the ESP module. The Chinese manufacturer Espressif provides a software development kit (SDK) for this. To do this, however, you have to be familiar with Linux and work with incomplete documentation.

The NodeMCU project tries to simplify the programming a lot by using LUA scripts. However, this approach suffers from a notorious lack of memory. Your own LUA script and data (variables) must be squeezed into approx. 40 kByte RAM. Scroll down on the project page, there is a link to the "custom firmware build service", where you can create an individually compiled firmware.

In my opinion, the most tinker-friendly solution is the ESP8266 extension for Arduino. You program there in C ++. The installation of the Arduino IDE is very easy - no comparison to the Espressif SDK.

All three variants have one thing in common: Debugging with an IDE is only possible to a very limited extent. In practice, you will work more with serial log messages, as is usual with Arduino anyway.

Getting started with Arduino

The Arduino Core combines the manufacturer's SDK with the Arduino Framework to make programming in C ++ easier. The compilation created with it therefore always contains the original firmware of the manufacturer plus your own application program.

Installation:

If your programs run unstable, try my bundles (Arduino IDE 1.8.13 with ESP8266 Core 2.3.0): LinuxWindows

Application:

  • Set the "Generic ESP8266 Module" in the Tools menu, or whatever module you have.
  • Then set the details for the board in the tools menu below, in case of doubt:
    • Board: Generic ESP8266 Module
    • Builtin LED: 2
    • Upload speed: 115200
    • CPU Frequency: 80 MHz
    • Crystal Frequency: 16 MHz
    • Flash size: 512k
    • Flash mode: DIO
    • Flash Frequency: 40 MHz
    • Reset Method: no dtr (ck), means: You have to press the Reset + Flash buttons manually
    • Debug Port: Disabled
    • Debug level: none
    • lwIP Variant: v2 Lower Memory
    • VTables: Flash
    • Exceptions: Legacy
    • Erase Flash: Only Sketch
    • Espressif FW: nonos-sdk
    • SSL Support: All SSL ciphers
    • Port: According to your USB-UART adapter (see Windows device manager or Linux command "dmesg")
    • Programmer: it doesn't matter, we always use a USB UART
  • Write your program (sketch).
  • Compile the program with the menu item Sketch / Check & Compile.
  • Upload your program with the menu item Sketch / Upload.

The menu item "Burn Bootloader" is irrelevant for the ESP8266, because it has a permanently installed bootloader that cannot be changed.

The serial monitor from the Arduino IDE sometimes doesn't work for me under Linux, but it always works with an external program (e.g. Cutecom). Something is wrong when switching the baud rate.

Read the documentation for Arduino and the ESP8266 Core version 2.3.0 / current version. The documentation for version 2.3.0 is also included in the bundle above.

Example skits

The Arduino IDE displays sketches in the "File / Examples" menu that demonstrate the use of the ESP8266 extension. In addition, I will show you skits that you can copy 1: 1 into your Arduino IDE for first attempts.

LED turn signals

The first sketch causes the blue LED on the ESP-12 module to flash and alternates between "Tick" and "Tack" on the serial port. He also logs into the WLAN network so that the module can be reached with a ping command.
#include // The ESP-12 has a blue LED on GPIO2 #define LED 2 // Name and password of the WLAN access point #define SSID "Pussycat" #define PASSWORD "supersecret" / ** Runs once at startup * / void setup () {Serial.begin (74880); pinMode (LED, OUTPUT); WiFi.mode (WIFI_STA); WiFi.begin (SSID, PASSWORD); } / ** Main loop, executed repeatedly * / void loop () {digitalWrite (LED, LOW); Serial.println (F ("Tick")); delay (500); digitalWrite (LED, HIGH); Serial.println (F ("Tack")); delay (500); }
In the "Tools" menu you can activate debug messages. To do this, the program must be recompiled and uploaded. You have to open the serial port yourself, as in the example above (with Serial.begin). If the option "WiFi" has been selected in the "Debug Level", you will receive messages about the connection to the WiFi network.

The unusual baud rate 74880 is advantageous for debugging because the bootloader also outputs messages with 74880 baud before the program starts. You can then read them too.

UDP server

The second sketch receives UDP messages and sends them back as an echo:
#include #include // The ESP-12 has a blue LED on GPIO2 #define LED 2 // Name and password of the WLAN access point #define SSID "Pussycat" #define PASSWORD " supersecret "// The server accepts connections on this port #define PORT 5444 WiFiUDP udpServer; // Buffer for incoming UDP messages char udp_buffer [WIFICLIENT_MAX_PACKET_SIZE + 1]; / ** Receive UDP messages and send an echo back * / void process_incoming_udp () {if (udpServer.parsePacket ()) {// Fetch received message int len ​​= udpServer.read (udp_buffer, sizeof (udp_buffer) -1); udp_buffer [len] = 0; // Display the message Serial.print (F ("Received from")); Serial.print (udpServer.remoteIP ()); Serial.print (":"); Serial.print (udpServer.remotePort ()); Serial.print (":"); Serial.println (udp_buffer); // Send echo back udpServer.beginPacket (udpServer.remoteIP (), udpServer.remotePort ()); udpServer.print (F ("Echo:")); udpServer.print (udp_buffer); udpServer.endPacket (); // Execute some commands if (strstr (udp_buffer, "on")) {digitalWrite (LED, LOW); udpServer.println (F ("LED is on")); } else if (strstr (udp_buffer, "off")) {digitalWrite (LED, HIGH); udpServer.println (F ("LED is off")); }}} / ** Optional: Notify about AP connection status changes * / void check_ap_connection () {static wl_status_t preStatus = WL_DISCONNECTED; wl_status_t newStatus = WiFi.status (); if (newStatus! = preStatus) {if (newStatus == WL_CONNECTED) {digitalWrite (LED, LOW); // Display the own IP address and port Serial.print (F ("AP connection established, listening on")); Serial.print (WiFi.localIP ()); Serial.print (":"); Serial.println (PORT); } else {digitalWrite (LED, HIGH); Serial.println (F ("AP connection lost")); } preStatus = newStatus; }} / ** Runs once at startup * / void setup () {// LED off pinMode (LED, OUTPUT); digitalWrite (LED, HIGH); // Initialize the serial port Serial.begin (115200); // Give the serial monitor of the Arduino IDE time to start delay (500); // Use an external AP WiFi.mode (WIFI_STA); WiFi.begin (SSID, PASSWORD); // Start the UDP server udpServer.begin (PORT); } / ** Main loop, executed repeatedly * / void loop () {process_incoming_udp (); check_ap_connection (); }
When the connection to the AP has been established, the blue LED lights up. The program outputs helpful status messages on the serial port. This is how you can test the server with Netcat:
nc -u 192.168.0.111 5444Monkey see monkey do Echo: Monkey see monkey do off Echo: off LED is off on Echo: on LED is on
The UDP service is easy to program because you can rely on the fact that messages will arrive 1: 1 as they were sent, i.e. neither fragmented nor put together. In addition, you don't need to worry about establishing the connection. The main disadvantage is that UDP messages are sometimes lost unnoticed - especially in wireless networks. In rare cases, packets that follow one another quickly reach their recipient in a different order.

TCP server

The third sketch shows a TCP server that serves several connections at the same time:
#include // The ESP-12 has a blue LED on GPIO2 #define LED 2 // Name and password of the WLAN access point #define SSID "Pussycat" #define PASSWORD "supersecret" // The server accepts connections on this port #define PORT 5333 WiFiServer tcpServer (PORT); // Objects for connections #define MAX_TCP_CONNECTIONS 5 WiFiClient clients [MAX_TCP_CONNECTIONS]; // Buffer for incoming text char tcp_buffer [MAX_TCP_CONNECTIONS] [30]; / ** * Collect lines of text. * Call this function repeatedly until it returns true, which indicates * that you now have a line of text in the buffer. If the line does not fit * (buffer to small), it will be truncated. * * @param source The source stream. * @param buffer Target buffer, must contain '\ 0' initially before calling this function. * @param bufSize Size of the target buffer. * @param terminator The last character that shall be read, usually '\ n'. * @return True if the terminating character was received. * / bool append_until (Stream & source, char * buffer, int bufSize, char terminator) {int data = source.read (); if (data> = 0) {int len ​​= static_cast (strlen (buffer)); do {if (len (data); } if (data == terminator) {buffer [len] = '\ 0'; return true; } data = source.read (); } while (data> = 0); buffer [len] = '\ 0'; } return false; } / ** Optional: Notify about AP connection status changes * / void check_ap_connection () {static wl_status_t preStatus = WL_DISCONNECTED; wl_status_t newStatus = WiFi.status (); if (newStatus! = preStatus) {if (newStatus == WL_CONNECTED) {digitalWrite (LED, LOW); // Display the own IP address and port Serial.print (F ("AP connection established, listening on")); Serial.print (WiFi.localIP ()); Serial.print (":"); Serial.println (PORT); } else {digitalWrite (LED, HIGH); Serial.println (F ("AP connection lost")); } preStatus = newStatus; }} / ** * Put new connections into the array and * send a welcome message. * / void handle_new_connections () {WiFiClient client = tcpServer.available (); if (client) {Serial.print (F ("New connection from")); Serial.println (client.remoteIP (). ToString ()); // Find a freee space in the array for (int i = 0; i = MAX_TCP_CONNECTIONS) {i = 0; }} / ** Executes once during start * / void setup () {// LED off pinMode (LED, OUTPUT); digitalWrite (LED, HIGH); // Initialize the serial port Serial.begin (115200); // Give the serial monitor of the Arduino IDE time to start delay (500); // Use an external AP WiFi.mode (WIFI_STA); WiFi.begin (SSID, PASSWORD); // Start the TCP server tcpServer.begin (); } / ** Main loop, executed repeatedly * / void loop () {handle_new_connections (); process_incoming_tcp (); check_ap_connection (); }
When the connection to the AP has been established, the blue LED lights up. The program outputs helpful status messages on the serial port. This is how you can test the application with Netcat:
nc 192.168.0.111 5333 Hello World! I am Groot Echo: I am Groot off Echo: off LED is off on Echo: on LED is on
With TCP, in contrast to UDP, you can be absolutely certain that no messages will be lost within a connection and that the order will not get mixed up. But a line of text may arrive broken up in several segments, even if it is short. Or a segment provides two lines of text that were originally sent individually.

That's why I developed the append_until () function that collects input line by line regardless of segmentation. In contrast to Arduino's readStringUntil () it has the following advantages:

  • It does not block the program flow while it waits for the end of the line.
  • It does without strings that provoke heap fragmentation.
  • It never returns more characters than fit in the buffer / memory.

WiFi Config Service

In the above examples, the access parameters for the WLAN access point were simply written into the source code. However, this approach is unsuitable for non-developers. WPS was actually invented for this purpose, but it didn't work so often for me (also on other devices) that I no longer use it.

An obvious alternative would be to create a provisional WLAN network and provide a website for configuration there. My little WiFi monitor project contains the ConfigService class, which does exactly that. The following shortened source code shows you how easy it is to use the WiFi Config Service:

#include "ConfigService.h" ConfigService configService (80); void setup () {configService.begin (5, "WiFi Monitor", ""); ...} void loop () {configService.run (); ...}
After switching on the power supply, the program activates a temporary network with the name "WiFi Monitor" without a password for 5 minutes. You can connect your computer or smartphone to this network and then go to http://192.168.4.1:

There you enter the access data for your access point (e.g. Fritz Box). If they are correct, the module will immediately establish a connection to this device. The main program in this sample project tests the accessibility of the configured web server and shows the status by means of a colored LED.

Temporarily switch off WLAN

Without WLAN, the chip consumes 10-15 mA of current. The analog input works much better in this state. In order to temporarily switch off the WLAN interface, the wake-up timer must be included:
ESP.deepSleep (1, WAKE_RF_DISABLED); delay (100);
The microcontroller goes to sleep for a very short time and restarts with deactivated WLAN.

How to reactivate the interface:

ESP.deepSleep (1, WAKE_RFCAL); delay (100);
The timer output GPIO16 must be connected to the RESET input as follows:

This will delay and lengthen the reset signal a bit. Take a look at the circuit diagram of your board! At least some of these components are likely already in place.

Pitfalls

It is important that the firmware gets enough computing time, otherwise the module will fail. All own program parts must pass control to the firmware after 50 ms at the latest (20 ms are recommended) by either sending the loop () Exit function or function delay (ms) or yield () call.

Only about a 4 kbyte stack is available for your own programs. If local variables take up more space in procedures, the program crashes. Larger amounts of data (e.g. buffers for data) should therefore preferably be declared globally so that they are outside the stack.

Remember that string objects and strings are usually in RAM. Here is a description of how to store them in flash memory instead to save RAM.

Dynamic memory management on the heap requires special care so that the heap is not fragmented. Once your own code the keywords delete or free () the long-term stability of the application should be checked carefully. I also strongly advise avoiding string objects because they make extensive use of them. More about it here.

When you send data, everyone becomes Client :: print () and Client :: write () Call up a single Ethernet packet. Many small packets reduce the performance because they take just as long as large packets. However, if you send too much data in one call, the firmware automatically divides it into several packets and, if necessary, even waits for space in the send buffer to be free.

  • lwIp 1.4: The maximum packet size is in WIFICLIENT_MAX_PACKET_SIZE and is 1460 bytes
  • lwIp 2.0: The maximum packet size is in TCP_MSS and is 536 or 1460 bytes depending on the board configuration

Since the receive buffer can hold several packets, you have to assume when programming that Client :: available () and Client :: readBytes () return a few kilobytes at a time, especially if the data arrives in quick succession. Therefore, when reading out the data, be careful not to overload your buffers or the stack.

Use the methods readString () and readStringUntil () preferably not at all, because they accumulate strings of any length that can easily cause a memory overflow. It works better with my append_until () function from the example sketch above.

Do not rely on sent TCP messages reaching the recipient in the same segmentation as they were sent. The network components are allowed to split the segments of the TCP data stream and reassemble them. In this discussion, the effects of segmentation were nicely explained.

With the UDP protocol you send and receive packets with the maximum size mentioned above. Under certain circumstances, this can be further restricted by network components (routers, modems, etc.).

Interrupt handler routines MUST work with the macro ICACHE_RAM_ATTR otherwise the microcontroller will crash. Within interrupt routines you must not use a WLAN function, read the ADC or use delay () or yield (). I advise against using interrupts at all, because they often lead to unexpected glitches.

It is recommended to post ESP.deepSleep () always one delay (100) insert so that falling asleep works reliably.

Every time the parameters of the WLAN connection are changed, there is write access to the flash memory. The settings are automatically saved and used again the next time you start. This affects the functions:

  • WiFi.begin (ssid, password)
  • WiFi.disconnect ()
  • WiFi.softAP (ssid, password, channel)
  • WiFi.softAPdisconnect ()
If these functions are called very often alternately or with different parameters, the flash memory can break prematurely. With WiFi.persistent (false) automatic saving is prevented. The password must be either an empty string ("") or at least 8 characters.

Use other IDE as a better text editor

Arduino's text editor is tight, to say the least. Other development environments are much more comfortable. They recognize many errors as they are being typed and help typing by displaying suggestions. For example, if you say "Serial." a good IDE will list all fields and methods of the Serial class. If you hold down the Ctrl key and then click on a #include file, a class name or a method name, the associated file opens and the cursor jumps to the corresponding line.

I have had good experiences with both Netbeans and Qt-Creator. I like Qt-Creator better because it analyzes the source text as you type and points out possible errors.

In the following paragraphs I have the installation directory of the Arduino IDE with <arduino> abbreviated. The <packages> The directory where the extensions are installed is usually in the personal folder:

  • Windows: C: \ Users \ stefan \ AppData \ Local \ Arduino15 \ packages
  • Linux: / home / stefan / .arduino15 / packages

In the case of a portable installation, however, the packages are located in the / portable directory.

Go to the File / Preferences menu in the Arduino IDE and activate the "Use external editor" option.

Qt creator

Qt Creator is a free IDE for C / C ++ projects with special features for the Qt framework. I particularly recommend the built-in source code analysis, because it helps a lot to avoid errors while editing. Qt Creator is available for Linux, Windows and macOS. The IDE is written in C ++ and therefore runs smoothly on any computer.

Use the installer from the Qt SDK to install the Qt Creator program. You don't need the optional components. Start the program and then go to the menu Extras / Settings / Kits / Compiler. There you have to add the C compiler and the C ++ compiler from the ESP8266 extension for Arduino as type "MinGW" (under Windows) or "GCC" (under Linux). For me it looks like this under Linux:

The C compiler is called xtensa-lx106-elf-gcc, and the C ++ compiler is called xtensa-lx106-elf-cpp. Both are somewhere in the directory. Qt-Creator uses these two commands to find the standard C libraries automatically.

At the bottom of the "ABI" line you don't need to change anything, just use the default values ​​there, even if they look different for you. Then go to the "Kits" tab and create a new kit with the compilers you just created:

The CMAKE configuration doesn't matter, just leave it unchanged.

Then you can import the Arduino project via the menu "File / New / Import project / Import an existing project". Then enter all files in the "ProjektName.files" file that you want to edit with Qt-Creator - i.e. the * .ino, * .h and * .cpp files.

In the "ProjectName.includes" file you specify all directories where the header files of the C libraries are to be searched for. For example:

/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include /esp8266/hardware/esp8266/2.3.0/cores/esp8266 /esp8266/hardware/esp8266/2.3.0/variants/generic /esp8266/hardware/esp8266/2.3.0/tools/sdk/include /esp8266/hardware/esp8266/2.3.0/ libraries / ESP8266WiFi / src /esp8266/hardware/esp8266/2.3.0/libraries/EEPROM /esp8266/hardware/esp8266/2.3.0/libraries/Wire /esp8266/hardware/esp8266/2.3 .0 / libraries / SPI

In the "ProjektName.config" file you enter the version 1.8.13 of your Arduino IDE:

Now you can edit your sketch with Qt-Creator. To check (compile) and upload it you still have to use the Arduino IDE.

NetBeans

NetBeans requires a Java Development Kit because the IDE was programmed in Java. It was primarily intended for Java applications, but also has a good C / C ++ editor as a plug-in.

After installing the plugin, go to the Tools / Options / Miscellaneous / Files menu. Select the file extension C ++. Then click on the "New ..." button and add the ending "ino". Then NetBeans recognizes the * .ino files as C ++ source text.

Go to the Tools / Options / C / C ++ / Build Tools menu. Add a new "Tool Collection" with the base directory / tools / xtensa-lx106-elf-gcc. Below that, the "Tool Collection Family" must be set to "GNU MinGW" (under Windows) or "GNU" (under Linux). The name for the new tool collection should be "ESP8266".

The C compiler is called xtensa-lx106-elf-gcc, and the C ++ compiler is called xtensa-lx106-elf-cpp. Both are somewhere in the directory. The other program fields below may remain empty:

Then switch to the "Code Assistance" tab. Select "ESP8266" under "Tool Collection" and then add all directories under "Include Directories" in the C ++ Compiler, where the header files of the C libraries are to be searched for. For example:

  • /esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include
  • /esp8266/hardware/esp8266/2.3.0/cores/esp8266
  • /esp8266/hardware/esp8266/2.3.0/variants/generic
  • /esp8266/hardware/esp8266/2.3.0/tools/sdk/include
  • /esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src
  • /esp8266/hardware/esp8266/2.3.0/libraries/EEPROM
  • /esp8266/hardware/esp8266/2.3.0/libraries/Wire
  • /esp8266/hardware/esp8266/2.3.0/libraries/SPI
Below you add a "Macro Definition" with the value "ARDUINO = 010813", this is the version number 1.8.13 of your Arduino IDE.

Create an empty file with the name "Makefile" in your Arduino project directory (where the * .ino file is located) (pay attention to the upper / lower case). Then go to the menu item File / New Project in NetBeans. Select "C / C ++ with Existing Sources" as the project type. In the next dialog you enter the project directory and the tool collection is "ESP8266". The option "Use Build Analyzer" should be switched off.

Now you can edit your sketch with Netbeans. To check (compile) and upload it you still have to use the Arduino IDE. You may want to take a look at these instructions, where the use of the editor is explained.

Sometimes all of the advanced editor functions do not work with individual files. Then right-click the file name in the project view and click Properties. In the following dialog you have to activate the option "Add To Parse", then it will work.

Visual Studio Code

Visual Studio Code (VSCode) is a free development environment from Microsoft. It is included as an optional package in many Linux distributions. The Arduino extension for Visual Studio Code requires an installed Arduino IDE.
  • Install the Arduino IDE and Visual Studio Code. Start Visual Studio Code.
  • Click the gear in the lower left corner, then click Extensions. Find the Arduino extension from Microsoft there and install it.
  • Click on the gear next to the name of the installed Arduino extension to get to its settings.
    • Under "Arduino: Path" you have to specify the directory in which the Arduino IDE was installed. For example "/opt/arduino-1.8.13".
    • At the top under "Arduino: Additional URLs" click on the link "edit settings.json". A text editor opens in which you should add the following line:
    • "arduino.additionalUrls": ["http://arduino.esp8266.com/stable/package_esp8266com_index.json"],
    • You have to restart the IDE afterwards.
  • Then you can open your project directory (where the * .ino file is located).
  • The IDE will then ask you to install various additional extensions.
  • Open the "Command Palette" view in the main menu and execute the "Arduino: Board Config" command.
  • There you set up your board and which (virtual) serial port it is connected to. These settings are saved in your project directory in the file "DeinProjekt / .vscode / arduino.json".
  • You may have to correct a few values ​​in the "DeinProjekt / .vscode / c_cpp_properties.json" file:
    • "intelliSenseMode": "gcc-x86",
    • "compilerPath": "/hdd/opt/arduino-1.8.13/hardware/tools/avr/bin/avr-gcc",
    • "cStandard": "gnu11",
    • "cppStandard": "gnu ++ 11"
  • In the top right corner of the IDE, the Arduino extension has added two new buttons:
    • Arduino: Upload compiles the program and uploads it to the board
    • Arduino: Verify compiles the program
  • In addition, the IDE shows a few Arduino-specific settings in the status bar, for example "Select Programmer" and "Select Serial Port" and the serial monitor (as a symbol with a plug).
See also this YouTube video.

criticism

The ESP82xx chip can only be used with the manufacturer's firmware, as many important hardware details are kept secret. Large parts of the firmware are only published in binary form without source code. Every application is therefore inevitably exposed to the peculiarities of this firmware - including Arduino and NodeMCU.

The manufacturer released its SDK early when it was still very unstable. Nevertheless, it met with great interest. The SDK version 1.5.3 (and the Arduino Core 2.3.0 based on it) were the first versions that you could seriously rely on. Immediately afterwards, the project was restructured several times and a featuritis broke out that had had a negative effect on the software quality for several years.

For a long time Espressif advertised its chip as "particularly economical" with incorrect numbers. In fact, its power consumption is even slightly higher than that of the Silabs AWM136 and Texas Instruments CC3120, to name just two alternatives. In general, WLAN is quite energy-consuming, it was never intended to save electricity.

The data sheet names some features (e.g. I²C, PWM, IR Remote) that the chip does not actually have. In the "small print" it says that you can "implement" this in software.

For pin 7 CHIP_EN (which has been renamed several times), the manufacturer hides in its documentation that this input only works properly after the firmware has been started.

A suspected flaw in the design of the chip causes it to hang up when waking up from deep sleep mode. Therefore the timer output must be connected to the reset input, which causes a complete restart of the firmware with loss of the data in the RAM.

After a program error (e.g. stack overflow) the chip sometimes blocks. The watchdog does not always serve its purpose here. If the chip hangs, it no longer reacts to the CHIP_EN input. But the reset input reliably fulfills its purpose. With an error-free program and the software versions mentioned above, however, it will run reliably.

The ADC input is only good as a rough estimate because it does not work linearly and can be disturbed by the RF interface.According to a very well hidden information in the data sheet, deviations of up to 20% are possible!

The RTC runs so imprecisely in deep sleep mode that it is practically unusable. So I don't care about the lack of support in the Arduino framework.

Since the CPU is busy with the WLAN interface at irregular intervals, it is impossible for software to generate signals with exact timings. This manifests itself, for example, in visible flickering in PWM dimmed lamps. For the popular Neopixel (WS2812 and similar) you have to abuse the serial interface or I²S with DMA in order to generate sufficiently accurate signals.

For hobby projects, ESP modules are still interesting, especially because of the unbeatable price.