SSD1306Ascii icon indicating copy to clipboard operation
SSD1306Ascii copied to clipboard

clear() takes 60ms.

Open MintSoup opened this issue 7 years ago • 7 comments

oled.clear takes about 60ms to clear the display, using an I2C 128x64 from ebay. This causes horrible flickering problems. Is it possible to speed this up?

MintSoup avatar May 05 '18 11:05 MintSoup

The controller has no command to clear display memory so the clear requires writing 512 bytes.

For I2C the limit is the speed of the Wire library.

60 ms sounds about right for 100 kHz. At 400 kHz it's about 24 ms.

An SPI display at 8 MHz clears in about 4 ms.

greiman avatar May 05 '18 16:05 greiman

Hmmm... not sure, but I think I was using 400khz. Will confirm tomorrow.

MintSoup avatar May 05 '18 17:05 MintSoup

I tried clear() on a ebay 128x64 and I get 46.3 ms. at 400kHz. An ebay SPI display clears in 8.1 ms.

I will experiment a bit more. I may have tested with a processor faster than an Uno. or a 128x32 display.

greiman avatar May 06 '18 12:05 greiman

Looks like optimizing clear() won't gain much. Here is a "fastClear" function that avoids the layered implementation. It takes 40.3 ms to clear the ebay display vs 46.3 for the more general clear() that clears any size region of any size display with I2C or SPI.

void fastClear() {
  for (uint8_t r = 0; r < 8; r++) {
    // set row to clear
    oled.setCursor(0, r);
    // Wire has 32 byte buffer so send 8 packets of 17 bytes.
    for (uint8_t b = 0; b < 8; b++) {
      Wire.beginTransmission(I2C_ADDRESS);
      Wire.write(0X40);
      for (uint8_t i = 0; i < 16; i++) {
        Wire.write(0);  
      }
      Wire.endTransmission();
    }
  }
  oled.setCursor(0, 0);
}

greiman avatar May 06 '18 13:05 greiman

I've got this problem as well, i have shifting lengths of text on an I2C 128x64 and it doesn't clear the leftover characters when the lines get shorter, except if i use oled.clear(); which makes the display flicker.

i have tried using oled.clear(Columnstart,Column...); but that just makes the small part selected flicker because of my rather short update delay.

Would it be possible to make an oled.clearram(); or something like that? Where it just clears the ram buffer, but doesn't update the display. Then you can fill the ram again with new stuff and then update the display.

Souji911 avatar Aug 02 '19 19:08 Souji911

I repeat. There is no fast memory clear command for the SSD1306. oled.clear() must write blanks to all locations in the SSD1306 memory so it takes a long time.

To reduce flicker, write blanks over the extra characters in each line. Also only write portions of the display that change.

clearField() and clearToEOL() clear a portion of the display.

SPI displays clear much faster so the flicker is less noticeable.

See various other posts about this issue. Others have proposed work arounds.

greiman avatar Aug 03 '19 13:08 greiman

Thanks for your answer! I actually got it working a short while after posting, using the "blanks after text" example and it works the charm!

Souji911 avatar Aug 03 '19 21:08 Souji911