logo elektroda
logo elektroda
X
logo elektroda

[Solved] [Arduino] SSD1306 flashes after adding Deep.sleep/Blynk

pier 3078 38
Best answers

Why does my SSD1306 OLED flash or go blank when I add Deep.sleep or Blynk to an ESP8266 sketch, even though it works without them?

The problem was not the OLED itself in the end: updating the ESP8266 board package fixed the flashing/blank display and the sketch then worked correctly with Blynk and deep sleep [#18536670][#18542924] Earlier in the thread, one likely cause was that some newer SSD1306 modules need a much longer startup delay before initialization, around 400 ms or more [#18530830] Another important point was that `display.begin(SSD1306_SWITCHCAPVCC, 0x3C)` can call `Wire.begin()` again on the default I2C pins, so if you already do `Wire.begin(D5, D6)` you should use the variant that does not reinitialize Wire [#18531538] In short, try updating the ESP8266 core first; if the issue persists, check OLED startup delay and I2C initialization/pins [#18530830][#18531538]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18529612
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    Hello.
    Colleagues please help as I have no strength left.

    Tell me what is wrong in this code that as soon as I add Deep.sleep or initiate Blynk, the display only flashes and displays nothing. Without these functions it works normally and shows measurements from the sensor.


    Code: C / C++
    Log in, to see the code
    .

    Added after 4 [hours] 23 [minutes]:

    I've come to the realization that some strange display has hit me. The same program uploaded to another board works with deep.sleep and with Blynk without any problems.
    Do you know what the issue is with this display?
  • ADVERTISEMENT
  • #2 18530364
    Marek_Skalski
    VIP Meritorious for electroda.pl
    Posts: 1338
    Help: 114
    Rate: 1044
    And isn't this display from the new series? They need a much higher initialisation delay. Without this, they either display nothing or just flash the image and everything disappears.
  • #3 18530466
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    Marek_Skalski wrote:
    And isn't this display from the new series? They need a much higher initialisation delay. Without that they either display nothing, or just flash an image and everything disappears.
    .
    Not sure about the new series bought this week.
    So does it initialise and give delaja or how to do it? Some new library maybe?
  • #4 18530486
    Anonymous
    Level 1  
  • #5 18530511
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    Do you have the pin from the display reset connected to the ESP?
    Code: C / C++
    Log in, to see the code
    .

    This is an I2C display with only four pins, no reset.
  • ADVERTISEMENT
  • #8 18530830
    Marek_Skalski
    VIP Meritorious for electroda.pl
    Posts: 1338
    Help: 114
    Rate: 1044
    New type display:
    [Arduino] SSD1306 flashes after adding Deep.sleep/Blynk .

    Display of old type:
    [Arduino] SSD1306 flashes after adding Deep.sleep/Blynk

    The main differences are:
    - the size of the display itself (the new one is smaller)
    - width of the ribbon connecting the display to the board - the new one is narrower
    - number of components on the board - the new one has less
    The old ones start immediately (< 50 ms from power on). The new ones need (in my case) > 400 ms. I bought some of the new ones and thought they were defective. But I was surprised to find that after a reset of the circuit they work without any problem. A while later I figured out that the chip needs more time to start. In tests it came out > 400 ms.
  • #9 18530954
    Anonymous
    Level 1  
  • #10 18530994
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    I have an old-style display.

    Khoam nothing is achieved by these treatments. After a reset the image shows for a while and disappears....
  • #11 18531015
    Anonymous
    Level 1  
  • #12 18531179
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    pier wrote:
    After a reset the image shows for a while and disappears...
    .
    If with the ESP.deepSleep() command at the end of the loop() then I'm not even surprised and I already wrote you about it in another thread.
    pier wrote:
    that as soon as I add Deep.sleep or initiate Blynk the display just flashes and displays nothing.
    .

    Khoam then where do I place deep.sleep?
    I put the Blynk initialisation in the setup as you suggested. In general eggs are happening with this display. Wherever I give delay(); for a test, the display is already dead. The rest of the program i.e. BME280, Blynk, Thingspeak are working fine.
  • ADVERTISEMENT
  • #14 18531232
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    Blynk.run() should be in loop():
    https://examples.blynk.cc/?board=ESP8266&...0WiFi&example=GettingStarted%2FBlynkBlink

    ESP.deepSleep() should not be called after every loop() run, but only when you decide to do so and it makes sense. When you return from deep-sleep, the program executes from the beginning, as after a reset.


    Yes Blynk.run() I have in loop().

    And now it's like this, when I use the Deep.sleep function the display shows the correct image for a while and that's it, but when I initialise the Blynk the display is completely dead. I don't understand any of this.

    I don't know how to use ESP.deep.sleep. I read the sensor, display the measurements on the lcd, send to the server and put ESP to sleep why should I spin the loop more times?
  • #15 18531359
    Anonymous
    Level 1  
  • #16 18531390
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    pier wrote:
    I read the sensor, display the measurements on the lcd, send to the server and put the ESP to sleep why should I spin the loop more times?
    .
    This will be a problem because Blynk.run() requires this "spinning" in loop().


    Well, not really. Already that two years I have a weather sensor that works according to what I wrote. Now I wanted to make a second one and such eggs I have with this display.
  • #17 18531538
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #18 18531822
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    There is one more thing. In the code you call Wire.begin(D5,D6) because of the pin change for I2C. However, display.begin(SSD1306_SWITCHCAPVCC, 0x3C) also calls Wire.begin(), but already for the default I2C pins (D1, D2). So try changing this call to:
    Code: C / C++
    Log in, to see the code
    The last parameter (false) means that Wire.begin() will not be called again.
    .

    I checked for peace of mind but just as I thought it didn't change anything. I repeat the display works if there is no lag, blynk or sleep in the code. For some unknown reason the problem for this display is any delay in the code, just give a delay(); greater than 10 anywhere in the code and already the display is silent.
    Khoam probably needs to consider that this display is some kind of junk, damaged or has some clone of the SSD1306 driver, give up on it and buy a new one.
  • #19 18532111
    Anonymous
    Level 1  
  • #20 18532168
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    pier wrote:
    Khoam probably need to consider that this display is some kind of junk, defective or has some clone of SSD1306 driver, give up with it and buy a new piece.
    .
    If you buy a new display and the problem remains, then we'll probably be back on topic.;)


    And didn't I write you that after uploading this program to another board with another copy of the display everything works as expected. I might be tempted to swap the lcd itself then it will be 100% sure.
  • #21 18532177
    Anonymous
    Level 1  
  • #22 18532404
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    Code: C / C++
    Log in, to see the code
    .


    Blynk.begin, Blynk.run() and ESP.deep.sleep are commented out because enabling any of them results in the display not working.

    Added after 8 [hours] 37 [minutes]:

    I still tried uploading a sample program from the library examples. Of course I changed the SCL SDA pins and what the display does not display anything.
  • #23 18534148
    Anonymous
    Level 1  
  • #24 18534524
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    I connected another copy of the display to this board and it works as expected and blynk and deep.dleep.
    The conclusion is that these two-colour displays are kind of weird.
    As it turns out, I'm not the only one who has a problem with this display Link .

    I also did a trial with adding pullups on the data lines, with no effect.
  • #25 18534898
    Anonymous
    Level 1  
  • #26 18535562
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    When the display is not working, does the message "SSD1306 allocation failed" appear in the serial port monitor?
    .

    I'm not likely to see such a message, the question is still what speed do I set the transmission to?

    But the eggs continue with this display. I've been playing around with the other display for a while, now I've plugged in the faulty one to check that message you wrote about and miracle works with Blynk! In the code I just added the display of one character more. But with sleep it still doesn't work? My hands are falling off.

    Code: C / C++
    Log in, to see the code
    .
  • #27 18535730
    Anonymous
    Level 1  
  • #28 18535756
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    It should rather be:
    Code: C / C++
    Log in, to see the code
    .

    It starts to work and with sleep, although the display does not always get up after deep.sleep.

    What does this UL give?
  • #29 18535765
    Anonymous
    Level 1  
  • #30 18535806
    pier
    Level 24  
    Posts: 2446
    Help: 40
    Rate: 1892
    khoam wrote:
    pier wrote:
    What does this give UL?
    .
    The fact that the result of the operation will then be a uint64_t, not an int.
    Code: C / C++
    Log in, to see the code


    Added after 13 [minutes]:

    pier wrote:
    although the display doesn't always get up after deep.sleep.
    .
    And what does this mean specifically? Are you sure the ESP8266 itself is awake?
    .

    More likely the whole thing is catching a hang because there are no further resets.
  • Topic summary

    ✨ The discussion revolves around issues faced when integrating the SSD1306 OLED display with an ESP8266 microcontroller while using Blynk and Deep Sleep functions. Users report that the display only flashes or shows nothing when these functions are added, despite working correctly without them. Suggestions include ensuring proper initialization delays for the display, checking I2C connections, and adjusting I2C speeds. It was noted that newer SSD1306 displays may require longer initialization times. The problem persisted until a board update resolved the issues, allowing the display to function correctly with Blynk and Deep Sleep.
    Generated by the language model.

    FAQ

    TL;DR: New SSD1306 I2C OLEDs need >400 ms startup delay—8× longer than earlier 50 ms panels [Elektroda, Marek_Skalski, post #18530830] "They either display nothing or just flash" [Elektroda, Marek_Skalski, post #18530364] Upgrading ESP8266 core to 2.6.3 and using ESP.deepSleep(...UL) fixed the flicker [Elektroda, pier, post #18536670]

    Why it matters: Correct timing, wiring and firmware cut boot failures and display flashing to zero.

    Quick Facts

    • ESP8266 Arduino core: use v2.6.3 or newer [Elektroda, khoam, post #18536243] • New-series SSD1306: require >400 ms power-on delay [Elektroda, Marek_Skalski, post #18530830] • Default Adafruit I2C clock is 400 kHz; 50-100 kHz improves stability [Elektroda, khoam, post #18530954] • deepSleep argument must be uint64_t: e.g. 1 800 000 000 µs (30 min) [Elektroda, khoam, post #18535765] • For auto-wake, connect GPIO16 (D0) to RESET [Elektroda, khoam, post #18535909]

    1. Why does my SSD1306 screen blink or stay blank after adding ESP.deepSleep() or Blynk?

    The new display boots slower than your code. When deepSleep() or Blynk adds even a 10 ms delay, the OLED misses its first commands and shows only a flash [Elektroda, pier, post #18531822] Add a >400 ms startup delay or initialise the display after Wi-Fi/Blynk and use the UL suffix in deepSleep().

    3. Which ESP8266 core version stops the flicker with deep sleep?

    Updating the Arduino ESP8266 core to v2.6.3 removed all overnight crashes and display issues [Elektroda, pier, post #18536670]

    4. What is the correct way to call ESP.deepSleep()?

    Pass a 64-bit value: ESP.deepSleep(sleepTimeS * 1 000 000UL); The UL forces 32-bit multiplication to promote to uint64_t, matching the function signature [Elektroda, khoam, post #18535765]

    5. Do I need to link GPIO16 to RESET for deep sleep?

    Yes. GPIO16 toggles LOW at the wake-up time; wiring it to RESET lets the ESP8266 reboot automatically [Elektroda, khoam, post #18535909]

    6. How can I slow I2C to stabilise the display?

    Use the extended constructor: Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1, 100000UL, 100000UL); Lowering the clock to 50–100 kHz reduces missed bytes on bit-banged ESP8266 I2C [Elektroda, khoam, post #18530954]

    7. The display dies after any delay(); why?

    Delay() postpones I2C writes while power stays on. The OLED waits only ~100 ms for commands; longer gaps (>10 ms observed by the author) make it time out and turn off [Elektroda, pier, post #18531822]

    8. Can repeated Wire.begin() calls break the OLED?

    Yes. display.begin() implicitly calls Wire.begin() on default pins (D1, D2). If you already ran Wire.begin(D5, D6), the bus jumps pins and communication stops [Elektroda, khoam, post #18531538] Pass the “false” flag to skip the second call.

    9. What constructor should I use for an I2C SSD1306 on custom pins?

    1. Wire.begin(SDA_pin, SCL_pin);
    2. define OLED_RESET -1

    3. Adafruit_SSD1306 display(128,64,&Wire,OLED_RESET,100000UL,100000UL); This matches the new library API and lets you set clock speed [Adafruit Docs].

    10. Are two-colour (yellow/blue) OLEDs less compatible?

    Some two-tone clones report incompatible controller IDs and ignore certain commands, causing random blanking despite correct wiring [Elektroda, pier, post #18534524]

    11. How do I know if the driver RAM failed to allocate?

    Open Serial Monitor. If you see “SSD1306 allocation failed”, the ESP8266 could not reserve the 1024-byte buffer (12 % of available RAM) and the screen will stay dark [Elektroda, khoam, #18534898; Adafruit].

    12. Quick 3-step: debug a blank SSD1306 on ESP8266

    1. Check 3V3, GND, SDA, SCL continuity and 4.7 kΩ pull-ups.
    2. Upload I2C scanner; confirm address 0x3C.
    3. Add Serial.print after display.begin(); if message appears but screen stays blank, insert a 500 ms delay then clear/display again [Elektroda, Marek_Skalski, post #18530830]
    Generated by the language model.
    ADVERTISEMENT