Tuesday, May 19, 2020

Adventures in ESP8266

You know, I have yet to encounter an electronics troubleshooting issue of which recounting doesn't feel like telling a gaff on myself.

First off, I'd just like acknowledge esp8266.com and esp8266.net as being invaluable information hubs!

If you want the solution and not the story, see this post.

Background

In 2015, shortly after the ESP8266 first came out, I used an ESP-01 module for one of my college classes. I don't remember much about the experience, but I'm pretty sure I managed to get it up and running in less than a three-hour class. Well, that and that part of the process was me casually mentioning to the lab supervisor that I unplugged one of the computers to plug into a wireless router and him saying "yeah... I'm not sure you're supposed to tell me that..."

Cut to 2017, and I finally decide it's time to dig back into ESPland with a new idea for a project. The two primary factors are 1) size and 2) I2C capability. The ESP-01 doesn't have ready-to-go I2C pins available, so I do some searching on compact ESP modules. Hey, turns out that the ESP-03 not only has the I2C pins broken out, but it's also smaller than the ESP-01! I order all my parts, start breadboarding, get sidetracked with some other project, and stow it away for playing with on some later date.

It's May of 2020, I'm quarantined at home, and I'm determined to get this thing working. So I start out with the "hello world" of the electronics world: a simple blinking light (with a bonus "Hello, World!" over serial).

Immediately I can't even load a program onto it, and remember why I packed this away three years ago.

I realize everything's out of date. So I update and still... Nothing. Let the real troubleshooting begin.

Equipment

Hardware


Software

For programming and flashing, I used the Arduino IDE. The folks at esp8266.com did a really nice job getting this bit to be about as easy as you could ask. Just add the following link to Additional Board Manager URLs, install 8266 via Board Manager, and you're good to go.
http://arduino.esp8266.com/stable/package_esp8266com_index.json

So I hook everything up, press the appropriate buttons in the appropriate order, and...

 Troubleshooting


esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

This is a phrase that will haunt me for a while.

DaedalusRising's board has the correct pullup and pulldown resistors to solve a lot of the obvious troubleshooting issues which made things handy setup-wise, but it's a little disappointing because that means this likely isn't going to be a 10 minute "oh, duh" fix.

First question: Does my FTDI adapter still work? Did I break it at some point? A simple loopback test with typing into PuTTY shows that it does indeed work.

AT Commands

After some more research, I learn about AT Commands, a set of commands to control a device over serial. Alright, let's see what we can do here.

>at
OK
Well that's good news! Next step:
>at+rst
Error
Well shoot. That's an issue. It's there, but it won't reset. Why not? Commence Googling and DuckDuckGoing that both end up fruitless.

After some further wild goose chasing, I try once more:
>AT
OK
 
>AT+RST
[Expected stuff here]

Success! Turns out that everything other than the basic "AT" is case-sensitive. Live and learn, I suppose.

ESPtool Research

So we know that our serial line works, and we know that our device seems to be working. Arduino uses esptool to communicate with the ESP8266, so next let's see if that's working as intended:

>esptool.py.exe -p COM4 -b 115200 chip_id
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

Nothing. Drat.


To get even more basic, I perform a test of just pySerial. After some trial and error, I again use a loopback with some Python code to see if I can get esptool to work.

>py loopback.py
COM4
b'hello'

Well... That's something I guess. I know that pySerial works.

Actually, this is helpful. I pretty much have it narrowed down to esptool at this point. Time to head back to Google (you know it's bad when you've reached the second page).

The Solution

With my newfound knowledge and more finely-tuned search terms, I read countless more forum posts and GitHub issues, until I run across this thread with these fateful comments:

GPIO0 is Linked to the ground

I think everyone on the planet knows about Gpio0 at this stage !

Pretty much. The breakout does has that handy Program pushbutton after all.

Yeah, but I had the same problem and it turns out that after connecting GPIO0 to ground you must restart the ESP. I mean just unplug it from the power and plug it again.

Wait... What? So I quickly try it.

WONDER OF WONDERS.

IT WORKS.

HALLELUJAH.

 Further Exploration

But why is this? Why doesn't the reset pin do the same thing? Is it a bad solder joint? No, I can probe the ESP-03 reset pin and it goes to GND when I press RST. So what's the deal?

I guess it would be too simple for the ESP-03 schematics to be readily available. At best, I can find this picture at esp8266.com:

But going through Google Images, I come across this picture:


Wait, why is that circled? I follow the link to nathan.chantrell.net and it zooms in.


Why they couldn't have broken out RST to that N/C pin is beyond me, but they didn't ask me. Maybe that's why the ESP-03 has been discontinued.

After all this, I go back to the ESP-03 page on esp8266.com

GPIO16 ... can also be connected to ESP EXT_RSTB (reset) pin by closing jumper near pin 8 ...

Conclusion

When in doubt, RTFM.

Like I said: I have yet to encounter an electronics troubleshooting issue of which recounting doesn't feel like telling a gaff on myself.

Solution to esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

I ran into this problem while messing with an ESP-03.

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for package header

(If you want to read my whole troubleshooting adventure, see this post.)

Arduino version 1.8.12, additional board manager from this URL, esp8266 board package version 2.7.1. AT Commands respond appropriately, so I know UART is working.

Turns out out that GPIO16 on ESP-03 is by default not connected to RST. So the oft-parroted sequence of GPIO0 low, GPIO16 low then high, GPIO0 high didn't work.

Solution!

The brute-force solution for any ESP module is
  1. Remove power
  2. GPIO0 low
  3. Provide power
  4. GPIO0 high
Another solution for ESP-03 is to bridge the jumper near VCC and GPIO14. This connects GPIO16 to RST, allowing external hard reset.
Picture courtesy of nathan.chantrell.net

Why they couldn't have broken out RST to that N/C pin is beyond me, but they didn't ask me. Maybe that's why the ESP-03 has been discontinued.