A look at the ESPDUINO-32 board

In this article we look at an ESP32 based board which goes by the name of ESPDUINO-32, it is also supposedly made by www.doit.am. I have seen a few clones of this board but this is what I bought

ESPDUINO-32

ESPDUINO-32

Here is the blurb I have seen on the internet

Overview
ESPDUINO-32 development board base on ESP-32 WiFi module, it can lead to all ESP32 module pins.
With WiFi, Bluetooth 4.2, Ethernet, real-time map and other functions, ESPduino-32 is compatible with all version of Arduino expansion boards.

Features
Control chip: Xtensa LX6 CPU
UART/EN/SPI/ENTERNET /Bluetooth 4.2
DC 5V-12V
Average current: 80 mA
1 analog input(3.2V max input) – not sure about this
Compatible with Arduino
Operating temperature:-40-85 Degrees Celsius

You need to install support for the board using the procedure in ESP32 and Arduino setup

For the board above I selected ESP32 Dev Module and the board was on COM 4, settings below

 

Code

The standard blink sketch does not work, the BUILTIN_LED is not recognised. A clue to what you use is written down the side of the board beside the connector

You’ll see pins labelled IO18, IO19 and IO23. So a quick change to the standard blink sketch – connecting an LED to IO 18 would be

 

void setup() 
{
  Serial.begin(115200);
  pinMode(18, OUTPUT);
}
 
// the loop function runs over and over again forever
void loop() {
  Serial.println("HIGH");
  digitalWrite(18, HIGH);   // turn the LED on
  delay(1000);              // wait for a second
  Serial.println("LOW");
  digitalWrite(18, LOW);    // turn the LED off
  delay(1000);              // wait for a second
}

 

I have seen a schematic but I do not think its this board, it looks to me like an ESP32 dev board similar to the nodemcu (ESP8266) ones that can be bought. The board is definitely usable but the claim that its compatible with arduino expansion shields is dubious. Why, well if you at the example above the LED is connected to what would be D13 on an Arduino but if you change to either D13 or 13 in the code, the example will not work.

One of the other ESP32 boards may work differently the pins_arduino.h shows how the pins are defined, for example an Arduino

#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)

The ESP32

static const uint8_t SS = 5;
static const uint8_t MOSI = 23;
static const uint8_t MISO = 19;
static const uint8_t SCK = 18;

So IO18 is the same as 13 but do’t expect 3rd party libraries to work particularly if the developer has defined pins in the library then it may well not work, if the developer has let the user define them then not an issue

Take this example from a TM1637 sketch which allows you to define the connection this can be changed

// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3

but this is in an LCD4884 library which would have to be changed based on the corresponding ESP32 pins, so just be wary of plugging in any shield and expecting it to work

// SPI Interface — (using Arduino Digital Pin 2,3,4,5,6)
#define SPI_SCK 2 //Serial Clock(Master Output)
#define SPI_MOSI 3 //Master Output,Slave Input
#define LCD_DC 4 //Data/Command(command active low)
#define SPI_CS 5 //Chip Select,Slave Transmit Enable(active low,Master Output)
#define LCD_RST 6 //One Reset button
#define LCD_BL 7//Backlit control (Arduino DIO Pin 7)

Also be wary that all of the IO pins run at 3.3V.

Its an interesting board that I will play about with considering the capabilities of the ESP32

Links

 ESP32 WiFi and Bluetooth Development Board Ethernet Internet Wireless Transceiver Control Board for arduino IDE

Micropython and ESP32 blink an led

In this example we will use Micropython on an ESP32, the tool I will use is called uPyCraft which makes the task easy

You will need to download the tool first, the latest version I have seen is available from – https://git.oschina.net/dfrobot/upycraft/raw/master/uPyCraft_V0.27.exe.

Start the tool and connect your ESP32 board

Open up the Tools and set the Serial port for your ESP32 board
Open up the Tools and set the ESP32 board in the board menu

Parts List

1 x ESP32 board
1 x LED
1 x 470 ohm resistor
1 x breadboard
Connecting wire

 

Schematic

esp32 and led

esp32 and led

 

Code

Insert the code below into the editor and click on the DownloadRun button

 

import time
from machine import Pin
led=Pin(15,Pin.OUT)
 
while True:
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(0.5)

 

Links

Official DOIT ESP32 Development Board WiFi+Bluetooth Ultra-Low Power Consumption Dual Core

A basic ESP32 Web server example

In this example we will create a basic web server with an ESP32, we will then serve a we page with an on and off button which will switch an LED on and off

Parts Required

1x ESP32 Dev Module (Lolin32)
1x LED
1x Breadboard
1x 470 Ohm Resistor
Jumper wires

 

Layout

This was the best ESP32 fritzing part I could find

 

esp32 and led

esp32 and led

 

Code

Adding support for ESP32 boards – showed how to add support to the Arduino IDE

 

#include <WiFi.h>
 
// Replace with your network credentials
const char* ssid     = "iainhendry";
const char* password = "iain061271";
 
WiFiServer server(80);
 
const int led =  15;      // the number of the LED pin
 
// Client variables 
char linebuf[80];
int charcount=0;
 
void setup() 
{
  // initialize the LED as an output:
  pinMode(led, OUTPUT);
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while(!Serial) {
  }
 
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  // attempt to connect to Wifi network:
  while(WiFi.status() != WL_CONNECTED) 
  {
    // Connect to WPA/WPA2 network.
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP()); 
  server.begin();
}
 
void loop() 
{
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) 
  {
    Serial.println("New client");
    memset(linebuf,0,sizeof(linebuf));
    charcount=0;
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        Serial.write(c);
        //read char by char HTTP request
        linebuf[charcount]=c;
        if (charcount<sizeof(linebuf)-1) charcount++;
 
        if (c == '\n' && currentLineIsBlank) 
        {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println();
          client.println("<!DOCTYPE HTML><html><head>");
          client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head>");
          client.println("<h1>ESP32 - Web Server example</h1>");
          client.println("<p>LED <a href=\"on\"><button>ON</button></a>&nbsp;<a href=\"off\"><button>OFF</button></a></p>");
          client.println("</html>");
          break;
        }
        if (c == '\n') 
        {
          // you're starting a new line
          currentLineIsBlank = true;
          if (strstr(linebuf,"GET /on") > 0)
          {
            Serial.println("LED ON");
            digitalWrite(led, HIGH);
          }
          else if (strstr(linebuf,"GET /off") > 0)
          {
            Serial.println("LED OFF");
            digitalWrite(led, LOW);
          }
 
          // you're starting a new line
          currentLineIsBlank = true;
          memset(linebuf,0,sizeof(linebuf));
          charcount=0;
        } 
        else if (c != '\r') 
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
 
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

 

Testing

Open the serial monitor to get the assigned IP address, in your favourite web browser navigate to this IP address

This is my example

esp32 webpage

esp32 webpage

 

Now press the on and off button and check if the LED flashes

 

Links

 
You can pick up a module for about $8, this makes it a more costly option than an ESP8266 but the bluetooth and extra digital and analog ports make it well worth it in my book

Official DOIT ESP32 Development Board WiFi+Bluetooth Ultra-Low Power Consumption Dual Core ESP-32

Blink an LED with NodeMCU

In this example we simple flash an LED connected to a nodemcu (esp8266) board. We will use lua for this example.

You will need a NodeMCU board, an led and a resistor, some connecting wire and if you are using components a breadboard makes life easier, I use combined LEDs and resistors on small modules which greatly simplify things removing the need of the breadboard

 

Layout

The layout assumes the use of a breadboard, I have chosen a 470 ohms resistor

nodemcu and led

nodemcu and led

 

Code

Save this as ledflash.lua and load it via the ESPlorer, video underneath shows this

LED_PIN = 1
 
gpio.mode(LED_PIN, gpio.OUTPUT)
value = true
 
tmr.alarm(0, 500, 1, function ()
    gpio.write(LED_PIN, value and gpio.HIGH or gpio.LOW)
    value = not value
end)

 

Video

The video shows me using the ESPlorer tool to connect to the NodeMCU board, open my lua file and then upload to my NodeMCU board