2

Description

I'm currently trying to get this SSD1306 0.91" OLED screen with an Arduino Nano with the U8G2 library (as per seller's guide), and in any code I run, as soon as a delay() is executed, the screen goes blank and doesn't show any further text or image.

What is the possible cause?

Wiring

enter image description here

Code

To first make sure the OLED module works, I'm using one of the HelloWorld examples from the U8G2 library, from which (with comments removed) I'm executing the next code:

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);


void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();                   // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr);   // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
  delay(1000);  
}

Expected Result

The OLED Screen should always show "Hello World!" text, as per this youtube video with the same setup.

Actual Result

At startup, it shows the "Hello World" text for a fraction of a second and it disappears.

I've found out that as soon as the delay() is executed, screen goes blank forever and doesn't reload any text. I don't want this approach if possible since:

  • I plan on using a battery to power the Arduino and the screen, and a permanent screen refresh would decrease autonomy
  • When doing so, the screen is a little bit flickery.

Troubleshooting executed

  1. I used a different Arduino Nano, and result was the same.
  2. I'm using a 5V 2A power supply for the entire circuit.
  3. I tried different U8G2 example sketches, with the same result (only working if no delay()).
  4. I tried using another OLED module of the same specs, and result is the same.
  5. I've tried to use Adafruit SSD1306 library, and screen doesn't show anything.
jsotola
  • 1,249
  • 2
  • 10
  • 18
Markussen
  • 21
  • 3
  • What I can tell you is that if I substitute an UNO for your Nano (which should make no difference) and an x64 display for your x32 display (which may make a difference, but I doubt it), your code works verbatim. It does not blank the display. I can modify it to display a counter and it counts as predicted. Include version numbers of everything involved (ide, libraries, core) and links to your actual display and arduino board. – timemage Nov 13 '22 at 19:27
  • Well. I found my display that's appears to be identical to what you have (assuming what you really have is what you linked) and it continues to work. There is a minor difference in how it displays, but it still essentially works as expected. So, add details. – timemage Nov 13 '22 at 20:16
  • I do see something a little odd here - the screen is being redrawn every second since you have that code in loop(). But that should still show the text again too, even if it's refreshed. Does this still happen if *only* the delay is left in loop and the rest is moved to setup()? – RDragonrydr Nov 16 '22 at 19:14
  • Thanks a lot. In the last week I had little time, but I'll do a test later today and come back with further findings and update this comment/post. – Markussen Nov 22 '22 at 13:52
  • Just did some additional testing and here's some more info: + IDE's: tried with Arduino IDE 2.0.1 and VSCode 1.73.0 with Arduino extension v0.4.12 - Just tested with an original Uno and same result. - If I put a delay(50), the screen keeps the HelloWorld! word although blinking is more visible. - Moving everything except delay() or delay(50) to setup results in the same behavior (it shows HelloWorld for a fraction of a second and screen goes blank). – Markussen Nov 22 '22 at 23:57
  • I finally found the root cause. I was using a breadboard for this setup, and as soon as I took the components out and used different cables, everything started working as expected. **Lesson learnt: do not always rely on the breadboards being 100% functional; when everything else fails, remove the breadboard from the equation.** – Markussen Dec 05 '22 at 21:57

0 Answers0