A Beginner's Guide to the ESP8266 (2017)

(tttapa.github.io)

258 points | by davikr 9 days ago

19 comments

  • 037 9 days ago
    For the ESP32, an hero is in the process of adding LVGL[1] to ESPHome[2][3]. You can try it out now: https://github.com/esphome/esphome/pull/6363

    Here's the (very good!) preview documentation: https://deploy-preview-3678--esphome.netlify.app/components/...

    This is such a game-changer for me that I'll be using the ESP32 over the ESP8266 for any projects involving displays from now on.

    [1]: https://lvgl.io/

    [2]: https://esphome.io/

    [3]: ESPHome on HN yesterday (500+ points): https://news.ycombinator.com/item?id=40138228

    • zyberzero 9 days ago
      This is amazing! Thanks for the tip. My ESP32 dev board with a display is in the hands of Fedex right now, so this is perfect timing :)
    • nayuki 8 days ago
      • botanical 8 days ago
        It means suicide to some miscreants from 2006; the phrase is also grammatically incorrect. It certainly does not mean something unexpected.
      • 037 8 days ago
        Oh, sorry, thanks for pointing that out!
    • gkhartman 8 days ago
      This is great news! I recently discovered LVGL and was thinking that it would be great to have in a esphome module. I currently have a few of the small i2c OLED displays going, but they are quite limited.

      Many thanks to those working on it. Can't wait to try the preview.

  • antirez 9 days ago
    I spent the latest three or four months doing embedded programming. After using extensively the ESP8266 and ESP32, now I'm quite certain I prefer big times the RP2040 (that is, the Raspberry Pico processor, but you can find it in different non-Raspberry produced development boards). The reasons are easy to summarize:

    1. Vastly superior C SDK, and even the MicroPython support appears to have an edge.

    2. Fantastic documentation, even if in PDF form, which makes a bit less accessible for us and especially for LLMs training data crawlers. In general LLMs know a great deal more about ESP stuff than the RP2040.

    3. Almost every RP2040 can be overclocked to 400Mhz and work stable, and I could say basically every RP2040 can be stable at 350Mhz, so when comparing performances, account for this.

    4. Very smart hardware capabilities: state machines for programmable pins (PIOs), great DMA support, hardware interpolators.

    5. High quality hardware, and if you don't need the version with wireless, the cost is still quite reasonable. 3/4 euros/dollars per piece.

    6. When you need the "W" one, the wireless chip the Pico uses has its own ARM processor, so you continue to have the two RP2040 cores spare for your application.

    7. Memory mapped flash with execute in place. You can read from 0x1000000+offset just deferencing a pointer and that's it, you access your flash.

    8. More GPIOs available.

    The big disadvantage of the RP2040:

    No SPI RAM support. At this point many ESP32 boards have built-in SPI and this makes memory a lot less a scarse resource.

    To familiarize with the ESP family is useful since they are everywhere and are extremely cheap for what they offer. But still, I would start basically any new project where I have choice with the RP2040.

    • jsheard 8 days ago
      > Almost every RP2040 can be overclocked to 400Mhz and work stable

      If you're playing with overclocking the RP2040 it's good to know that the flash chip might not be able to keep up with those higher clocks though, which leads to inscrutable crashes, and of course the official documentation doesn't endorse overclocking so they don't tell you how to work around that. The flash runs on a configurable clock divider defaulting to 4, so if you're running the CPU at double the nominal clock you can raise the divider to 8 to keep the flash running at its original speed.

      • antirez 8 days ago
        What I do here (https://github.com/antirez/zx2040/) is: stay overclocked when not accessing the flash, downclock when accessing the flash via memory map, return back to the higher clock. Works without issues. I find this method to work more reliably than dividing the clock in practice. Maybe I did something wrong dividing the clock so it was not stable, but the system I described really works flawlessy.
    • unwind 8 days ago
      Why do you feel that LLMs knowing less is a good thing?

      I would add "no on-board flash" as a big negative, at least to me it makes it less of a "true" microcontroller.

      • antirez 8 days ago
        Never said that it's a good thing that LLMs know less. It's a negative thing and I suspect it's like that because of good documentation in PDF format. So you usually need a lot less help in forums, and the doc itself is less discoverable.

        The Pico has 2MB to 16MB on board flash with XIP in all the configurations AFAIK.

        • unwind 8 days ago
          Okay, that is how your second list item:

          Fantastic documentation, even if in PDF form, which makes a bit less accessible for us and especially for LLMs training data crawlers. In general LLMs know a great deal more about ESP stuff than the RP2040.

          came across to me, as if the entire item was a reason why you prefer the RP2040-based systems.

          And I meant that the microcontroller itself (the RP2040 chip) lacks built-in flash. I realize it's on the boards instead, that is the thing I personally don't like since you can never have a single-chip solution.

    • dandy23 9 days ago
      It uses a lot of power for embedded apps though. Not often you need all that performance either.
      • antirez 9 days ago
        You can downclock the Pico as you can overclock it in order to reduce power usage. By default AFAIK it already more or less matches the ESP32 power usage, and downclocking it should be able to reach the one of the ESP8266, likely, but I'm not sure.
        • dandy23 8 days ago
          The RP2040 doesn't have a good low power sleep mode. It uses several hundred uA in sleep and dormant mode versus the ESP8266 which uses only 20uA in deep sleep.

          This makes a huge difference for sensor systems etc. A pico/RP2040 cannot be powered by a battery for very long.

          • antirez 8 days ago
            I never tried to explore the Pico deep sleep indeed. I used it with esp32 with great results even if the wake time of 200 ms does not make certain applications viable. Thanks for the point.
    • regularfry 8 days ago
      Personally I'd like the option to give up a core for wifi/bluetooth. The pico boards are a little ungainly, and having an rp2040 plus radio in a single package would be nice.
  • devsda 9 days ago
    This is a good and extensive guide.

    Most guides out there work with dev boards that are powered by usb. It's great to see a section dedicated to power them with alternatives like LM-1117.

    I'm still hoping to find a guide dedicated to power management of espxxx boards that includes guides for powering them with a range of sources like coin cells, aa, lithium, 9v, 12v batteries etc along with a primer on different features (like sleep modes) and their impact on power consumption to maintain the battery life.

    I always see mentions of all these interesting diy projects but not how they are powered. So, its difficult to get a complete picture of the maintenance needed and their usefulness in the long term.

    • 2Gkashmiri 9 days ago
      I have an esp8266 hooked up to a solar inverter. it used to have problems with not getting enough power so i hooked up a power bank between the inverter and the esp. if the power from solar gets out, the power bank (10k mah on paper, must be less) can run it for around 36 hours on full charge.
      • gh02t 7 days ago
        Finding a powerbank that doesn't auto shut off with small power draws from a esp/microcontroller is hit or miss, it's not something that is advertised and the threshold can vary wildly. There are workarounds but they can get a little complex if you don't want them to just burn a bunch of excess power.

        I've also had bad luck with power banks that can survive outside more than a little while. Not moisture, you can seal that out, but heat and cold seems to kill the batteries.

    • YugyDugan 9 days ago
      That's like your nan being frustrated that there isn't a single definitive guide to buying a laptop.

      There are so many factors that it's a near-impossible task. And even if you somehow managed to do so, it would already be obsolete by the time you stopped typing.

      The datasheet (for each of the ESPxx, regulator, etc) will specify power consumption in different states. But sadly there's a lot of misleading amateurish pseudoscience in Arduino-land so you're best to ignore everything else (which would even include a guide like this, for example).

      • devsda 8 days ago
        I think there's some misunderstanding on the expectations. Documenting a combination of all the available peripherals, boards and power sources is virtually impossible but that is not what I meant.

        Given a power source and board with defined power requirements (e.g. say 3.3v upto 150mA) if we can easily find what commonly available components are needed and how to wire them up (with tradeoffs) is sufficient.

        Here's an excellent video that touches lightly on what I meant. https://m.youtube.com/watch?v=heD1zw3bMhw .

        PS: If you find the video format of tutorials useful for learning about electronics, Andreas Spiess and Great scott channels on youtube have very good content that is helpful for beginners.

        • YugyDugan 8 days ago
          If you're this new to electronics though, you're better off buying a hobbyist development board like any of those suggested in the guide. You don't need to concern yourself with this. Just plug in the USB cable.

          If you're designing your own board, you would simply enter 3.3v and >150mA into the parametric search on Mouser, Digi-Key, TI, etc and pick whatever part takes your fancy.

          This is so simple that there isn't any need for a guide. The datasheet for whatever regulator you choose will tell you the recommended input capacitance, output capacitance, inductance, any configuration resistors, etc.

          Same goes for battery charger ICs, which can be just as simple or far more advanced, and there are new devices being announced all the time for everything from tiny energy harvesting applications to USB PD, which is what I mean when I say it'll be obsolete by the time it's announced.

          It's daunting at first but you need to take the plunge: find a part that interests you on Mouser, integrate it into a design according to its datasheet, and order some PCBs. You'll be amazed how accessible it is.

      • TeMPOraL 9 days ago
        How to read that info from the sheet? Problem: I have my NodeMCU gizmo with sensors and stuff, that works while powered via USB charger. I want to make it portable and powered by AAA batteries. How do I do it? I feel that my nan would've had an easier time figuring out on her own what laptop to buy.
        • stavros 9 days ago
          Connect two AAA batteries to the 3v3 rail.
        • YugyDugan 8 days ago
          That's not what it's designed for. That's like asking how to run your iPhone on AAAs.

          The hobbyist solution would be to find some obscure product on AliExpress with a holder for 2xAAAs and a 5V boost regulator with a USB connector. It's janky and inefficient, but that'll power your board, or your iPhone.

          The 'proper' solution would be to then take this prototype to an optimised design in your ECAD software of choice, integrating a AAA holder and choosing an appropriate regulator, and having some PCBs assembled.

          I'm not sure what else you could want. If the latter sounds daunting to you, it would be very easy for even an inexperienced EE on Fiverr to whip up for you.

      • HeyLaughingBoy 8 days ago
        > misleading amateurish pseudoscience in Arduino-land

        Drives me crazy just how much people don't realize that they don't know and are just spouting unfounded assumptions.

  • dr_dshiv 8 days ago
    My 14 year old has gotten so into arduino this year. ChatGPT was a game changer for him.

    He is using a pair of ESP32s with cameras to make a “mom detector” so he has more time to switch tabs.

    • BrandoElFollito 6 days ago
      I had a "parents detector" in the mid-80s when we got the old TV in our room.

      Unknown to my parents I did a deviation on the mains of the TV to be able to switch off the TV from my bed when the stuff I put on the way trapped.

      For those who may have the reference, it was France, Canal+ times when you had instructional broadcasts on Saturday at midnight and you needed to make out what was going on from a scrambled image. Also the fact that you had to multitask like crazy to not be caught.

    • roughsquare 8 days ago
      Why not have it switch tabs automatically?
  • paul_funyun 9 days ago
    A useful gizmo but bang for your buck seems esp32 is the way to go
    • reaperman 9 days ago
      Biggest advantage of the ESP32 for me is that it can connect to WiFi networks with enterprise encryption with X.509 certificates. ESP8266 doesn't have the CPU horsepower to manage this.
      • throwup238 9 days ago
        The other big advantage is nonvolatile storage. The ESP32 can store the state of modules between restarts.
        • gh02t 7 days ago
          Every ESP8266 module I've ever used had a chunk of flash memory you could use for persistent storage that survived reboots/poweroff too. It's used to store WiFi credentials in a lot of frameworks, but you can stick other data in there. I guess it's not integrated into the chip, but don't most people use the integrated modules even in custom designs? All mine have.

          Also IIRC it's not as well known, but the RTC also has a very tiny amount of memory you can use to pass state between deep sleep cycles. That one won't survive a power loss, but it's handy when sleeping and doesn't wear out like the flash memory.

    • jes5199 9 days ago
      I’ve used both, and I’m actually more productive with the ESP8266 because it is so limited - I can usually squeeze in a minimal implementation of one or two things and that’s it. With the ESP32 there’s always other options, and it means I have to make more decisions, so I end up getting bogged down in irrelevant stuff
    • sircastor 9 days ago
      The ESP32 line is the natural progression. Specifically the ESP32-C3 is the successor to the 8266.
      • yau8edq12i 9 days ago
        If you're looking for a "successor" for the ESP8266, then it's clearly the ESP8684, part of the C2 line - even Espressif says so.
      • weinzierl 9 days ago
        The ESP32-C is a RISC-V, unlike the others.
        • pantalaimon 9 days ago
          All the new ESP32 parts are RISC-V
          • weinzierl 8 days ago
            Isn't the C3 the only one so far?
            • pantalaimon 8 days ago
              ESP32-C2, ESP32-C5, ESP32-C6, ESP32-H2, ESP32-H4 and ESP32-P4 are also RISC-V. Xtensa are ESP8266, ESP32, ESP32-S2 and ESP32-S3.
    • jareklupinski 9 days ago
      i reach for an esp8266 for the same reasons i try to design a 2 layer pcb instead of 4 layer: the challenge

      and maybe just maybe if i have to make a thousand, i'll be ahead of the game

    • GuB-42 9 days ago
      This guide is from 2017, before the ESP32 essentially took over.
    • 3abiton 9 days ago
      It totally depends on the usecase, but I find that esp32 is so powerful, it's not power efficient. Al lot of IoT application run on batteries with a single task usually, and this where ESP8266 shines.
      • cranium 9 days ago
        The ESP32 has series tailored for different purposes: https://www.espressif.com/en/products/socs (eg. the ESP32-H is for low-powered applications). I don't know how it fares against the ESP8266 in power consumption but as a hobbyist I would pick an appropriate ESP32-XX first and only look at alternatives if it's really lacking.

        See also: https://products.espressif.com/#/product-comparison

        • mavamaarten 8 days ago
          It's almost problematic how many variants there are these days. I'm sure they all have their particular application but I sure don't know the difference anymore without spending a lot of time comparing. I feel like a few years ago you just went for an Esp8266 with x amount of flash. I thought the only difference was that and the form factor, but I might just have been oblivious of all variants back then.
          • HeyLaughingBoy 8 days ago
            I used to work for an engineering services company, and by default, our quotes would include a minimum of 40 hours just for finding and sourcing appropriate components.

            Even for an experienced EE, it can be ridiculously time consuming. And it's one of those "hidden tasks" that has to be done but is rarely explicitly accounted for.

    • connicpu 9 days ago
      I mean, if it's for a task where I know my program will fit in 512K flash and 80K ram, then an ESP8266 is still cheaper. One of those is powering my DIY thermostat right now :)
      • LeafItAlone 9 days ago
        I have to imagine that in most hobby (as in, one off) use cases the $1-$2 difference makes no real difference.

        And at one point (years ago) I was able to buy ESP32s for practically the same price on Aliexpress.

        • connicpu 6 days ago
          Space and power savings shouldn't be discounted either. Especially if you're going to run it off a battery ;)
      • peterhadlaw 9 days ago
        Any resources on how you made your diy thermostat? :)
        • connicpu 9 days ago
          If you've done any basic electronics before it would be relatively straightforward. I didn't follow any specific guides, just spent a lot of time reading the datasheets for components that sounded like they might work. My ESP8266 is connected to a GPIO expansion board from Adafruit over I²C, which controls 3 TRIACs through TRIAC opto-isolators. HVAC control wires use 24VAC so TRIACs are the silent option for switching, although relays would have probably worked just as well. After that I just programmed the ESP8266 in Arduino to listen to the MQTT broker on my network to send the values from its temperature probe (also an I²C board from Adafruit) and receive commands. It also has a basic thermostat mode programmed in if it stops receiving commands for too long.
      • pantalaimon 9 days ago
        Unfortunately it relies on an outdated GCC 5 toolchain that will never get an update
  • Perz1val 9 days ago
    I recently got mine out of the stash of "things for future projects" and I wanted to program it using PlatformIO and the RTOS SDK, but that's terribly outdated, with parts of that stack newer and it just doesn't work. Should I use the Arduino framework? That's boring, I did that already with arduino boards. Or maybe I should install the official Espressif toolchain and try the RTOS framework there? It is a bit dated, but I guess if the hardware didn't change, the software doesn't have to either. If anyone wants to give a recommendation, I want to make a system that listens to an endpoint (EC2 atm) and sends wake on lan packets to my devices that join a VPN after booting, so I can access them from anywhere.
    • agys 9 days ago
      I go with PlatformIO and Arduino as framework (#include <Arduino.h> on top of the main.cpp file) for all my ESP32 projects… All the library dependencies are managed through the platformio.ini file. Works perfectly!
    • vineyardmike 8 days ago
      If you really want to quickly build, you can try ESPHome. Less learning, but way easier. They also make it possible to insert your own C into that code too.
  • chaosprint 9 days ago
    esp32 s3 or c6 can be better to get started with:

    https://gist.github.com/sekcompsci/2bf39e715d5fe47579fa184fa...

  • amelius 8 days ago
    Is the Arduino IDE the best way to program these chips? Is there something more "professional", for Linux? Anyone programming with just CLI tools and without Arduino libs?
    • zik 8 days ago
      Sure. I use the ESP32 (rather than the older ESP8266 mentioned here) and I program in C and the ESP API [1]. The provided software has a lot of features and is pretty nice to work with. There's also a vscode plugin which makes configuring and programming the device a breeze.

      [1] https://docs.espressif.com/projects/esp-idf/en/stable/esp32/...

      • amelius 8 days ago
        Thanks. Aside, that looks a lot more developer-friendly than many other vendor-provided tools/frameworks I've seen in the past. I hope the others follow suit.
    • iamds 8 days ago
      VSCode with the platformIO plugin is pretty good
      • HankB99 8 days ago
        Last time I looked, I thought that VSCode/PlatformIO supported both the ESP libraries (ESP-IDF) directly as well as the Arduino libraries (which I think are based on ESP-IDF.)

        My personal preference is to use the Espressif libraries rather than Arduino libraries, but I used to program micro-controllers for a living so I'm more comfortable with that development environment.

  • zippox 9 days ago
    I always see these low prices (<$5) on articles and comments but this doesn't seem the be the case for the boards people actually recommend. Are people buying on aliexpress or other cheap alternatives?
    • otherme123 4 days ago
      You surely won't read this, but this is my best shot: as of today, there's an offer at AZ-delivery (they use to have offers like this every couple of months) that allows you to buy three 8266 for 7€ (2.40€ a piece), one for 3.79€. Sadly, the offer don't extend to the pack of five, that is 20€ (still, 4€ a piece!)

      https://www.az-delivery.de/en/products/nodemcu-lua-lolin-v3-...

      I know I sound like a salesman, but if you subscribe to their newsletter, you'll get that kind of offers all the time.

    • kube-system 9 days ago
    • danieldk 9 days ago
      Wemos D1 Mini is about 5 Euro from many local sellers here. It’s a great little board (if you have the official ones, don’t know about clones).
    • otherme123 9 days ago
      To get less than 5€ you usually have to buy more than one, like here: https://www.az-delivery.de/products/nodemcu-lua-amica-v2-mod....
      • 3D30497420 9 days ago
        As an aside, I've bought a bunch of AZ-Delivery products and have been very happy with them.
    • yjftsjthsd-h 9 days ago
      Aliexpress is probably cheaper, but TBH I just order them on Amazon. If you buy a bundle of like 6 then the unit cost gets around... I would have said $6, but I might be misremembering. Of course, for the number I've used, ~$4 and ~$6 are equivalent so YMMV.
      • regularfry 9 days ago
        Right now I can see knock-off D1 mini clones on Amazon for about £2.40 each. Real Wemos boards are about £4 each in bulk.
    • mft_ 9 days ago
      I’ve got three from AliExpress that were all €2-3 (I pushed the boat out for a USB-C model most recently) and they’re all working perfectly so far.
  • sebosp 7 days ago
    What's the equivalent to foreman/quickstart but for embedded devices, ie you got a bunch of devices, different architectures, different sensors to different pins, different versions of firmware, some of them off, how do you keep track of them?
  • dotnet00 8 days ago
    It's pretty cool how cheap and capable microcontroller dev boards are these days, I just have a stash of two-three dozen esp8266's, esp32s and rp2040s laying around, convenient to just be able to grab one whenever something I'm tinkering with could use some intelligence.
  • krish98sai 9 days ago
    Very clean guide. I wish I had something like this when I attempted to make my Roomba "smarter": https://github.com/krish98sai/smart-roomba
  • bahmboo 9 days ago
    (2017)
  • defanor 9 days ago
    Strange to see an overview of network protocols in the guide, and a web server in the SDK: they are very generic, do not seem like any of that should be specific to ESP8266.

    Edit: Removed two points of the comment that were wrong (as mentioned in a reply).

    • zargon 9 days ago
      The introduction is quite clear that the guide uses Arduino, and using C is a possible alternative, among other options, not covered in the guide. It mentions several of the options in that same paragraph that you complain about it not mentioning.
      • defanor 9 days ago
        Indeed, both are mentioned in the "programming" section, which I have either misread or skimmed over.

        Edit: The options in the same paragraph are for different languages though (I saw those), but nevertheless it also mentions that they exist in general, including those for C. Well, it only mentions the official SDK for C, but hinting at more options still.

  • dvh 9 days ago
    Is there a wifi module with smaller power consumption?
    • BenjiWiebe 8 days ago
      This isn't really answering your question, but Wi-Fi isn't a very power efficient protocol.
  • gekkekoe 8 days ago
    [dead]