{"id":1081,"date":"2018-06-02T06:01:39","date_gmt":"2018-06-02T11:01:39","guid":{"rendered":"https:\/\/makecoolthings.com\/?p=1081"},"modified":"2019-07-28T10:53:13","modified_gmt":"2019-07-28T15:53:13","slug":"do-you-have-a-moment-to-talk-about-our-lord-and-savior-the-esp32","status":"publish","type":"post","link":"https:\/\/makecoolthings.com\/?p=1081","title":{"rendered":"Do you have a moment to talk about Our Lord and Savior, the ESP32?"},"content":{"rendered":"<div id=\"attachment_1093\" style=\"width: 655px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1093\" class=\"wp-image-1093 size-large\" title=\"The ESP-WROOM-32 'module'.\" src=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03-1024x683.jpg\" alt=\"The ESP-WROOM-32 'module'.\" width=\"645\" height=\"430\" srcset=\"https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03-1024x683.jpg 1024w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03-300x200.jpg 300w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03-768x512.jpg 768w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03.jpg 1200w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/a><p id=\"caption-attachment-1093\" class=\"wp-caption-text\">The ESP-WROOM-32 &#8216;module&#8217;.<\/p><\/div>\n<p>By now just about every electronics hobbyist, embedded systems engineer, person interested in the &#8216;Internet of Things&#8217;, or anyone I can get to stand still for more than three minutes, knows about Espressif&#8217;s ESP32 line of absurdly inexpensive and frighteningly powerful &#8216;system on a chip&#8217; devices. If by some strange chance you don&#8217;t, and it sounds like something relevant to your interests, buckle up!<!--more--><\/p>\n<p>First off, what is it?\u00a0 In its raw form, it&#8217;s a small surface mount chip&#8230; But that chip then requires some external components to really work. (Static RAM, an oscillator, etc.)\u00a0 Where it comes into its own as an embedded computing and <acronym title=\"Internet of Things\">IoT<\/acronym>\u00a0powerhouse however, is as a &#8216;module&#8217;. This is a small PCB with all the required components under an RF shield, with a built-in antenna. It then has pads all around the perimeter for soldering it into your design.<\/p>\n<p>This potent little board is basically a tiny computer.\u00a0 It has a dual-core 32-bit processor capable of operating at up to 240MHz, it has multiple serial ports, it has built-in full-featured Wi-Fi and Bluetooth Low Energy, a couple dozen I\/O\u00a0pins&#8230;most of which can be reassigned to use as a specific bus, a co-processor which allows it to sleep in an extremely low-power state\u2014which we&#8217;ll discuss more later \u2014and the best part? You can get them on Amazon for less than $5 a piece, with Prime&#8230;which of course means you can get them <em>even cheaper<\/em>\u00a0if you buy directly from suppliers in China! &#8230;assuming you don&#8217;t mind the wait.<\/p>\n<div id=\"attachment_1095\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1095\" class=\"wp-image-1095 size-medium\" title=\"Three ESP-WROOM-32 modules.\" src=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05-300x200.jpg\" alt=\"Three ESP-WROOM-32 modules.\" width=\"300\" height=\"200\" srcset=\"https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05-300x200.jpg 300w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05-768x512.jpg 768w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05-1024x683.jpg 1024w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_05.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1095\" class=\"wp-caption-text\">Three ESP-WROOM-32 modules, in &#8216;tape &amp; reel&#8217; format. (Purchased as a 5-pack, I&#8217;d already removed the other two.)<\/p><\/div>\n<h3>The Toolbox<\/h3>\n<p>So what&#8217;re we lookin&#8217; at here, feature-wise? Well! You better go grab a sandwich or something, <em>this is gonna take a while.<\/em><\/p>\n<ul>\n<li>34 <acronym title=\"General Purpose Input\/Output\">GPIO<\/acronym>\u00a0pins.<\/li>\n<li>A 12-bit <acronym title=\"Analog-to-Digital Converter\">ADC<\/acronym> which can be active on up to 18 pins at once, some of which can be assigned to a programmable gain amplifier.<\/li>\n<li>Two 8-bit <acronym title=\"Digital-to-Analog Converter\">DAC<\/acronym> channels which can be used to output variable voltage analog signals.<\/li>\n<li>Ten capacitive touch-sensing <acronym title=\"General Purpose Input\/Output\">GPIO<\/acronym>, for making touch-sensing buttons or surfaces. (These pins cannot be reassigned.)<\/li>\n<li>A wired Ethernet <acronym title=\"Media Access Controller\">MAC<\/acronym> 10\/100Mbps twisted pair or fiber, sorry&#8230;no gigabit!<\/li>\n<li>SD\/SDIO\/MMC Host Controller (For SD Cards, etc.)<\/li>\n<li>Three <acronym title=\"Universal Asynchronous Receiver Transmitter\">UART<\/acronym>\u00a0interfaces, supporting <acronym title=\"Infrared Data Association\">IrDA<\/acronym>, and all directly accessible by the <acronym title=\"Direct Memory Access\">DMA<\/acronym>\u00a0Controller or CPU.<\/li>\n<li>Two\u00a0<acronym title=\"Inter-Integrated Circuit\">I\u00b2C<\/acronym> Bus interfaces. Standard or Fast mode. 7-bit or 10-bit addressing.<\/li>\n<li>Two\u00a0<acronym title=\"Inter-IC Sound, https:\/\/en.wikipedia.org\/wiki\/I%C2%B2S\">I\u00b2S<\/acronym> Bus interfaces. Half- or Full-Duplex operation. Clock frequency from 10kHz to 40MHz. Supports 8-\/16-\/32-\/48-\/64-bit sample resolution on input or output. Dedicated <acronym title=\"Direct Memory Access\">DMA<\/acronym> Controller for each bus. The master clock can be output to the <acronym title=\"Digital-to-Analog Converter\">DAC<\/acronym>. (I&#8217;m assuming this means you can technically generate sound directly from this.)<\/li>\n<li>Infrared Remote Controller. Supports eight channels of IR remote transmitting and receiving.\u00a0 Programmable, can support various protocols. Has a dedicated 512&#215;32-bit block of memory for storing incoming\/outgoing waveform.<\/li>\n<li>Pulse Counter<\/li>\n<li><acronym title=\"Pulse-Width Modulation\">PWM<\/acronym><\/li>\n<li>LED <acronym title=\"Pulse-Width Modulation\">PWM<\/acronym><\/li>\n<li><acronym title=\"Serial Peripheral Interface\">SPI<\/acronym> Bus<\/li>\n<li>Hardware Acceleration<\/li>\n<li><acronym title=\"Controller Area Network\">CAN<\/acronym> Bus,\u00a0a message-based protocol, designed originally for multiplex electrical wiring within automobiles but also used in many other contexts, including industrial sensor networks.<\/li>\n<li>Bluetooth LE Radio<\/li>\n<li>WiFi Radio<\/li>\n<\/ul>\n<div id=\"attachment_1092\" style=\"width: 210px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1092\" class=\"wp-image-1092 size-medium\" title=\"That's a lot of pins!\" src=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02-200x300.jpg\" alt=\"That's a lot of pins!\" width=\"200\" height=\"300\" srcset=\"https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02-200x300.jpg 200w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02-768x1152.jpg 768w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02-683x1024.jpg 683w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_02.jpg 800w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><p id=\"caption-attachment-1092\" class=\"wp-caption-text\">That&#8217;s a lot of pins!<\/p><\/div>\n<p>It really makes the Arduino boards I was working with look like some kind of tinkertoy. The ATMega168\/328 are 16MHz 8-bit microcontrollers with 16\/32kb of RAM, one <acronym title=\"Universal Asynchronous Receiver Transmitter\">UART<\/acronym>, one <acronym title=\"Inter-Integrated Circuit\">I\u00b2C<\/acronym> bus, one <acronym title=\"Serial Peripheral Interface\">SPI<\/acronym> bus&#8230;\u00a0 The ATMega32u4 basically just adds on-board <acronym title=\"Universal Serial Bus\">USB<\/acronym> so it doesn&#8217;t require a <acronym title=\"Universal Serial Bus\">USB<\/acronym>-to-<acronym title=\"Universal Asynchronous Receiver Transmitter\">UART<\/acronym> bridge to talk to a computer and upload new code without a dedicated programmer. The <acronym title=\"Universal Serial Bus\">USB<\/acronym> support also allows the ATMega32u4 to be programmed to act as a <acronym title=\"Universal Serial Bus\">USB<\/acronym> device, such as a <acronym title=\"Universal Serial Bus\">USB<\/acronym> <acronym title=\"Human Interface Device\">HID<\/acronym> <em>(Keyboards, mice, game controllers, etc.)<\/em>, natively.<\/p>\n<p>On-board <acronym title=\"Universal Serial Bus\">USB<\/acronym> is pretty much the one thing that the ESP32 lacks&#8230;\u00a0<em>However<\/em> it can act as a Bluetooth <acronym title=\"Human Interface Device\">HID<\/acronym>, and it can be programmed <acronym title=\"Over-The-Air\">OTA<\/acronym>\u00a0via WiFi with an appropriately-configured bootloader.<\/p>\n<p>But let&#8217;s not stop at comparing it to other microcontrollers; When we&#8217;re talking about sheer computing power, the ESP32 tops every computer I owned from the day I was born in 1981 through my first Windows PC in 1995&#8230;\u00a0<em>Combined!<\/em><\/p>\n<h3>With Great Power Something Something<\/h3>\n<p>Now, you&#8217;re probably thinking &#8220;Yeah, but all that muscle&#8217;s gotta come at a price, right?&#8221; Well, guess what?! The CPU only consumes 30~50mA at full speed! Granted, using the radio eats up some power; The 54mbps WiFi can consume 190mA transmit, 100mA receive, and the Bluetooth-LE is 130mA\/100mA&#8230;however I imagine the duration of that current draw depends greatly on how your code is written&#8230;I&#8217;m sure there&#8217;s plenty of ways to be economical about keeping the RF module powered up&#8230;<\/p>\n<p>But then we get into the ESP32&#8217;s crazy low-power modes. Its co-processor allows it to go into a &#8216;deep sleep&#8217; mode of just 150<acronym title=\"microamps, millionths of an ampere\">\u03bcA<\/acronym> (That&#8217;s MICRO amps!) by turning off the CPU entirely and using the co-processor to poll the <acronym title=\"General Purpose Input\/Output\">GPIO<\/acronym> pins looking for whatever values or states your program is waiting for.\u00a0That can be further reduced to\u00a0100<acronym title=\"microamps, millionths of an ampere\">\u03bcA<\/acronym> by only polling at a 1% duty cycle. (Still more than good enough for physical inputs and all but the most sensitive of sensors.) There&#8217;s a final &#8216;deep sleep&#8217; mode which just maintains the <acronym title=\"Real-Time Clock\">RTC<\/acronym>\u00a0and the contents of its memory, at the cost of just 10<acronym title=\"microamps, millionths of an ampere\">\u03bcA<\/acronym>&#8230;\u00a0 You can go full &#8216;hibernation&#8217; where only the <acronym title=\"Real-Time Clock\">RTC<\/acronym> itself is powered, for 5<acronym title=\"microamps, millionths of an ampere\">\u03bcA<\/acronym>. Of course when I first read up on those last two I was like &#8220;Wait, then how does it&#8230;?&#8221; it turns out that the <acronym title=\"Real-Time Clock\">RTC<\/acronym> can wake the chip up based on a predetermined timer, as well as a couple dedicated <acronym title=\"Real-Time Clock\">RTC<\/acronym> <acronym title=\"General Purpose Input\/Output\">GPIO<\/acronym> pins that can wake it.<\/p>\n<div id=\"attachment_1094\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1094\" class=\"wp-image-1094 size-medium\" title=\"ESP32 (L) beside ESP8266 (R)\" src=\"http:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04-300x200.jpg\" alt=\"ESP32 (L) beside ESP8266 (R)\" width=\"300\" height=\"200\" srcset=\"https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04-300x200.jpg 300w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04-768x512.jpg 768w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04-1024x683.jpg 1024w, https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_04.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1094\" class=\"wp-caption-text\">An ESP32 module beside its predecessor, an ESP8266 WiFi module.<\/p><\/div>\n<h3>Conclusion<\/h3>\n<p>It&#8217;s just one hell of a piece of hardware, yet it&#8217;s stupid-cheap, absurdly-small, and can run very very light on the power consumption.\u00a0 Maybe at some point in the future I&#8217;ll make another post about applications, but as it is I started writing this in June 2018, so it&#8217;s been\u00a0<em>a year<\/em> and I still hadn&#8217;t finished it. Time to just post the bloody thing! &#x1f613;<\/p>\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>By now just about every electronics hobbyist, embedded systems engineer, person interested in the &#8216;Internet of Things&#8217;, or anyone I can get to stand still for more than three minutes, knows about Espressif&#8217;s ESP32 line of absurdly inexpensive and frighteningly powerful &#8216;system on a chip&#8217; devices. If by some strange chance you don&#8217;t, and it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1093,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bgseo_title":"","bgseo_description":"","bgseo_robots_index":"","bgseo_robots_follow":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[],"wf_post_folders":[],"class_list":["post-1081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/media.makecoolthings.com\/wp\/2018\/06\/esp32_03.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6NlLW-hr","_links":{"self":[{"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/posts\/1081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1081"}],"version-history":[{"count":10,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/posts\/1081\/revisions"}],"predecessor-version":[{"id":1280,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/posts\/1081\/revisions\/1280"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=\/wp\/v2\/media\/1093"}],"wp:attachment":[{"href":"https:\/\/makecoolthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1081"},{"taxonomy":"wf_post_folders","embeddable":true,"href":"https:\/\/makecoolthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fwf_post_folders&post=1081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}