• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Maker Hacks

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • YouTube
  • Free Arduino Course
  • Recommendations
  • Contact

ESP32 Arduino – First Look

You are here: Home / Software / ESP32 Arduino – First Look
FacebookTweetPin
Author: Chris Garrett
ESP32

The ESP32 is the newest* super powered IoT/Arduino board you are going to want in your arsenal.

I have long been a fan of the ESP8266, especially the cheap Chinese NodeMCU boards, so when I saw the faster, more capable ESP32 had Arduino compatibility, I had to give it a try!

* Yeah, it’s been talked about since 2015, but really it’s not been convenient to play with until now 🙂

ESP32 Arduino Power House

How big and capable? It’s a 32 bit board, dual-core running at … wait for it … 160mhz (or as high as 240mhz)!

There’s 128KB of ROM, 416KB SRAM, and Flash memory is external (I think mine is 4MB, max 64MB).

So it is fast, has a bunch of memory, and does wifi. Cool?

One downside of the ESP8266 was its lack of pins. Not a problem here, there are 36 GPIO pins, including:

  • Up to 16 channels ADC
  • 2x 8-bit DAC (actual analog!)
  • 16x PWM
  • 10x capacitive touch sensing
  • 2x UART
  • 2x I2C
  • 4x SPI
  • 2x I2S

Yeah, it’s not the first 32 bit board out there, but this is still serious business for Arduino IoT fans!

While I have friends who swear by the Teensy boards, I just don’t see the point in them now the ESP32 is packaged in a convenient, wifi-enabled board.

Oh, and there is more – It doesn’t just do wifi by the way, as well as wifi it also has Bluetooth/BLE!

ESP32

Buying an ESP32

The board I purchased was the $15 Espressif ESP32 board from Adafruit.

Sparkfun also have a board, and I am sure there will be many more out there.

The chip is causing a lot of buzz so I have no doubt the dev board clones will be coming thick and fast too.

Arduino with the ESP32

Like with many third-party Arduino boards, you need to add hardware definitions, but right now it is still early in the development so you need to get the files from the git repo.

Download and uncompress and place in your Hardware folder.

Within the tools folder you will find a get.py python script that will install the compiler etc.

python ./get.py

How to Connect to Wifi on the ESP32

The wifi on the ESP32 is fast and is SSL compatible, which is nice because Maker Hacks just went 100% HTTPS 😉  There is a secure HTTP client available here that follows 301 redirects, as yet I haven’t got it working (I think I messed up my libraries) but I will update when I do get it running.

ESP32 has plenty of memory so can cope with the large strings that make up web pages, JSON/XML data, and everything we throw at internet of things devices nowadays.

Let’s try some code, shall we?

In this example we will connect via wifi to a website and switch on an LED when stuff is happening. Nothing too strenuous 🙂

Just to make it extra fancy I placed a 3d printed Stormtrooper head over the LED 😉

View this post on Instagram

A post shared by Chris Garrett (@chrisgarrett)

ESP32 Code

// wifi library
#include <WiFi.h>
// WiFi network name and password:
const char * networkName = "YOUR_WIFI_HERE";
const char * networkPswd = "PASSWORD_HERE";
// The domain to request from:
const char * hostDomain = "chrisg.org";
const int hostPort = 80;
// whichever pin your LED is attached
const int LED_PIN = 5;
void setup()
{
  // set the baud rate:
  Serial.begin(115200);
  // set the LED pin to output
  pinMode(LED_PIN, OUTPUT);
  // Function for the wifi, see below 
  connectToWiFi(networkName, networkPswd);
}
// do this forever
void loop()
{
    // LED on
    digitalWrite(LED_PIN, HIGH); 
  
    // get the web page
    requestURL(hostDomain, hostPort);
  
    // LED off
    digitalWrite(LED_PIN, LOW); 
  
    // wait a second
    delay(1000);
}
// function to connect
void connectToWiFi(const char * ssid, const char * pwd)
{
  // init the LED state
  int ledState = 0;
  
  // connecting message
  Serial.println("Connecting to your network: " + String(ssid));
  // start the wifi
  WiFi.begin(ssid, pwd);
  // loop while not connected
  while (WiFi.status() != WL_CONNECTED) 
  {
    // Blink LED
    digitalWrite(LED_PIN, ledState);
    
    // switch state between on and off
    ledState = (ledState + 1) % 2; 
    
    // wait half a second
    delay(500);
    
    // dots
    Serial.print(".");
  }
  // blank line
  Serial.println();
  
  // yay!
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}
// grab the html
void requestURL(const char * host, uint8_t port)
{
  // status 
  Serial.println("Connecting to domain: " + String(host));
  // Use WiFiClient to get TCP connection
  WiFiClient client;
  if (!client.connect(host, port))
  {
    Serial.println("connection failed");
    return;
  }
  
  // connected!
  Serial.println("Connected!");
  // send the HTTP GET request 
  client.print((String)"GET / HTTP/1.1\r\n" +
               "Host: " + String(host) + "\r\n" +
               "Connection: close\r\n\r\n");
  
  // timeout
  unsigned long timeout = millis();
  while (client.available() == 0) 
  {
    if (millis() - timeout > 5000) 
    {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  // Read + print to serial monitor
  while (client.available()) 
  {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  // all done
  Serial.println();
  Serial.println("closing connection");
  client.stop();
}

 

Related

Category: SoftwareTag: arduino, esp32, Makes, making
FacebookTweetPin

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Maker Hacks on Ko-Fi and get exclusive content and rewards!

Previous Post:OctoPrint / OctopiHow to Install and Set Up Octopi for Remote Raspberry Pi 3D Printer Control with Octoprint
Next Post:Meshmixer Tutorial – Using Meshmixer to Delete and Edit Parts of an Existing .STLmeshmixer-orientation

Sidebar

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Recently Popular

  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • xTool D1 Pro Laser Cutter Review
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review
  • Glowforge Air Filter Review
  • Thunder Laser Review
  • 3D Printing
  • CNC
  • Hardware
  • Laser Cutting
  • News
  • Retro Computing
  • Software

amiga amos arduino basic programming budget buying cad cnc commodore corexy c programming creality crypto doctor who emulation esp32 esp8266 filament fpga glowforge Hacks Ideas kids lighting linux Makes making Monoprice Parts pc props prusa python raspberry pi ratrig resin Reviews robots software sounds technology tips upgrades wanhao xtool

.

Maker Hacks Blog Copyright © 2023 · All Rights Reserved · Powered by Mai Theme