The Wemos 0.66 inch OLED Shield is a small OLED display that can be used with the Wemos D1 Mini. The display has a resolution of 64x48 pixels and is controlled by the SSD1306 driver. The display is connected to the I2C bus of the Wemos D1 Mini. The display can be used to show text, images, and graphics. The display is equipped with a push button that can be used to interact with the display. The display can be used to show sensor data, status information, or as a user interface for a project.

Example Code

Install the libraries using the Arduino Library Manager. The libraries are:

  • Adafruit GFX Library
  • Adafruit SSD1306 Library Wemos Mini OLED

DANGER

Do not install the Adafruit SSD1306 library, it will not work with the Wemos Mini OLED. Having both libraries installed will cause weird errors. So be sure to only have the Adafruit SSD1306 Wemos Mini OLED installed.

higher or equal to v2.1.0:

Make sure to install the correct library to interact with the buttons: https://github.com/wemos/LOLIN_OLED_I2C_Button_Library

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <LOLIN_I2C_BUTTON.h>
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
I2C_BUTTON button(DEFAULT_I2C_BUTTON_ADDRESS); //I2C Address 0x31
const String statusName[] = { "Open", "Pressed", "Long", "Double", "Hold" };
void setup() {
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
   if (button.get() == 0) {
      display.clearDisplay();
      display.setCursor(0, 0);
      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.println("NDL");
      display.setTextSize(1);
      display.print("A: ");
      display.println(statusName[button.BUTTON_A]);
      display.print("B: ");
      display.println(statusName[button.BUTTON_B]);
      display.display();//Always end with display to push the display buffer to the screen
   } 
   delay(500);
}

This library has some unfortunate name clashes with the new motor library named LOLIN_I2C_MOTOR.h The problem is that both libraries export an enumaration type with identical names. Proper use of namespaces, careful export of names or using better names would have prevented this problem. If you need to combine those libraries the only option is to update at least one of them to solve the problem. Moving the enumeration type from the header file to the corresponding implementation appears to be an easy solution.

lower than v2.1.0

To interact with the buttons, just use GPIO (digitalRead, and don’t forget to set them to input). D3=Key A, D4=Key B

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define KEYA D3
#define KEYB D4
#define OLED_RESET -1
// GPIO1
Adafruit_SSD1306 display(OLED_RESET);
 
void setup() {
	display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
	delay(1000);
	// initialize with the I2 C address
	pinMode(KEYA, INPUT);
	pinMode(KEYB, INPUT);
}
 
void loop() {
	display.clearDisplay();
	display.setCursor(0, 0);
	display.setTextColor(WHITE);
	display.setTextSize(2);
	display.println("NDL");
	display.setTextSize(1);
	display.print("Key A = ");
	display.println(digitalRead(KEYA));
	display.print("Key B = ");
	display.println(digitalRead(KEYB));
	display.display();
	// required to refresh the screen contents
	delay(200);
}

Wemos OLED Button Shield