Using the Microcontroller ESP8266 for automation tasks for the IoT

Andrei Krauchuk, 123RF.com

The Mighty Micro

The ESP8266 Wifi chip can be used for measurement applications wherever the capabilities of the Raspberry Pi are woefully underutilized. In sleep mode, this microcontroller uses less than 3.3 milliwatts and costs only 6 Euro.

The first encounter with the an upstart microcontroller like the ESP8266 can be jarring for genuine Raspberry Pi Geeks. Firstly, the microcontroller does not have its own operating system and it can only be programmed in C or Assembly language.It also has no ports for a keyboard, mouse and monitor. So, in terms of the Raspberry Pi, what does the ESP8266 bring to the team?

As it turns out, the greatest strengths of the ESP8266 lie in its limitations. It can be used for many applications for which the Raspberry Pi would be overkill, for example, measuring temperatures. The performance capabilities of the Pi far outstrip this simple task and buying one for such a menial task wouldn't be cost-effective. The ESP8266 on the other hand costs less than 6 Euro [1].

The meager power consumption of the small microcontroller is also an appealing feature. A Pi pulls 3.5 Watts during operation while the ESP8266 needs a maximum of 0.5. In sleep mode, this is reduced to less than 3.3 Milliwatts making the component ideal for use with a battery. As a result, it works even in places where there is no mains power.

ESP8266-12 Specs

  • 32-Bit-RISC-CPU Tensilica Xtensa LX106 (80 MHz clock rate)
  • 64 KB RAM for Program Code, 96 KByte Data-RAM
  • External QSPI-Flash (512 KB to 4 MB)
  • WiFi IEEE 802.11b/g/n (WPA/WPA2), +19,5 dBm output performance (802.11b)
  • WiFi Direct (P2P), Soft-Access-Point, integrated Antenna
  • Integrated TCP/IP protocol stack
  • Integrated TR-Switch, Balun, LNA, End stage and Antenna Tuner
  • Power loss (Power Down) less than 10 Microamperes
  • 10 GPIO-Pins, SPI, I2C
  • I2S-Interface with DMA (Sharing-Pins with GPIO)
  • UART: URXD/UTXD
  • 10-Bit-ADC
  • Wakeup and Packet transmission in under 2 Milliseconds
  • Standby power consumption less than 1,0 Milliampere
  • Size 17.2 x 12.3 Millimeter

Family Ties

In truth, here is no such thing as an ESP8266. The ESP8266-12 which we will be discussing and which users like to refer to as the ESP-12 or 12E, belongs to an entire family of microcontrollers which share a common name as well as two key features: they all come with WiFi and an integrated GPIO interface.

These components have an excellent price to performance ratio and offer more computing power than most of the other microcontrollers on the market. Some of the brands imported from the Far East can be bought for around 3 Euro, making them very interesting to hobbyists. Approach the less expensive offerings from eBay and other online merchants cautiously. Delivery from China to Europe can take weeks.

The diverse range ofESP8266 versions is reminiscent of the Arduino microntroller family. What then is the difference between an ESP8266 and an Arduino board? In brief, the ESP8266 offers more processor power and more memory for your money. It also has a WiFi interface. Depending on the model, Arduinos may have many more I/O pins. On the other hand, you can connect additional I/Os to the ESP8266 via the I2C- or SPI-Bus.

In summary, it is definitely worth your time to take a look at the ESP8266. You will undoubtedly find a wide variety of applications for this component in your future projects.

Development Environment

There is more than one way to write programs for the ESP8266. In the following sections of this article, we take a look at the more straightforward and convenient possibilities. To start with, you should download and install the development environment from the Arduino homepage [1] onto a desktop computer (Figure 1). The software is available for Linux, Mac OS X and Windows.

Figure 1: The download area on the Arduino Homepage.

When operating a Linux computer, you should make sure to select the version that is suitable for the operating system (32/64 bit). The command from the first line of Listing 1 decompresses the archive under all current distributions. Next you should start the Arduino IDE from the command line by switching to the directory containing the extracted data. Once in the directory, enter ./arduino (Listing 1, Lines 3 and 4).

Listing 1

arduino-1.6.7-linux64.tar.xz

$ tar xf arduino-1.6.7-linux64.tar.xz
$ cd arduino-1.6.7/
$ ./arduino

After starting the development environment enter the following URL under File | Preferences | Additional Boards Manager URLs (Figure 2):

Figure 2: Adding an additional board manager.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

This is how you get the Arduino IDE to incorporate the board manager needed for the ESP8266 into the corresponding list. Next, start installing the board manager for the ESP8266 by selecting the menu option tools | Board | start board manager. Figure 3 shows the dialog for installing this. Once installation is complete, you can select the Generic ESP Module under tools | Board.

Figure 3: Installing the board manager.

Now the Arduino development environment can be used to create programs for the ESP8266 chip. You will need to grant rights to the current user for accessing the serial interface (Listing 2). To do this, add the user to the dialout group.

Listing 2

Adding your user to dialout

$ sudo usermod -a -G dialout $USER
$ sudo reboot

Either log in and out to apply changes or reboot your machine.

The IDE installation concludes the preparations on the software side for use of the ESP8266. Now it is time to set up the hardware.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content