esp-01 with arduino

Posted on

by

in

Program ESP8266 ESP-01 With Arduino

Introduction

This article discusses how we can program the ESP8266 ESP-01 module using the Arduino IDE.

The ESP8266 ESP-01 microcontroller module is a low-cost WIFI Enabled module developed by the Espressif System that has the capability to execute TCP IP Connections. This MCU contains a lot of “punch” for its size and has GPIO ports in itself that you can use to control simple projects and is ideal for Internet of Things (IOT) Applications.

AT Commands and the ESP8266 Arduino library

When you buy this module it comes pre-installed with its own firmware and is able to execute TCP/IP commands thru what we call AT Commands. However, I find these AT commands a little bit “cumbersome” to execute in the code so we will be using an alternative “firmware“.

You will often see the following commands in different tutorials

AT
AT+RST
AT+CWMODE=1
AT+CWLAP
AT+CWJAP="SSID","PASSWORD"
AT+CIFSR

Luckily the ESP8266 community released a companion project for the Arduino as an Add-On and can be found here https://github.com/esp8266/Arduino. We will be using this library in this article.

How to install ESP8266 library in Arduino IDE

We will follow the instructions for this library by following this link.

  1. In your Arduino, click File then Preferences
  2. Add the following https://arduino.esp8266.com/stable/package_esp8266com_index.json to your Additional Board Manager URL. Use a comma if there is another URL there already.
Arduino IDE - Additional Board Manager

3. Open Boards Manager from Tools > Board menu and find esp8266 platform

Arduino IDE - Choose Board
Arduino IDE - Board Manager

4. Click Install

5. After which Select your board as “Generic ESP8266 Module

Arduino IDE - Select Generic ESP8266 Module

Wiring Diagram

One quick solution to load programs in the ESP-01 is to use the ESP-01 programmer which you can source online. We will discuss this in a separate article.

ESP8266 ESP01 Programmer

But in this article, we will be using the Arduino to program our ESP8266 ESP-01 module in this article if you don’t have the programmer above.

Arduino - ESP8266 - ESP-01 Wiring

Understanding Boot Mode

ESP-01 has two modes

  1. Normal Mode
  2. Bootloader Mode

In order to load new firmware then we have to set it in Bootloader Mode. To set it to bootloader CH_PD should be set to HIGH and the GPIO0 connected to GND. That is the reason we have an SPST switch between GPIO0 and the GND.

The same applies also when we want to create our program and load it into the ESP-01 flash memory.

Installing the Arduino ESP8266 Firmware

Once you are done with the wiring, we will just need to replace the firmware with the Arduino ESP8266. Note that once we have changed the firmware then we cannot execute AT commands anymore into the ESP-01.

To load the firmware we just need to upload the Blink Sketch. To do this just click File -> Examples -> Basics -> Blink

Make sure that your Board is set to “Generic ESP8266 Module” and the Toggle Switch connected in GPIO0 is connected to GND.

Click upload and when you see the following message click the momentary switch connected to the RST for about 1 second so that we could reset the ESP-01

Afterward, we would see the following success message.

To see the ESP-01 built-in LED blink then make sure that the toggle button connected to GPI0 is not connected to GND. Click the momentary switch in RST and then check if the LED is blinking.

Troubleshooting

You sometimes will encounter the following problem so it could be that you might not have pressed the reset button enough. When the “connecting” message starts showing then click the momentary switch connected to RST for about a second.

Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "C:\Users\DONSKY\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "C:/Users/DONSKY/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 2890, in main
    esp.connect(args.before)
  File "C:/Users/DONSKY/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
the selected serial port _
 does not exist or your board is not connected

Demo

Watch the following demo on how I did it.

That’s it!

Happy Exploring!

If you like my post then please consider sharing this. Thanks!

10 responses to “Program ESP8266 ESP-01 With Arduino”

  1. Connect Arduino Project to Internet or WIFI Using ESP8266 – donskytech.com

    […] To load the program to the ESP-01 then you should set it to boot mode. If you need more information on how this is done then read how to load program esp-01 with arduino. […]

  2. Designing Arduino RFID Database Security System with ESP8266 ESP-01

    […] We will program the ESP-01 separately from the arduino so that it can retrieve the JSON response coming from our application. If you want to jump in and learn how to program ESP-01 using your Arduino then read the following link. […]

  3. Arduino RFID Database Security System: Program Arduino and ESP8266

    […] the ESP8266 ESP-01 firmware. You can use your arduino to program your ESP8266. I have written an article on how to program your ESP8266 ESP-01 with Arduino if you don’t have an idea about […]

  4. Installing ESP8266 Core to Arduino IDE – donskytech.com

    […] ESP-01 can be done using your Arduino if you have not bought a programmer for it. I have created an article on how to do […]

  5. NodeMCU ESP8266 Web Server Tutorial Series – donskytech.com

    […] The NodeMCU ESP8266 module contains its own usb port that we can use to load our sketch. This will simplify our programming process so that we don’t need to use additional circuitry to load our program. The small but versatile ESP8266 ESP-01 is often used if “space” or “dimension” is your concern. However programming the ESP-01 requires additional circuitry if you have not bought the Programmer for it. I have written a post on how to program your ESP-01 using the Arduino IDE. […]

  6. rick Avatar
    rick

    Hello I want to ask, what if I dont have a switch? Can I just remove the jumper cables instead of pushing the button? If yes, which jumper should I remove? The GPIO0 that is connected to ground or the reset pin of the esp that is also connected to the ground?

  7. luk Avatar
    luk

    are you sure we connect RX to RX and TX to TX (esp arduino) ???
    it’s a bit strange because RX to receive data and TX is transmite.
    so if i want transmit TX data then i need to receive RX on other side ?
    or im wrong?

  8. Carlos Avatar
    Carlos

    Wouldn’t connecting RST directly to ground keep resetting the Arduino?

    1. donsky Avatar
      donsky

      Yes that is correct. Since we are programming the ESP-01 so we do not want the Arduino Uno to run

  9. Using ESP32 SoftwareSerial in your Arduino Projects – donskytech.com

    […] Read Next – Related to this topic: Program ESP8266 ESP-01 With Arduino […]

Leave a Reply

Your email address will not be published. Required fields are marked *