logo elektroda
logo elektroda
X
logo elektroda

Operation of the ESP-12F OLED display on the NodeMCU with Arduino IDE

JanuszKornas 4104 17
Best answers

How do I get the integrated SSD1306 OLED on an ESP-12F NodeMCU board working from the Arduino IDE?

Use the D-duino example code for this board and initialize the OLED over I2C; the display is an SSD1306, and the board documentation points to D1 as SDA and D2 as SCL [#18490406] [#18491604] If you selected "Generic ESP8266 Module" in the Arduino IDE, the Dx names are not defined there, so use the GPIO numbers instead or choose a board variant that provides the Dx aliases [#18505226] [#18506161] In the thread, the working setup was to use pins 5 and 4 in the I2C configuration, after which the SSD1306 examples started working [#18491604] [#18506161] The examples in the manufacturer’s repository, especially the subfolders like AdafruitGFX and OLED, are the recommended starting point [#18490406] [#18491604]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18490356
    JanuszKornas
    Level 11  
    Posts: 120
    Help: 6
    Rate: 25
    I bought such a plate:

    https://abc-rc.pl/product-pol-9534-Modul-NODE...SP-12F-z-wyswietlaczem-OLED-0-96-Arduino.html

    It has an integrated Oled module. When power is applied via USB, it starts some demo, so the board is probably good. I've been programming the ESP32 through the Arduino IDE environment and wanted the same here. Unfortunately, but I can't find a library to support this OLED. ABC-RC writes that there is a 1306 and the display itself is 168x64. Libraries for 1306, on the other hand, have descriptions that they are up to 128x64 or smaller. Abstracting from the resolution, they do not work.
    I tried this library:
    https://github.com/ThingPulse/esp8266-oled-ssd1306

    But leaving SDA/SCL doesn't work, and swapping to D1/D2 (as the PCB descriptions suggest), throws errors.

    Anyone program such a board with the help of the Arduino IDE?
  • ADVERTISEMENT
  • #3 18490492
    vieleicht
    Level 37  
    Posts: 2163
    Help: 463
    Rate: 453
    Check the I2c address with a scanner. Maybe it is different from the example.
  • #4 18490558
    JanuszKornas
    Level 11  
    Posts: 120
    Help: 6
    Rate: 25
    vieleicht wrote:
    Check the I2c address with a scanner. Maybe it is different from the example.
    .
    I tried it and it didn't detect anything. But I had a warning that bibiotego times.h, or wires.h was in several versions (I'll check carefully tonight). It sounded like I had it in several versions and now I don't know which one was loading.

    I will check these examples from the manufacturer in the evening.
  • ADVERTISEMENT
  • #5 18490584
    Anonymous
    Level 1  
  • #6 18491589
    JanuszKornas
    Level 11  
    Posts: 120
    Help: 6
    Rate: 25
    1) I don't know how in an I2C scanner I'm supposed to indicate that the SDA/SCL is on such and such port, I've looked and haven't figured out how to do that. If anyone knows, for sport I'd love to know.
    2.
    khoam wrote:
    I suggest starting with the examples that have been prepared by the manufacturer of this D-duino board:
    https://github.com/lspoplove/D-duino/tree/master/Arduino-examples
    .
    This link works, but there are links to two whitepapers, unfortunately the first one does not work (wrong link). On the other hand, I found the pin description (PinMap from this link to be crucial:
    https://github.com/lspoplove/D-duino
    The numbers used on the ArduinoIDE are described in blue. After entering the SDA/SCL numbers as pins 5 and 4, some examples work (I have examples that are described as "ESP8266 and ESP32 OLED driver for SSD1306 displays". These are examples from the library I indicated in the first post. The example from the link indicated in the current (this) post also works.

    UFF, something is already working to display. Thank you all for your help.
  • Helpful post
    #7 18491604
    Anonymous
    Level 1  
  • #8 18492123
    vieleicht
    Level 37  
    Posts: 2163
    Help: 463
    Rate: 453
    JanuszKornas wrote:
    1. I don't know how in the I2C scanner I would indicate that the SDA/SCL is on such and such port, I have searched and not figured out how to do this. If anyone knows, for sport I would be happy to know.
    .

    You can use the I2C Scanner to check the addresses of the devices that are on the bus, but of course they must already be properly integrated into it.
  • ADVERTISEMENT
  • #9 18503329
    xeank
    Level 2  
    Posts: 4
    There are also modules on sale with the ESP8266EX chip ( to be distinguished from ESP8266MOD ). They are sold commercially as: "ESP8266 NodeMCU v3 Wifi 2.4Ghz CH340". For interfacing the OLED display with the SSD1306 controller, set the pins: #define SCL D3 , #define SDA D5 ,// Initialize the OLED display using Wire library. SSD1306 display(0x3c, SDA, SCL);. Under the arduino we then select the board: "LOLIN(WEMOS) D1 mini PRO".
    An example program after modification should look like this:
    /**
    * The MIT License (MIT).
    *
    * Copyright (c) 2016 by Daniel Eichhorn
    *
    * Permission is hereby granted, free of charge, to any person obtaining a copy
    * of this software and associated documentation files (the "Software"), to deal
    * in the Software without restriction, including without limitation the rights
    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    * copies of the Software, and to permit persons to whom the Software is
    * furnished to do so, subject to the following conditions:
    *
    * The above copyright notice and this permission notice shall be included in all
    * copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    * SOFTWARE.
    *
    */

    // Include the correct display library
    // For a connection via I2C using Wire include
    #include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
    #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`.
    // or #include "SH1106.h" alias for `#include "SH1106Wire.h"`.
    // For a connection via I2C using brzo_i2c (must be installed) include
    // #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
    // #include "SSD1306Brzo.h"
    // #include "SH1106Brzo.h"
    // For a connection via SPI include
    // #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
    // #include "SSD1306Spi.h"
    // #include "SH1106SPi.h"

    // Include custom images
    // #include "images.h"

    // Initialize the OLED display using SPI
    // D5 -> CLK
    // D7 -> MOSI (DOUT)
    // D0 -> RES
    // D2 -> DC
    // D8 -> CS
    // SSD1306Spi display(D0, D2, D8);
    // or
    // SH1106Spi display(D0, D2);

    // Initialize the OLED display using brzo_i2c
    // D3 -> SDA
    // D5 -> SCL
    // SSD1306Brzo display(0x3c, D3, D5);
    // or
    // SH1106Brzo display(0x3c, D3, D5);
    // D3 -> SCL
    // D5 -> SDA
    #define SCL D3
    #define SDA D5
    // Initialize the OLED display using Wire library
    SSD1306 display(0x3c, SDA, SCL);
    // SH1106 display(0x3c, D3, D5);


    #define DEMO_DURATION 3000
    typedef void(*Demo)(void);

    int demoMode = 0;
    int counter = 1;

    void setup() {
    Serial.begin(115200);
    Serial.println();
    Serial.println("ok");


    // Initialising the UI will initiate the display too.
    display.init();

    display.flipScreenVertically();
    display.setFont(ArialMT_Plain_10);

    }

    void drawFontFaceDemo() {
    // Font Demo1
    // create more fonts at http://oleddisplay.squix.ch/
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.setFont(ArialMT_Plain_10);
    display.drawString(0, 0, "Hello world");
    display.setFont(ArialMT_Plain_16);
    display.drawString(0, 10, "Hello world");
    display.setFont(ArialMT_Plain_24);
    display.drawString(0, 26, "Hello world");
    }

    void drawTextFlowDemo() {
    display.setFont(ArialMT_Plain_10);
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawStringMaxWidth(0, 0, 128,
    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
    }

    void drawTextAlignmentDemo() {
    // Text alignment demo
    display.setFont(ArialMT_Plain_10);

    // The coordinates define the left starting point of the text
    display.setTextAlignment(TEXT_ALIGN_LEFT);
    display.drawString(0, 10, "Left aligned (0,10)");

    // The coordinates define the center of the text
    display.setTextAlignment(TEXT_ALIGN_CENTER);
    display.drawString(64, 22, "Center aligned (64,22)");

    // The coordinates define the right end of the text
    display.setTextAlignment(TEXT_ALIGN_RIGHT);
    display.drawString(128, 33, "Right aligned (128,33)");
    }

    void drawRectDemo() {
    // Draw a pixel at given position
    for (int i = 0; i < 10; i++) {
    display.setPixel(i, i);
    display.setPixel(10 - i, i);
    }
    display.drawRect(12, 12, 20, 20);

    // Fill the rectangle
    display.fillRect(14, 14, 17, 17);

    // Draw a line horizontally
    display.drawHorizontalLine(0, 40, 20);

    // Draw a line horizontally
    display.drawVerticalLine(40, 0, 20);
    }

    void drawCircleDemo() {
    for (int i=1; i < 8; i++) {
    display.setColor(WHITE);
    display.drawCircle(32, 32, i*3);
    if (i % 2 == 0) {
    display.setColor(BLACK);
    }
    display.fillCircle(96, 32, 32 - i* 3);
    }
    }

    void drawProgressBarDemo() {
    int progress = (counter / 5) % 100;
    // draw the progress bar
    display.drawProgressBar(0, 32, 120, 10, progress);

    // draw the percentage as String
    display.setTextAlignment(TEXT_ALIGN_CENTER);
    display.drawString(64, 15, String(progress) + "%");
    }

    void drawImageDemo() {
    // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
    // on how to create xbm files
    // display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
    }

    Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo};
    int demoLength = (sizeof(demos) / sizeof(Demo));
    long timeSinceLastModeSwitch = 0;

    void loop() {
    // clear the display
    display.clear();
    // draw the current demo method
    demos[demoMode]();

    display.setTextAlignment(TEXT_ALIGN_RIGHT);
    display.drawString(10, 128, String(millis()));
    // write the buffer to the display
    display.display();

    if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {
    demoMode = (demoMode + 1) % demoLength;
    timeSinceLastModeSwitch = millis();
    }
    counter++;
    delay(10);
    }
    Attachments:
    • ESP8266EX_D1_LOIN_D1_mini_PRO.zip (2.38 KB) You must be logged in to download this attachment.
  • #10 18503479
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #11 18504962
    JanuszKornas
    Level 11  
    Posts: 120
    Help: 6
    Rate: 25
    My ArduinoIDE does not ingest D1, D2, D3 etc.... I had to manually add the appropriate definitions to use D1, D2.... How do you guys make it elegant so that I don't have to type it in manually? Maybe I have something not installed in my environment that something is not being incorporated?
  • #12 18505226
    Anonymous
    Level 1  
  • #13 18505647
    JanuszKornas
    Level 11  
    Posts: 120
    Help: 6
    Rate: 25
    I have the "Generic ESP8266 Module" set up. Most of the examples I have looked at use D1....
  • #14 18506161
    Anonymous
    Level 1  
  • #15 19110455
    Aimeiz
    Level 16  
    Posts: 290
    Help: 2
    Rate: 20
    Hi.
    I have two esp8266 modules with integrated 128x32 OLED displays.
    The board out of the bag has the wifi scanner program pre-loaded and it works seamlessly.
    Unfortunately I am having problems using other programs.
    I have tried different libraries, used in different examples:
    Adafruit_GFX with Adafruit_SSD1306
    OLED.h
    SSD1306Wire.h

    Seemingly everything works, but the display goes out after a few seconds or so and you have to reset or even turn it on and off.
    Unfortunately I don't see an ESP8266 OLED board in the board set, so I tried Generic, ESP-12E, same effect.
    I can't find anywhere the source of this program, the wifi scanner that was preloaded, because there it worked without problems and after loading other programs still the same problem.

    I thought the programs were hanging up - stack overflow etc, but when the program has communication via serial, it works all the time, only the display goes out.
    I use SDA and SCL in the display declarations - it works, but the problem with going out is there.

    Any ideas?
  • #16 19110628
    Anonymous
    Level 1  
  • #17 19134406
    Aimeiz
    Level 16  
    Posts: 290
    Help: 2
    Rate: 20
    Hi.
    Bought two modules on Ebay last year.
    It is called:
    "ESP8266 Nodemcu WIFI Chip 0.91 inch OLED Display Screen CP2104 Board For Arduino".
    Dark coloured board. There are versions with a white board.
    Both behave in the same way. Original preloaded code - wifiscan works fine, so the module may work properly.
    OLED examples from the available libraries, both Adafruit and others available through the library manager behave similarly.
    The display either displays nothing or only for a short time and goes out.
    Nowhere could I find information about the library used in the preloaded program.
  • #18 19134566
    Anonymous
    Level 1  

Topic summary

✨ The discussion revolves around the operation of the ESP-12F OLED display integrated with the NodeMCU using the Arduino IDE. The user initially faced challenges in finding a compatible library for the OLED display, which is identified as an SSD1306 with a resolution of 128x64. Various responses suggested checking the I2C address, using specific pin configurations (D1 for SDA and D2 for SCL), and utilizing example codes from the manufacturer. The user encountered issues with library compatibility and pin definitions, leading to confusion over the correct GPIO numbering. Solutions included modifying the Wire.begin() function and using native GPIO numbering instead of D1/D2 designations. Additional users reported similar issues with different OLED sizes and libraries, emphasizing the importance of correct pin assignments and library usage for successful display operation.
Generated by the language model.

FAQ

TL;DR: SSD1306 OLEDs are 128×64; "supports a resolution of 128x64". Start with D-duino examples and set I2C pins correctly to fix no-display issues. [Elektroda, khoam, post #18490406]

Why it matters: For Arduino IDE users with ESP8266/NodeMCU + onboard OLED, this FAQ speeds up first-light by solving pin, address, and library pitfalls.

Quick Facts

What’s the correct resolution for the SSD1306 OLED on ESP-12F/NodeMCU?

SSD1306-based panels top out at 128×64. Treat any “168×64” spec as a listing error. Start from the D-duino example set to validate your wiring and library choices before customizing. This avoids mismatched buffer sizes and initialization issues in libraries. [Elektroda, khoam, post #18490406]

My I2C scanner shows “No I2C devices found.” How do I fix it on this board?

Set the scanner to the board’s pins by changing the bus init. “Change Wire.begin(), to Wire.begin(D1, D2).” How-To: 1. Open the I2C scanner. 2. Replace Wire.begin() with Wire.begin(D1, D2). 3. Upload and rescan. This directs I2C to the OLED’s lines. [Elektroda, khoam, post #18491604]

Which pins are SDA and SCL on the NodeMCU with integrated OLED?

On this module, SDA is D1 and SCL is D2. That is the opposite of many default ESP8266 tutorials. If you leave Wire.begin() unmodified, the display will not be detected. Map your library to these pins for reliable operation. [Elektroda, khoam, post #18490584]

What GPIO numbers correspond to D1 and D2 on this board?

D1 maps to GPIO5 and D2 maps to GPIO4. Setting your OLED library to use pins 5 (SDA) and 4 (SCL) made the sample sketches run successfully for users. This mapping resolves scanner failures and blank screens. [Elektroda, JanuszKornas, post #18491589]

Which Arduino libraries actually work with the onboard SSD1306?

The ThingPulse “ESP8266 and ESP32 OLED driver for SSD1306 displays” works once SDA/SCL are set to GPIO5/4. The D-duino repository examples also initialize correctly with those pins. Configure pins first, then test the bundled demos to confirm. [Elektroda, JanuszKornas, post #18491589]

Arduino IDE says D1/D2 are not defined. What should I do?

The Generic ESP8266 board package does not define D1–D8 constants. Use native GPIO numbers instead, or select a board variant that provides Dx aliases. “Dx designations are ambiguous” across boards, so GPIOx is safer. [Elektroda, khoam, post #18506161]

Do ESP8266EX and ESP8266MOD differ for OLED usage?

Functionally, no. ESP8266EX is by Espressif and ESP8266MOD was by AI-Thinker, but they behave the same for I2C OLED use. Choose pins and libraries based on the board layout, not the chip marking. [Elektroda, khoam, post #18503479]

What I2C address should I try first for the SSD1306?

Start with 0x3C, which many example sketches target for SSD1306 panels on ESP8266. If your scanner still shows nothing, revisit the Wire.begin(D1, D2) pin setup and re-run the scan. [Elektroda, xeank, post #18503329]

My 128×32 OLED turns off after a few seconds. How can I stop that?

Use the Heltec_ESP8266 library for those Heltec-style 128×32 boards. Users report the preloaded WiFi scan works, but other libraries blank the OLED. Switching to Heltec’s package stabilizes operation. [Elektroda, khoam, post #19134566]

Can I remap I2C to other pins, like D3 and D5, on some boards?

Yes. ESP8266 I2C is software-defined. Some modules and examples wire OLED as SCL=D3 and SDA=D5. Update your library’s constructor or Wire.begin accordingly and test with the demo. [Elektroda, xeank, post #18503329]

Where can I find working example code for this specific OLED board?

Use the D-duino Arduino-examples repository suggested in the thread. Those sketches match the integrated OLED wiring and initialize SSD1306 correctly when pins are set. Start there for a known-good baseline. [Elektroda, khoam, post #18490406]

Why does the I2C scanner still fail after setting pins?

An I2C scanner only finds devices that are correctly on the bus. Verify the OLED is powered and connected to the same I2C lines you initialized in code. Then re-run the scan. [Elektroda, vieleicht, post #18492123]

What serial baud rate should I use in demos and scanners?

Set the Serial Monitor to 115200 baud to match the shared example code. Mismatched baud settings can look like random garbage or no output, confusing debugging. [Elektroda, xeank, post #18503329]
Generated by the language model.
ADVERTISEMENT