I like the idea of Internet of Things (IoT) which is becoming so popular. We have everything connected to the Internet: TVs, printers, fridges, cars, even teeth brushes, etc. We already have botnets which consist of IoT devices, and are used for massive DDoS attacks. I personally prefer calling it “Internet of Shit” because sometimes it’s not clear why some devices connect to the Internet. By the way, there is a twitter called “Internet of Shit”. I highly recommend to follow.
Using those fancy IoT devices is fun. Furthermore, sometimes such devices are even helpful. But it’s more fun to participate more actively. For example, you can create your own IoT device with blackjack and hookers. God bless those people who developed ESP8266 boards which now allow everybody to build their own IoT devices. As you may know, ESP8266 boards are extremely cheap. And I would say they are relatively easy to use (especially if you know about Google).
I was going to try ESP8266 controllers for long time. Finally, I did it, and want to share my experience in hope it may be useful. I found a lot of articles about ESP8266 and NodeMCU firmware which allows you to run Lua scripts on your ESP8266 board. That’s cool, but the problem is that I don’t know anything about Lua language. Another problem is that I am lazy in this time of year, so I didn’t want to learn Lua. But luckily I know Python a little bit, and there is MicroPython project which allows you to run Python scripts on embedded devices including ESP8266.
Here is a tutorial how to get started with ESP8266 and MicroPython.
If I remember correctly, there are about 12 types of ESP8266 boards. I used ESP-07 board which looks like this:
The easiest way is to buy it on AliExpress or DX. I would recommend to order an adapter place (see above) which makes it much easier to work with the board.
I ordered a couple of ESP8266 boards on AliExpress. I actually ordered them twice from two different sellers, and noticed that GPIO4 and GPIO5 pins may be are exchanged:
Not sure if that’s a mistake in markup. The Internet says it is, but I have not checked that. I just used the one with markup that matched with the markup on the adapter plate.
Here is a circuit I used:
Here you can see ESP8266 ESP-07 board in the center and something else:
`Flash` and `Reset` buttons let you switch your board in a couple of modes. ESP8266 boards has two modes which I know about: bootloader mode and flash startup mode. The bootloader mode allows you to flash your board via UART port (see TXD and RXD pins). The flash startup mode is a usual mode when the board runs it’s firmware after it started.
UART interface – see TXD and RXD pins which connect ESP8266 with PC.
Some other stuff around GPIO pins which I’ll try to explain below.
A voltage regulator based on LM1117T.
As I mentioned earlier, we are going to use two modes: bootloader mode and flash startup mode. The board will be switched to the bootloader mode if you put low level on GPIO0 and GPIO15, high level on GPIO2, and reset the board. It means that you need to hold `Flash` button, press `Reset` button while holding `Flash` button, and finally release `Flash` button.
At first, I found a couple of simpler circuits on the Internet:
No R4 resistor.
GPIO15 connected to `Flash` button.
No R3 resistor, GPIO2 is not used (no high level on this port).
But it didn’t work. I could flash the board (see below how), but when I connected to the flashed board via USB-Serial converter, I couldn’t see Python prompt. I tried to reset the board while connected via terminal, and it printed out some garbage to the terminal. I searched on the Internet, and found that it might mean that the board didn’t switch to flash startup mode, and is still in bootloader mode. Then, I found a note about GPIO2, added R4, made GPIO15 to have low level always, and it worked.
You may notice that REST and GPIO16 pins are connected to C1 and R1. I found this on the Internet, it allows the ESP8266 to reset itself after entering low-power sleep mode. I didn’t get time to read more about it, but added just in case.
I’ll provide all links in the end if you are interested in details.
They provide stable builds more than 512K, daily builds more than 512K, and daily builds less than 512K (just wondering, why they don’t have stable builds less than 512K). You should select the firmware depending on how much flash memory your ESP8266 has. When I ordered my ESP8266, I didn’t pay attention on amount of flash, and now I have only 512K. So, I could use only daily builds which are less than 512K. If you don’t know how much flash your ESP8266 has, just try stable builds which are more than 512K. It’s going to report a error if there is no enough memory.
I used esptool to upload the firmware on ESP8266. You can install it with pip or just clone it from https://github.com/espressif/esptool. I have heard that esptool supports only Python 2, so be careful.
Let’s flash ESP8266. First, it’s better to erase flash on your ESP8266. It can be done with a command like the following:
sudo esptool --port /dev/ttyUSB0 erase_flash
Next, you need to switch it to the bootloader mode (see above). You have to do that each time when you want to flash your board again – it automatically tries to switch to the normal mode after flashing. Here is a command which can be used to upload the firmware:
Oh yes, that’s for Linux. On Windows it may look like a little different. Don’t forget to use correct file name. Finally, you may want to verify flashed firmware with the following command (don’t forget to switch your board to the bootloader mode again):