ESP8266 ESP-01 and IoT of LED — Part 1

Mudassar Tamboli
6 min readJul 2, 2018

--

Series : Part 1, Part 2 , Part 3, Part 4

Introduction

This topic demonstrates how to use ESP8266 ESP-01 Wifi module with simple LED and interact with the client apps. The LED is particularly used here as it is very easy to interface and visibily clear when it is switched on and off. Hence keeping the ESP8266’s output hardware as simple as LED we can concentrate on the working of ESP8266.

What is ESP8266 ?

ESP8266 is a low cost Wifi microchip and microcontroller with a full TCP/IP stack. Now what does this mean? It means that it can be programmed to connect to internet and control and monitor devices anywhere in the world via PC, mobile or microntroller itself using the internet. If the internet is not available it can create its own mesh of network via Soft Access Points and collect information and control and monitor devices.

ESP8266 ESP-01 Pinout

Recently i bought ESP8266 ESP-01 module from Amazon for $5.

ESP8266 ESP-01

It has just 8 pins, out of which only 2 pins are GPIO, 2 pins are RX/TX, 1 VCC, 1 GND, 1 Reset and 1 CH_PD (Chip Enable). The limited 2 GPIO pins can be used to trigger DC Relay for example. But, generally, a microcontroller has many peripherals through SPI, I2C, Serial, ADC etc. ESP8266 ESP-01 has none of these except Serial RX/TX. However, it can be connected to like Arduino UNO via Serial UART and communicate commands via RX/TX.

Programmer for ESP8266 ESP-01

I used CP2102 USB to TTL converter to program ESP 01. See the picture below.

CP2102 USB to TTL Converter

Preparing the Arduino IDE for ESP8266 ESP 01

Configure Arduino IDE with ESP8266 board packages.

Arduino IDE setup installs with default packages for common Arduino boards like UNO, Mega, Nano, Pro Mini etc. Hence it is readily available in the IDE’s Menu->Tools list. But ESP8266 board package need to be added manually through Menu->Tools->Board: <Current Board> ->Boards Manager …

But before that, you must provide ESP8266 repository URL to IDE via

Menu->File->Preferences->Settings->Additional Boards Manager URLs:

Paste the following link in the text box : http://arduino.esp8266.com/stable/package_esp8266com_index.json

Arduino IDE — ESP8266 package URL
Arduino IDE — Board Manager

Search for esp8266 by ESP8266 community and install it.

After successfull installation, choose the board as Generic esp8266 module as below

Choose ESP8266 Module for ESP-01 microchip

Preparing PCB board for ESP8266 ESP 01

ESP8266 ESP-01 needs to powered and its pins appropriately connected before programming it through IDE. We also need an LED connected to GPIO pin for demo purpose. Bread board helps, but, male and female pin fittings, entangling wires, risk of loose connections due to movement wastes lot of time in debugging and reconnecting the wires. Making a soldered PCB connection makes the board more rugged and one time solution and i can easily and carelessly move my board around :).

ESP-01 to CP2102 Schematic

The schematic shows the connection between the ESP-01 and CP2012 USB TTL programmer. There are some points that should be followed when programming ESP-01.

  1. ESP 01 should be powered by 3.3v. Here CP2102 provides 3.3v.
  2. G0 should be grounded during programming. I have used 1K pullup resistor to ground G0. Also i have jumper to short 1K to ground during programming.
  3. G2 is connected to LED but is left open during programming. J2 is a jumper and is short when not programming.

4. CH_PD should be enabled by connecting to VCC. I have used 1K resistor between VCC and CH_PD.

PCB board for ESP-01

Heres the PCB board designed as per the above schematic that makes my life a lot easy :)

Programming ESP8266 ESP-01 through Arduino IDE

The ESP-01 is factory programmed with a TCP/IP firmware that accepts AT commands. On powering the device you should see the Wifi access point provided by the ESP-01 device in your Window Wifi list as below.

ESP Access Point listed in Windows 10

If you program your ESP device with your code in Arduino, the default factory set firmware will be over written with the new firmware. The factory firmware can be reset to its original by programming it with the binary available online. I am providing a snapshot of the programming software and list of AT firmware file downloaded from online repo. Flashing “V2.0 At Firmware(ESP).bin” brings back my ESP device to factory default. esp8266_flasher.exe is used to flash the firmware.

We are now all set to program our first Hello World program.

Hello Led !

Lets write a small program that would blink the Led. This is a C program using the Arduino environment and libraries.

GPIO2 is connected to an LED through a current limiting resistor.

In the above code GPIO2 is first set to output mode and set HIGH and LOW at interval of 1 second in a loop.

Programming the “Led Blink” firmware

In the above config “Generic ESP8266 Module” board is selected for ESP-01 The varying COM port is selected depending on the system.

ESP8266 ESP-01 Flash Successfull

You should see the above screen on successful flash.

Troubleshooting

Flash Failed

The above error shows that IDE failed to flash the firmware. In order to resolve it, check the following before starting to program.

  1. The GPIO0 should be grounded. I short it via J1 jumper.
  2. Check that the USB programmer’s COM port is selected.
  3. Pull out the USB programmer and re-insert it again.(This may not be required all the time.)
  4. I disconnect GPIO2/LED from ground by removing J2 while programming.

Conclusion

In this article we discussed about the ESP8266 hardware, Pin connections, USB programmer(CP2012), Arduino IDE setup, led blinking program and how to flash firmware and troubleshoot firmware programming issues.

In the next article we will see the Server/Client programming of the ESP8266- 01 and how to control the LED. We are now all set to implement the comprehensive software part of IoT.

Series : Part 1, Part 2 , Part 3, Part 4

--

--

Mudassar Tamboli

AWS Certified Solutions Architect, IoT enthusiast, Entrepreneurial Thinker, Polyglot programmer