Successfully programming ESP-01 / ESP-01S

Has anyone else given up on programming the ESP-01? That was me until last week.

I bought a heap of ESP-01’s a couple of years ago, but after reading hundreds of poorly written “instructions” on programming and trying every programming method I could find (USB/TTL programmer with red board, USB/TTL programmer with big cap and black board, FTDI-UART board (like YP-05 FT232RL adaptor), soldering wires and switches to different pins of these, holding GPIOs to ground on boot, and Arduino UNO / Duemalinove…no method proved easy OR reliable so I eventually gave up and went to play with easy boards like the D1 Mini and ESP32’s.

I recently tried again with an Arduino UNO as the communicator and web.esphome.io for programming (using binaries I’d compiled in ESPHome) and had limited success. I got one (of five) to work, but the other four failed during the “flashing” process or WiFi configuration steps. Two of these would still respond to AT commands but couldn’t be programmed with ESPHome. I eventually worked out the other two kept failing to connect to wifi then rebooted in a loop. I then tried to OTA upload code to the one working unit via ESPHome and it stopped communicating too.

I recently found a new “ESP01 programmer” that had a set of header pins I could connect a sensor to, and at under AU$2 each I figured I’d have one last try before binning the lot.

Happy to report I have successfully reprogrammed all five “dead” ESP-01s that couldn’t be programmed via Arduino or other modules - plus a bunch of new ESP-01S’s using ESPhome / esphome.io and these boards. No soldering wires across pins, adding buttons, holding a button or jumper in place on boot etc. Just plug the ESP-01 into the board and program away.

To “deploy” my new ESP01 sensor modules I’m leaving the ESP01 in the header and connecting my sensors to the headers, and only a USB extension cable is needed to power them.

7 Likes

That is the easy one

What’s the difference between these and the usual methods? It looks like any other uart adapter.

In any case thanks for the post. As an ESPHome newbie I didn’t know that nodemcus etc were supported. Now to free up some of my other boards!

Electrically I’m unsure what the difference are, but I’ve now tried programming different ESP01s on three of these boards and each has worked flawlessly. I’ve got around a dozen other UART boards and had nothing but frustration with all of them (and all have tons of reviews on Aliexpress/Banggood saying how well they work…maybe I’ve just been unlucky).

This one claims to automatically detect whether the ESP01 needs to be placed in running mode or boot mode, but no idea how. But chipset on this board looks much like any other. The push button on the side appears to be a reboot button only.

Sometimes is hard to bridge GND and GPIO00 temporarily

Just put an order in with cheap (slow) shipping. :grinning:

Your post just helped me to save my ESP01 army :slight_smile: and lead me to expand it too!
This tool is just simple and effective, love it.

Many thanks for sharing :pray:

1 Like

My question is, once programming how do you boot it when not connected to the programming board?

And which GPIOs cannt be used that will interrupt boot.

I’ve finally got mine programmed and they work flawlessly when connected via the modile in UART mode, but when adding them to my project im having all kinds of issues.

Can we utilize the RX and TX GPIOs on these board through ESPHOME?

Also, which GPIOs need to be pulled high and which need to be pulled low for sucessful boot?

Im about to throw mine in the ocean.

3 Likes

Which OS is the computer running you use to communicate to the uart/ esp?
I just repower mine to reboot. To put the esp1-01 into programming mode see #4 from nikito7.

Did you finish your project successfully now?

Yes, this topic is old and answered, but it took me a long time to find and gather all this info together, and this looks like a good place to post it. Hopefully it will save others some time.

Using ESP-01s with Home Assistant with ESPhome

Serial
When flashing an ESP for the first time, you need to figure out a way to talk serial from your computer to the ESP. After flashing with an OTA-capable firmware, you don’t need to use the serial programmer anymore – update wirelessly.

USB-serial bridge board
The easy way
Buy this specialty ESP-01S Programmer from Amazon or AliExpress

  • No wiring necessary. Just plug in the ESP01 directly to the serial board.
  • No driver necessary. The USB->UART on this board is a CH340G chip, and its serial driver is included by Apple since OSX 10.14.
  • No GPIO0 disconnection necessary. The board has a built-in switch to go from flash mode (PROG) to serial only (UART).
    When flashing with ESPHome (see below): Install the image, unplug the serial board, flip the switch to UART, and plug it back in for power.

The DIY way
Wire it up yourself using a different USB-serial bridge board.
Before finding the above board, I used a FT232RL-based usb-serial FTDI board from AliExpress. Connect the board to USB, the red led should light. USB-C is weird, I had to use two adapters to go from USB-C to A, then A back to C to convince USB-C to power on my board.

Connect the ESP to the serial device
Wiring:

Set 3.3V (not 5v) with on-board jumper on the FTDI board (between the pins and the chip). Jumper should be between middle pin and the one labelled 3.3v.
Make sure you can disconnect GPIO0; you will need to do this to take the board out of programming mode.

Install USB serial driver
Regardless of which board you’re using, you need make sure your computer can now speak serial over the USB port - meaning you need a driver for your USB-to-serial board.
(Note I’m using Mac OSX, other OS’s may/may not need to install new drivers.)
For the FT232RL board, download the latest driver from FTDI. For a CP210x usb-serial board, get the drivers from SILabs. The drivers for the CH340G (“the easy way” above) are already included in OSX.

Flash with ESPHome from Home Assistant
Install the ESPHome Add-On to your Home Assistant instance.
Home Assistant → Settings → Add Ons → ESPHome → WebUI → New Device → Continue
This gets you to Create Configuration, give it a name.
Select esp8266 device
How do you want to install: plug into this computer
“Download project” after it’s finished preparing (will take a few minutes) to get the newly-compiled firmware onto your laptop.
Open ESPHome Web, Connect. If you have properly installed your driver above, you will see an option in the list for usbserial.
CH340G
or
FT232RL

Make sure the switch is in Prog mode, see above. Installation will try and fail if it isn’t.

Don’t use “Prepare for first use”, instead Install Downloaded Project, selecting the firmware file you just downloaded. If you use “Prepare for first use”, the install succeeds, but then the next thing that happens is “An error occurred. Improv Wi-Fi Serial not detected.”
You’ll see the TX/RX LEDs on your serial board flash (if it has them).

Unplug the serial board from USB. Take the board out of flashing mode (just flip the switch if you’re using the ESP-01S programmer, or disconnect the GPIO0 pin if not.)
Plug the serial board back in to power the ESP01.

Close that install window, going back to ESPHome in Home Assistant, hopefully you’ll see your new project on the dashboard, with “online” now in the upper right corner of the tile. Go to “logs” to see what’s up, got an IP, connected to you wifi and all.

Future code updates will all be done wirelessly, no need to go through any of the above steps again!

Code up your project and install from the ESPHome web gui
Edit the new device’s config to something useful.
Here’s a starter device yaml for an ESP01-S that generates the sensors shown picture below.

substitutions:
  name: esp02
  friendly_name: "ESP02"

esphome:
  name: "${name}"
  friendly_name: "${friendly_name}"

esp8266:
  board: esp01_1m
  restore_from_flash: false

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "...ESPHome will generate..."

ota:
  password: "...ESPHome will generate..."

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp02 Fallback Hotspot"
    password: "...ESPHome will generate..."

captive_portal:

# Minimal flash writes, once per day
preferences:
  flash_write_interval: 1440min

# Sync time with Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time

switch:
  # Switch to restart the ESP
  - platform: restart
    name: ${friendly_name} Restart

# Blink LED for status, and also expose to HA as switch
light:
  - platform: status_led
    name: "${friendly_name} status light"
    id: blueled
    pin:
      number: GPIO2
      inverted: yes
    restore_mode: RESTORE_DEFAULT_OFF

script:
  - id: heartbeat
    mode: single
    then:
      - light.toggle: blueled
      - delay: 20 ms
      - light.toggle: blueled

# Heartbeat while connected to HA
interval:
  - interval: 5s
    then:
      if:
        condition:
          api.connected:
        then:
          - script.execute: heartbeat

text_sensor:
  # Expose WiFi information as sensors
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP
    mac_address:
      name: ${friendly_name} Mac Address

binary_sensor:
  - platform: gpio
    # Use your pins for something fun!
    pin:
      number: GPIO3
      inverted: true
    # HW: pull to ground with 10k, tie high through pump NC switch
    id: pump_alarm
    name: Drain Pump Alarm
    device_class: problem
  - platform: status
    # Status platform provides a connectivity sensor
    name: "${friendly_name} - Status"
    device_class: connectivity

sensor:
  # Report wifi signal strength every 5 min if changed    
  - platform: wifi_signal
    name: ${friendly_name} WiFi Signal
    update_interval: 300s
    filters:
      - delta: 10%

# Pin assignments for ESP-01
# https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
# 3v3 |  | RX/GPIO3 - high at boot
# RST |  | GPIO0 - pulled up, flash if low on boot
# EN  |  | GPIO2 - pulled up, blue led on if pulled down, must be high at boot
# TX  |  | GND
#  ^ TX/GPIO1 - high at boot

Save.
On the “…” Menu, Validate. If all is ok, go ahead and Install, Wirelessly. (Note if you get linking errors (like “not found”) you need to “Clean Build Files” from the ‘…’ menu.)
You will not need the serial board from here on out (assuming you’ve powered your ESP somehow).

Home Assistant
Go to HA Settings → Integrations → ESPHome. The Home Assistant Integration ESPHome, not the ESPHome Add-on this time - we’re adding the new working ESP device to HA for your automations and dashboards. You should see your new board as Discovered, hit Configure.
It will ask if you want to add it to HA, hit Submit, and you should now see it in your devices list, with all its sensors as Entities.

4 Likes