We all know how versatile the ESP8266-01 is. By "we", of course I mean the 6 people that are still reading this after seeing the title! Sure, it does have its limitations:
- only 2 GPIOs
- no analog GPIO
- inability to use the ESP.deepSleep() function
We've looked at getting more GPIOs before here.
We'll look at analog options another time. But in this Instructable, we'll deal with the Deep Sleep issue.
Step 1: Things You'll Need, or Maybe Want
You most likely have everything you need already. The basics:
We are going to be doing some detail soldering, so I also recommend something with clamps, hands, magnifier, and lights, like:
- soldering station (example)
Step 2: About ESP.deepSleep()
When your IoT project is powered by a plug in the wall, you tend not to care too much about power consumption. But if you are going to power your project by batteries, every mA counts.
The video at the beginning of this Instructable shows the actual power consumption of a data logging module I developed. In the video, you can see that while in deep sleep, the unit is only drawing about 3mA. In actuality, the ESP and the other components of the circuit are only drawing micro amps, but the project makes use of a voltage converter and regulator because it's fed off of 12 volt batteries. Those 3 mA are lost power consumed by the ghosts of necessary evil..
The point is, if your circuit is spending most of its time doing nothing, you can really cut back its power use by leveraging the deepSleep() function. In my example, I went from using an almost constant 40 mA, and cut it down to 3 mA.
Code-wise, you do have to think a little differently. When programming with the Arduino IDE, a lot of your heavy lifting code will be in the loop() function. The deepSleep() function will essentially reset your ESP. So, any variables, loop counts, etc, they all get lost.
Your setup() function in effect becomes your loop. When your program has done all that it needs to, before the closing bracket, you just throw in:
//1,000,000 = 1 second ESP.deepSleep(10000000);
And of course this assumes we have the following include at the beginning of the sketch:
At the end of the time specified in the deepSleep() function, the ESP will reset, and start everything at the beginning again.
Here is some code, and ways to handle variable storage. But in this Instructable, we'll focus on the hardware mods.
Step 3: Cut Some Fine Wire
Our ESP-01 can NOT use deepSleep out of the box. We have to solder a wire across two pins. This looks difficult, but trust me, it is not as hard as it seems. Start with some fine wire and strip both ends. An eighth of an inch should work.
I used some 28 ga wire that I use for jumper wires on my breadboards. You could use single-strand wire, but I think it works a little better with multi-strand wires - the wires hold a bit of extra solder amongst themselves. Plus if the gauge is too big, you could remove a few strands to get to the size we need.
Step 4: Examine the End That Connects to the Chip
The chip on the esp is tiny. It would be next to impossible to solder a wire directly to the pin we need to access. Luckily, the pin we need to hit is on the corner of the board. So what we will do, is make sure our tinned jumper wire is well tinned (but not over-soldered), and still skinny and pointy like a needle.
Practice holding the wire end to the pin we need to connect to. If you can't easily poke it straight at the corner pin and make good contact, try a thinner wire, or use some snippers to cut the wire to a point.
Step 5: Solder the Wire to the Rst (reset) Pin
Once the wire is cut and tinned, I like to bend it into the rough shape that you see in the pictures.
Now, we'll solder one end to the Rst pin on the ESP. We do this end first because it helps hold the wire stable when we solder the other end.
Step 6: Solder the Other Wire End to the ESP Chip
This is the hardest part - but don't fret, it's not that bad!
Take the other end of the wire, and poke it at that corner pin of the ESP chip (see picture).
Using your finger (or I like to use a pin, needle, or toothpick - something small yet strong), and hold the wire with the end jabbing at that pin. You want to use something to hold it while you solder, so it doesn't spring back once you remove your iron.
Now, touch your iron to the wire - not at the pin - but close to the plastic wire jacket. Because the wire is so thin, the pre-tinned solder should instantly melt. As soon as you see it liquefy, remove the iron.
Step 7: Hot Glue It to Add Strength
Finally, hit the edge of the board and the wire with some hot glue.
This will help to make sure that you don't break that wire off as you swap the ESP in and out of other project boards.
Step 8: Concluding Thoughts
Using the deepSleep() function will probably get you the most bang for your buck on conserving power, but don't forget to look at other power drains:
- Do you have any other components that are constantly using power? Try using a transistor or a relay to only turn them on when you need them.
- LEDs - if you don't need a light on, kill it! That annoying red power LED on the ESP? hit one side of it with your soldering iron while gently prying it with a small screwdriver (pin, needle, toothpick, etc). If you compare the two pictures here, the main difference is I killed the red power LED on the voltage regulator. Another mA saved! (yes, I know the ESP is also out in the second picture - but trust me, the savings is from that LED!)
Now you know how to make your batteries run the distance - go get creative with your upgraded ESP8266-01!