Sunday, April 17, 2016

NodeMCU (ESP8266) to display on 128x64 I2C OLED, using Adafruit SSD1306 library




This post show how to program NodeMCU (ESP8266) on Arduino IDE (with ESP8266 core for Arduino), to display on  0.96 inch 128X64 I2C OLED (base on SSD1306), using Adafruit SSD1306 and Adafruit GFX Libraries.

- It's assumed you are programming NodeMCU on Arduino Software, with ESP8266 core for Arduino installed.

- Connect I2C OLED to NodeMCU.


OLED VCC - NodeMCU 3v3
OLED GND - NodeMCU GND
OLED SCL - NodeMCU D1
OLED SDA - NodeMCU D2

(reamrk: the Fritzing parts of can OLED_SSD1306_I2C_128x64 can be download HERE)


- Add OLED library to Arduino Software:
* Open Library Manager in Arduino IDE, search SSD1306. You can find Adafruit SSD1306 library, SSD1306 OLED driver library for 'monochrome' 128x64 and 128x32 OLEDs. Install it.
* Install Adafruit GFX Library also.

- Open SSD1306 example:
File > Examples > Adafruit SSD1306 > ssd1306_128x64_i2c.

If you get error of "Height incorrect, please fix Adafruit_SSD1306.h!":
Open Adafruit_SSD1306.h file, in the path like "C:\Users\user\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.h". Un-comment "#define SSD1306_128_64", and comment "#define SSD1306_128_32".


- Return to the Adafruit SSD1306 library again. Visit the web site of the library, https://github.com/adafruit/Adafruit_SSD1306. It's Tested Works on ESP8266 (Adafruit Huzzah), but have to change OLED_RESET to different pin if using default I2C pins D4/D5.

There are no RESET signal on my I2C OLED, so I assign it to any pin, LED_BUILTIN (the on-board LED).


- Make sure the I2C address is correct:
My I2C OLED have address 3C, correct the code display.begin(SSD1306_SWITCHCAPVCC, 0x3C);


- Finished.


more:
- Hello World NodeMCU (ESP8266) + 128x64 I2C OLED


Related:
- Another library of I2C OLED for ESP8266 core for Arduino - esp8266-OLED
esp8266-oled-ssd1306 library

9 comments:

  1. Thanks for documenting this. I was pulling my hair out until I came across your blog post. Turns out I was using the wrong pins AND the wrong I2C address.

    --Aaron

    ReplyDelete
  2. Nice Work Eric,
    Is there any way to change the default I2C pins for ESP8266 & boot logo of adafruit library ?

    Attrish

    ReplyDelete
    Replies
    1. Yes you can remove Adafruit library logo - it's default content of buffer array coded at the beginning of cpp file (starts @ line ~40) - just put all zeros. However it is not allowed to remove it if You redistribute Your app.

      Delete
  3. Big thanks ! I try all day and almost give up until I found this.

    ReplyDelete
  4. BIG thanks ... you solved the issue i faced while shifting from UNO to WEMOSd1 .

    ReplyDelete
  5. Changing RESET pin to LED_BUILTIN did the trick, just before I put the MCU and the display in the meat grinder :-)

    Thank you

    ReplyDelete
  6. With the new NodeMCU I had to change RESET to 1 (not LED_BUILTIN) and then it worked.

    ReplyDelete
  7. can i used SD0,SD1,SD2 pins of node mcu?

    ReplyDelete