The IoT Node and its Processor
As already indicated in the introduction an IoT node consists of an Internet-enabled processor with interfaces to external sensor and actuator hardware. On the Internet side connections can be made through
- Ethernet
- WiFi
- or any gateway giving access to the Internet. This can be
- a serial connection to a machine with internet access
- a LoRaWan node connected to a base station (which is connected to the Internet)
- a BlueTooth connection to an Internet enabled processor ...
There are plenty of processors available on the market, many of which are ARM-based devices with a big variety of external interfaces. There are however two extremely popular processor families which we want to have a look into:
- The Raspberry Pi, which is a full blown computer system running a Debian based Linux operating system with all the tools needed to develop software natively. The Raspberry Pi 3 for example features a quad-core 64 bit ARM processor with 1 GByte of RAM and a micro SD card with up to 32 GBytes of storage space. Due to its capabilities, the Raspberry Pi is a rather expensive solution (~ 70 Euros) especially it only a very limited number of sensors or actuators are connected.
- The Arduino. Originally the Arduino used 8-bit AVR processors and is much less powerful than the Raspberry Pi. The most interesting part of the Arduino family is an Integrated Development Environment running on Windows and on Linux machines and featuring a C++ like programming language. The IDE contains a compiler and a flash programmer for the processor used. The IDE has been extended to processors different from the AVR family and can now be used also for ESP8266 or ESP32 processors or for the STM32 family of processors. In all cases however the software is cross-developed and the resulting binaries are loaded into the processor flash.
The standard AVR Arduino does not have an Internet connection but there are piggy back boards, so-called shields, that can be plugged on top of the processor board and Ethernet or WiFi shields are available. Processors like the ESP8266 or the ESP32 have Wifi already available on the processor board. The advantage of the Arduino is its price. It is possible to create an IoT node with one or two sensors or actuators less than 5 Euros.
- There are boards with an Arduino form factor, same size, same connectors as the AVR Arduinos which however are based on a different processor. Typically they use Espressif's ESP8266 or ESP32 processors, 32-bit machines with integrated WiFi and much more flash memory available than the AVR machine. These machines are ideally suited as IoT nodes. In addition to the Arduino type machine, there are also smaller boards to which sensors can easily be attached. These boards can either be programmed with the Arduino IDE or they can run a Lua or micro Python interpreter.
The ESP01
Although the ESP01 is designed as a WiFi interface with which a host processor communicates through AT commands over a serial line, this device features a powerful ESP8266 processor with 8 MBytes of flash which can be programmed. Of course you will loose the AT firmware but you can easily re-install it if needed. One nice feature of the ESP01 is that several sensor boards have been designed onto which you can simply plug this processor card.
... and then there is the price: The whole node, processor, Internet connection and sensor will cost you less than 5 Euros. Here are two examples:
In order to re-program the ESP01 flash it is easiest to use a programmer which you can buy for a mere 85 cents.
You can use this card as a USB to serial converter for your PC allowing you easy communication with the ESP01 serial line. A minor modification to the board is needed however if we want to program its flash.
Here is the ESP01 pinout:
In order to put the ESP01 into programming mode, you must short-circuit GPIO0 to ground when powering the machine. I did this by adding a removable jumper connection to the ESP01 programmer board as shown in this photo:
You can now easily put the ESP01 into programming mode inserting the jumper and into normal running mode when taking the jumper off.
I tried programming the device first erasing all the flash with esptool, which you can find here:
https://github.com/espressif/esptool.
esptool --port /dev/ttyUSB0 --baud 115200 erase_flash
and then to program it with a micro-python interpreter in file microPython-ESP8266.bin
esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect --verify 0 microPython-ESP8266.bin
The micro Python binaries are attached to this page:
https://iotworkshop.africa/pub/AFNOG/TheNopIoTNode/microPython-ESP8266.bin
https://iotworkshop.africa/pub/AFNOG/TheNopIoTNode/microPython-ESP32.bin
Here is a screen dump of the messages sent by esptool.py during flash-erase and programming:
I had to take the programmer out in order to reset the ESP01 after each command I sent with esptool. This was true for erasing but also when getting the chip id with
esptool chip_id or reading the MAC address with esptool read_mac.
When flashing micropython, first insert the jumper at the back of the programmer and insert the programmer into the PC'S USB slot with the ESP01 connected. Erase the flash as seen in the screen dump above. Take the programmer out of the USB socket, wait a few seconds and then plug it in again. Flash the micropython code as shown above. Take the programmer out again and remove the jumper. Plug the programmer with the ESP01 as piggyback in again.
Start minicom or another serial terminal emulator and press return. You should get the Python prompt and you can now happily use the newly installed Python interpreter:
To make things even simpler I wrote a Python script that automates the procedure.
https://iotworkshop.africa/pub/AFNOG/TheNopIoTNode/flashMicroPython
This should work for any of the ESP8266 or EPS32 boards (except the ESP01)
Just type ./flashMicroPython and watch the magic!
Accessing micro Python on the IoT node
--
Uli Raich - 2019-02-12
Comments