ESP-32

The ESP-32 platform

The Espressif ESP 32 System-on-chip is the big sister of the older ESP-8266 (as used in the NodeMCU and the Wemos D1 Mini.

ESP 32 has a Dual Core processor, both WiFi and Bluetooth, and many more built in peripherals. It still costs under ten dollars for a development board.

There are a number of similar-but-different development boards that combine system-on-chip, flash memory, USB interface and sometimes a battery charger, OLED screen or LoRa modem. They all work essentially the same but the pins are often in a different order. Pay attention to the markings on your board.

You can program the ESP-32 in a number of ways.

  • Program in C with the ESP-32 IoT Development Framework (IDF)
  • Program in C++ with the Arduino framework.
  • Program in Javascript with Mongoose OS

This page talks about using Arduino and C++.

The ESP-32 chip is not compatible with the AVR Microcontroller as used in the original Arduino, so you will need to install the Board Support Package for the ESP32, which teaches the Arduino Integrated Development Environment (IDE) how to program the ESP32.

Installing the Board Support Package

Follow these instructions from espressif

  • Start Arduino and open Preferences window.
  • Enter https://dl.espressif.com/dl/package_esp32_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  • Open Boards Manager from Tools > Board menu and install esp32 platform (and don’t forget to select your ESP32 board from Tools > Board menu after installation).

  • Open the Tools -> Board menu and look for the name of your development board. If you don’t find your board’s name listed, select ESP32 Dev Module.

Install the drivers for your development board’s USB interface.

There are three or four popular brands of USB interface chip used by Arduino and other development boards. You will need to install the operating system device drivers for the appropriate chip. Most of the ESP32 boards use the Silicon Labs CP2012, others use the CH-340.

See this page for instructions on links for installing the appropriate driver(s).

  • In the Arduino IDE, open File -> Examples -> Basics -> Blink

  • Check your development board to find out which pin has a built in LED, or simply connect your own LED to pin 2.

  • If you get an error about LED_BUILTIN not being defined, then you will need to define the BUILTIN_LED constant in the Blink sketch. Do this by adding the line #define LED_BUILTIN 2 at around line 25


#define LED_BUILTIN 2

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Using Arduino Over-The-Air Update (OTA)

The USB connection to your development board is about 1 megabit per second. WiFi can be 100 times faster than this.

Rather than connecting your development board to your USB port, I recommend instead powering it from a USB powerbank or a phone charger, and using the Over-the-Air update facility.

This works by configuring the development board to join your wifi. The board will then appear in your Tools -> Ports menu.

Open the OTA example program from File -> Examples -> Examples for ESP32 -> ArduinoOTA -> BasicOTA. Customise the program to set ssid and password to the name and password of your wifi. Install this program over the USB connection.

Once you have installed this program, you can disconnect the USB (you still need to power the board from somewhere, perhaps a USB power bank). You should now find an entry for your board in the Tools -> Port menu, listed under Network Ports.

You can now download your sketches to your ESP32 Development Board over wifi, which is faster and more convenient than USB . You will need to copy the Setup and Loop code from the BasicOTA sketch into your sketch, so that the OTA update code is part of your sketch.