Introduction: Wemos D1 Mini + 0.96 Inch SSD1306 OLED Display Using SPI
I really love the Wemos D1 mini platform! I bought one of those little WiFi enabled boards a few weeks ago and I've been playing around with it for quote some time now. One of the most interesting things was controlling it using the Blynk App. There's a good Instructable on that as well. A must read as well when you're not familiar yet with setting up your Arduino IDE for the Wemos D1 board (see the steps in Step 2)
The Wemos D1 mini family has 9 shields (10 if you count the prototype shield in as well). If you're not familiar with the concept of shields yet, those are tiny little add-on/plug-in boards with specific "add-on" functionality. See the full lineup here. One of those boards adds a 0.66" OLED display, but the cheapest listing I could find was a little over €5,- so I searched for a similar generic OLED module. I stumbled upon a slightly bigger (0.96 inch) and cheaper (€3,54) module with the same chipset: SSD1306. This was the ebay listing. A quick Google search taught me that this is a widely supported chipset for an OLED display. There's even an Adafruit library for the Arduino platform. So I figured it would be a breeze to use this on my Wemos D1 mini. Well... It would have been if someone would have written this Instructable before I did...
The first thing that was a little off - and I didn't notice when I ordered it - was that the module that I ordered has far more pins in use than the shield, which only uses 2 (and 2 for power). The shield only has an I2C interface while the module I bought supports both I2C and SPI.
Step 1: Choosing Which Serial Interface to Use
The 0.96" module has 7 pins (from left to right):
- GND (Ground)
- VCC (3.3 or 5V DC power)
- D0 (Clock)
- D1 (Data: SDA or MOSI)
- RES (Reset)
- DC (Data/Command)
- CS (Chip Select)
This project which aimed at connecting an Arduino to the same 0.96" OLED module helped a lot in finding the purpose of the D0 and D1 pin.
At first I tried (and failed!) to connect the OLED module using I2C. Then I noticed that the OLED module had a little printed instruction on the back. In order to use it as an I2C module I had to rewire it by soldering and desoldering some resistors on the back. That's when I decided to aim for connecting it using the default configuration: 4 wire SPI.
Step 2: Connect the Wires Between the Wemos D1 Mini and the OLED Module
Next step was to find which pins on the Wemos D1 mini to connect to which pins on the OLED module. The Ground (G) and VCC are obvious, but the others were translated from a sketch I found using an Arduino.
Wemos -> OLED module
- G -> GND
- 3.3V -> VCC
- D5 -> D0
- D7 -> D1
- D3 -> RES
- D1 -> DC
- D8 -> CS
Step 3: Upload the Sketch and Run the Example
I opted to use the Adafruit OLED demo. There's a great instruction written by Adafruit on how to install the required libraries. Adafruit mentions in their instruction that the header file needs to be changed, because it can not detect the display size automatically. Find the file Adafruit_SSD1306.h file in your libraries folder and make sure the SSD1306_128_64 is uncommented and the other dimensions are commented.
// #define SSD1306_128_32 // #define SSD1306_96_16
Next I opened the ssd1306_128x96_spi example that came with the Adafruit libraries and altered the definitions of the OLED_xxx values around line 24 in the example:
#define OLED_MOSI D7 //Connect to D1 on OLED #define OLED_CLK D5 //Connect to D0 on OLED #define OLED_DC D1 //Connect to DC on OLED #define OLED_CS D8 //Connect to CS on OLED #define OLED_RESET D3 //Connect to RES on OLED
After uploading the sketch to the Wemos D1 mini it started running the example! See the video.