NederlandsKlik deze knop voor de Nederlandstalige website

WEMOS D1 Esp-Wroom-02 and Arduino IDE

The “WEMOS D1 Esp-Wroom-02” that I got from VNG Systems is another microcontroller development board with an ESP8266 WiFi chip. This board also has an OLED screen, 18650 battery charging circuit and a directional button built-in. This makes the board an excellent option for mobile applications. And like all the other ESP8266 based boards, this one can be programmed with the familar Arduino IDE.

Wemos D1 ESP-Wroom-02 and Arduino IDE: VNG systems unboxing
Wemos D1 ESP-Wroom-02 and Arduino IDE: VNG systems unboxing

WEMOS D1 Esp-Wroom-02 features

First, let’s take a closer look at the board itself. The black circuit board comes with a 10 pin header that you can solder onto it, if needed. The back of the board has a battery holder that supports flat top 18650 batteries. Other characteristics of the board are:

  • Board size: 102x30x20mm
  • Voltage Input range: 5V-12V
  • Micro USB connection
  • Charge Current: 500 mA
  • Battery overcharging and overdischarging protection circuit

I found that the information about the board published online usually is incorrect.. For instance, the name  of the board implies that it is fitted with the ESP-WROOM-02 WiFi chip. Instead, it has an ESP-12E/F module. Also, most of the sites mention the wrong OLED-libraries and GPIO pinouts. So below I will write about my own findings and experiences.

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
Tested and recommended by OneGuyOneBlog.com:

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
VNGsystems.nl

Wemos D1 Esp-Wroom-02 Inputs and outputs

On the board there are the following inputs and outputs available:

  • 1 Analog input AD (A0)
  • 5 Digital inputs/outputs with interrupt/PWM/I2C/one-wire support D3 (GPIO0), D4 (GPIO2), D8 (GPIO15), D9 (GPIO3), D10 (GPIO1)

Built-in LEDs

The description states that the board has one programmable LED, on pin D0. But I found that the board has 2 programmable LEDs. One is the blue LED on the ESP8266 module, the other one is an additional green led on the breakout board.

  • Programmable blue LED on GPIO2 (LED_BUILTIN)
  • Programmable green LED on GPIO16

OLED screen

The built-in OLED screen has the following specifications:

  • Controller: SSD1306
  • Resolution: 128 x 64 pixels, size: 0.96 Inch, color: White
  • I2C (GPIO5: SDA; GPIO4: SCL)
  • Address: 0x3C

It can be used with the ThingPulse ESP8266 OLED SSD1306 library.

Directional button

The board has a built-in directional button which supports 5 functions:

  • Up (GPIO13), Down (GPIO12)
  • Left (RESET) , Right (GPIO0)
  • Push (GPIO14)

Unfortunately, the left direction contact of the button is hardwired to the RESET pin of the ESP8266, so this can not be changed without modifying the board.

GPIO summary

Summarizing, I found the GPIOs of the ESP are wired as follows:

GPIO Function
0 D3 / Button right
1 D10
2 D4 / LED blue (LED_BUILTIN)
3 D9
4 OLED SCL
5 OLED SDA
12 Button down
13 Button up
14 Button push
15 D8
16 LED green
A0 AD (ADC)

18650 Battery holder

The battery holder supports a single flat top 18650 cell. The charging circuit will protect your battery from overcharging and also overdischarging. Warning: the circuit does not have reversed polarity protection. So be aware to insert the battery the right way. If you insert it reversed, then your board will be damaged. The polarity is indicated by a + and – printed on the board. The charging circuit has two LED indicators: the green LED indicates charging, the red LED (“standby”) lights up when there is power but the battery is not charging. When you upload a sketch to the ESP-Wroom-02, you have to remove the battery first, and set the power switch to the “ON” position.

Using the Wemos Esp-Wroom-02 with the Arduino IDE

First, you need to have the Arduino IDE installed on your computer. For Windows 10 users, check out the blog post “Installing the Arduino IDE on Windows 10” on how to do that. Linux users should see the blog post “Install or upgrade to the latest Arduino IDE on Linux“.

Second, you need to have the “Arduino core for ESP8266 WiFi chip” installed in your Arduino IDE.  See the section “Installing the ESP8266 Arduino core” in the blog post “ESP8266 NodeMcu and Arduino IDE on Linux“. This procedure is the same for both Windows and Linux.

Third, select an appropriate ESP8266-based board in de Arduino IDE. For me, the selection “WeMos D1 R1” worked fine. See the picture below for the settings that I used.

Wemos D1 ESP-Wroom-02 and Arduino IDE: Board settings
Wemos D1 ESP-Wroom-02 and Arduino IDE: Board settings

Fourth, you need to install the OLED library. You can download the ThingPulse ESP8266 OLED SSD1306 library directly from GitHub or install it using the Arduino IDE library manager. See the image below.

Wemos D1 ESP-Wroom-02 and Arduino IDE: OLED library
Wemos D1 ESP-Wroom-02 and Arduino IDE: OLED library

Finally, you should install the Brzo I2C Library (https://github.com/pasko-zh/brzo_i2c) in the same way: go to Sketch > Use Library > Manage Libraries > Search for “Brzo I2C” and choose “install”.

Now, you can test your Esp-Wroom-02 board with the demo sketch below. When the button is pressed, the OLED screen will show the direction of the button. It also displays the value of the analog input, It will change when you touch it with your finger.

/**

     GPIO  0 - Button right / D3
     GPIO  1 - D10
     GPIO  2 - LED blue (LED_BUILTIN) / D4
     GPIO  3 - D9
     GPIO  4 - OLED SCL
     GPIO  5 - OLED SDA
     GPIO 12 - Button down
     GPIO 13 - Button up
     GPIO 14 - Button push
     GPIO 15 - D8
     GPIO 16 - LED green
     GPIO A0 - ADC

**/

#include "SSD1306Brzo.h"            // Include OLED Library

SSD1306Brzo  display(0x3c, 5, 4);   // Initialize OLED display

int blueLed = LED_BUILTIN;          // Blue LED is on GPIO 2 (LED_BUILTIN)
int greenLed = 16;                  // Green LED is on GPIO 16

int analogPin = A0;                 // Analog input is A0
int analogValue = 0;

volatile byte state = LOW;
String button = "Waiting...";

void setup() {
  display.init();   // Initialise the display

  pinMode(blueLed, OUTPUT);   // Initialize digital pin LED_BUILTIN as an output.
  pinMode(greenLed, OUTPUT);  // initialize digital pin 16 as an output.

  pinMode(0, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(0), interrupt0, HIGH);    // Right
  pinMode(12, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(12), interrupt12, HIGH);  // Down
  pinMode(13, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(13), interrupt13, HIGH);  // Up
  pinMode(14, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(14), interrupt14, HIGH);  // Push
}

void drawText() { // Fuction to draw the text
  display.setTextAlignment(TEXT_ALIGN_LEFT);

  display.setFont(ArialMT_Plain_16);
  display.drawString(0, 0, "Button:");
  display.setFont(ArialMT_Plain_24);
  display.drawString(0, 16, button);                          // Print button press

  display.setFont(ArialMT_Plain_16);
  analogValue = analogRead(analogPin);
  display.drawString(0, 48, "ADC: " + String(analogValue));   // Print value of analog input
}

void interrupt0() // Right
{
  button = "Right";
  blink();
}

void interrupt12() // Down
{
  button = "Down";
  blink();
}

void interrupt13() // Up
{
  button = "Up";
  blink();
}

void interrupt14() // Push
{
  button = "Push";
  blink();
}

void blink() {
  state = !state;   // Reverse LED state
}

void loop() {
  display.clear();      // Clear OLED display
  drawText();           // Draw the text
  display.display();    // Write the buffer to the display

  digitalWrite(blueLed, state);      // Turn the blue LED on/off
  digitalWrite(greenLed, !state);    // Turn the green LED on/off
}

VNG Systems

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
Tested and recommended by OneGuyOneBlog.com:

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
VNGsystems.nl
19 Comments