Programming the esp8266 module

Air quality monitor binary code

Pre-built binary images of our air quality monitor are available that can be written to the esp8266 module flash storage using the Esptool on Linux or Windows or MacOS. Please download the binary image file to program the firmware:

  1. ESP8266 Nodemcu board firmware version 0.1.1
  2. ESP8266 Nodemcu board firmware version 0.1.2
  3. ESP8266 Nodemcu board firmware version 0.1.3

Installing Esptool

The modules used in the air quality monitor can be programmed using the Esptool ESP8266 and ESP32 serial bootloader utility.

There are two approaches to installing this on Windows:

  1. The maker of the esp8266 offer a bundled Esptool for windows which works without firstly installing Python as it bundles it into an exe file. There is also a bundled Esptool for MacOS but I have not test that path. This would likely suit people just wanting to program the module.
  2. The installation instructions on the Esptool page note that it needs Python installed which can be installed from Python Downloads and after Python is installed the Esptool can be installed via the following command and this approach would suit people who already use Python:
    pip install esptool

Device drivers

Windows 10 automatically downloaded the appropriate drivers when these devices were connected to my PC USB port – this did take a few minutes so have a little patience on the first connection. The status can be seen under the Windows Settings in the Devices menu and it shows up under Other Devices as either “USB-SERIAL CH340 (COMx)” or “Silicon Labs CP210x USB to UART Bridge (COMx)” after the driver has been installed. There happen to be two different USB serial components widely used in the these boards, hence the difference possible drivers. The “COMx” noted in the device settings might be “COM3” or “COM4” etc and this is the port to use when using the Esptool, and this might change if other USB devices are in use etc.

Writing the program to flash memory

With the binary file downloaded, and the Esptool installed, and the device connected to USB and the driver installed, the esp8266 module is now ready to be programmed. Note replace “COM1” in the examples below with the COM port actually reported by Windows in the settings noted above.

The firmware can be written to the flash using the follow command:

esptool -p COM1 write_flash -fs 32m -fm qio -ff 40m 0 firmware.bin

Erasing the flash memory

If the device has never been programmed with the air quality monitoring software then it is recommended to firstly erase the flash using the following command. Note these devices typically come with something pre-installed to get people started, such as the NodeMCU Lua firmware, and it might be best to firstly erase that. Further the air quality monitoring software uses free areas of the flush to record data, and if it is not erased it can not be used, and it also stores settings in some areas and it might get badly confused if these are not firstly erased. It might also be necessary to erase the flash if you suspect the flash has become corrupted which might be due to some embarrassing software error or due to incompatibilities between versions. You might also wish to erase the flash to clear all the logged data and setting such as wifi passwords.

esptool -p COM1 erase_flash

 

Sidebar