This article is about using and programming a Wireless Module for IoT – ESP8266 for enhancing sensors (whether Temperature, Motion, Smoke etc) to send their telemetry data for aggregation and analysis for Internet of Things applications. One of the most widely available module/circuit for making a standard Hardware sensor talk over a network (or Internet) with a server is the Arduino based (or compatible) series of WiFi modules. So, let us go through the details about ESP8266 and its software, schematics, SDK, etc which will help you in understanding and actually developing a WiFi based embedded system.
As the number of sensors grow and spread over a bigger geographical area, it becomes more difficult and expensive to draw and maintain physical wires to/from each of them for monitoring. (By the way, the same holds true for Actuators too). So, learning how to program, use and interface a Wireless sensor with your hardware becomes key to a success for project deployment, management and usability.
Furthermore, with ESP8266 it has become extremely easy to integrate any sensor with WiFi these days and there are various applications that can benefit from wireless connectivity, for example:
One can connect to an ESP8266 through its serial interface pins, and then of course via Wifi, through a Light Weight IP stack. In addition, to communicate with sensors, one can make use of I2C or SPI bus capabilities of the GPIO pins.
There are WiFi solutions based on the IC ESP8266 designed for the needs of a new connected world. Each wireless module is a self-contained WiFi based networking solution. ESP8266 has on-board processing and storage capabilities as well as GPIOs to integrate with other electronics like sensors (and actuators). A basic pin-out of the ESP8266 is given in the figure below:
VCC: 3.3 Volt, GND: Ground
CH_PD: Chip Enable, RST: Chip Reset (For both of them use 10K PULL-UP resistor to VCC)
TX: The serial-data transmit, RX: The serial-data receive (Connect to RX/TX Serial or USB-Serial FTDI converter)
GPIO-0/2: General purpose I/O pins (with GPIO-0 to control flashing a new firmware program)
A general schematic can be found here or advanced auto-reset scheme here.
The circuits packages are available in various form-factors and as SMD packages or normal circuit boards with varying amounts of memory (flash) from 0.5MB to 4MB or more. The wireless standards supported are usually the 802.11b/g/n type in this series of wireless modules.
The ESP wireless module can be programmed (for example with the Arduino IDE or the supplied tool-chain) and a C/C++ program etc can write/read from the socket API just like a normal Linux application. There is a Serial Interface is the used for writing to the ESP flash and once the image (or Sketch) is programmed, the ESP will boot and run the updated firmware (the embedded software). Caution: Programming your custom firmware program will delete/overwrite the manufacturer AT firmware and/or other functionality.
There are several way to program your device:
When The Firmware version of the Wireless module is printed on the Serial console when we boot the device. For example, you may get something like following:
2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000
Or, you can execute: AT+GMR and should see something like:
AT version:220.127.116.11(Jul 1 2016 20:04:45)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
The following information I get about the ESP device (REES52) that I used is necessary to re-image or update the firmware.
Flash size: 8Mbit: 512KB+512KB
Firmware update binaries from the OEM and address vectors for installation:
esp_init_data_default.bin 0xfc000 (optional)
blank.bin 0x7e000 & 0xfe000
The ESP hardware (depending on the brand) usually comes with a default firmware which is usually enough to setup the WiFi without changing the flash image. With the USB-to-Serial TTY (or a direct Serial connection) various commands like the following can be executed:
Here is one cool Instructable on using AT commands with ESP device.
The general APIs provided in the Arduino libraries/IDE are digitalRead(), digitalWrite(), analogRead(), analogWrite() for creating a custom program that uses the general purpose I/O pins for its particular use-case. Remember, when you flash the ESP with a custom program (or firmware) the default firmware would be erased (over-written) which also means that the AT command-set of the ESP8266 would not be available (unless you re-flash the original or similar firmware again).
That brand that I used (REES52) has the chip/SDK version from AI Thinker based on original firmware/SoC from Espressif (The AT command-set from Espressif does not have ability to read/write GPIO from the default firmware image)
Links to some useful tutorials:
The ESP wireless module comes integrated with TCP/IP protocol stack for communication over a network and it becomes extremely simple for any Hardware to send/receive wireless data and connect to the network or the cloud server. A socket/connect is a standard interface, and the ESP can also be programmed to communicate via HTTP and other higher layer protocols based on the server and IoT application architecture and requirements. Here are a few practical examples and libraries:
There is a new module based on STM32F4 ARM Coretex M4 microcontroller called the EMW3165, which we shall explore in a different write-up separate from this one concentrating on ESP8266.
And finally, feel free to comment about your progress with ESP based wireless module and if this article was insightful. I plan to add more details in the same page, so you can bookmark, subscribe, comment and share this page. Enjoy making your new or existing hardware-solution wireless!
Copyright 2018 Fitness WordPress Theme