0

Why does the OLED display flicker when using the SSD1306Ascii.h library? The Adafruit library does not have this issue, but I've been told uses a lot of memory and so I'm trying to use Ascii to conserve memory resources. The problem manifests itself when the void loop() begins. When using similar code with the Adafruit library, the display stays steady as a rock.

Here is my example code. many thanks in advance.

// Edit AVRI2C_FASTMODE in SSD1306Ascii.h to change the default I2C frequency.

#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"

#define I2C_ADDRESS 0x3C

// Define proper RST_PIN if required.
#define RST_PIN -1


SSD1306AsciiAvrI2c oled;
//------------------------------------------------------------------------------
void setup() {

#if RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
  // Call oled.setI2cClock(frequency) to change from the default frequency.

  oled.setFont(System5x7);
  oled.clear();
  oled.print("Hello World!");
  delay(2000);
  oled.clear();


}
//------------------------------------------------------------------------------
void loop() {

  oled.setFont(System5x7);
  oled.print("Hello fuuuzzzzyyyy world!");
  delay(1);
  oled.clear();

}
6
  • how do you know that the problem is caused by the library?
    – jsotola
    Commented Aug 27, 2019 at 0:34
  • what debugging have you done?
    – jsotola
    Commented Aug 27, 2019 at 0:34
  • I've played around with the frequency settings which speeds up or slows down the flicker, but like I say the more common Adafruit library doesn't produce this effect when running through the loop. I'm pretty new to this so any guidance is much appreciated.
    – paul1066
    Commented Aug 27, 2019 at 9:19
  • Also, i think there may be ways around it using other methods in the library to only manipulate the areas where a value is changing, but it will get messy...
    – paul1066
    Commented Aug 27, 2019 at 9:20
  • don't run clear(). make an array that fits the screen, fill the array as needed with data (don't forget to write spaces for blanks), and write the whole array to the screen each time.
    – dandavis
    Commented Aug 27, 2019 at 21:07

2 Answers 2

1

Your loop is repeatedly writing and clearing the display, nearly as fast as possible (minus the 1ms delay at the bottom), which is the reason for the flicker you're seeing. If instead, you only update the display when something changes, it will look much smoother. Even a clear-and-rewrite the entire display when something changes (assuming the changes are infrequent) will be a major improvement. Of course this assumes you'd eventually be writing dynamic data; your test program, of course, writes and re-writes static data.

Update:

If I run the same code structure with Adafruit library there is no flicker, even with no delay in the loop.

Can you compare the two libraries to see what they do differently?

The Adafruit library does not have this issue, but I've been told uses a lot of memory

There's a likely clue: Adafruit may be buffering the display contents in memory so it can find out which character positions changed and update only those. That would be a classic time/space trade-off.

1
  • I'm displaying values from a Gyro so needs to update continually. If you set the delay to 1 second, there is still a noticeable flicker as the display refreshes. If I run the same code structure with Adafruit library there is no flicker, even with no delay in the loop.
    – paul1066
    Commented Aug 27, 2019 at 19:13
0

Yes, it's due to rewriting the whole display. I generally only rewrite portions that have changed or at worst use the ClearToEOL command to make sure everything's obliterated.

1
  • 1
    You could only rewrite those parts of the display that change which is the gyro value
    – Sim Son
    Commented Dec 5, 2019 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.