Adafruit OLED display buffer screenshot save to file

I am using the Adafruit monochrome 2.7" display which uses the SSD1325.
I really wanted a way to get what is on the display out to an image file that I can then put in the documentation. Taking a photo of the screen is not so great.

This could also be useful if you are starting a project but don't have your hands on the display yet. These instructions are for an SSD1325 display but should transfer easily to other displays like the SSD1306

Thought I would share what I came up with and share the code here.

This adds a short piece of code to the Adafruit_SSD1325 library so that in your code you can put:

display.display();
display.dumpPBM();  //Dump the display buffer to console

The dumpPBM() method is what we add to the library. When called it writes the content of the display buffer to the serial console in Portable BitMap format which is a really simple file format and only contains printable characters.

The output looks like this:

P1
# OLED display buffer
128 64
1111111111111111111111111111111...... truncated
......64 rows of 1 and 0

Copy this output into a text editor and save it as something.pbm then open this in Gimp or other graphics program that supports Portable BitMap.

Example output:
screenshot

To add the code to the library, go to the libraries folder then inside Adafruit_SSD1325.
Open the .h file and add the line

void dumpPBM();

I put it below drawPixel
Open the cpp file and add the following. I put it after clearDisplay

// write PBM format of buffer
void Adafruit_SSD1325::dumpPBM(void) {
  Serial.println("P1");
  Serial.println("# OLED display buffer");
  Serial.print(SSD1325_LCDWIDTH);
  Serial.print(" ");
  Serial.println(SSD1325_LCDHEIGHT);
  for (uint8_t y = 0; y <= 63; y++) {
    for (uint8_t x = 0; x <= 127; x++) {
      if (bitRead((buffer[x + (y / 8) * SSD1325_LCDWIDTH]), (y % 8))) {
        Serial.print("0");
      } else {
        Serial.print("1");
      }
    }
    Serial.println(" ");
  }
}

That is it. You can now put the new display.dumpPBM(); into your code and create an image bit perfect to what is on the screen. Swap the 1 and 0 in the Serial.print to swap black and white.
I'm sure that with very few changes this should also work on other monochrome OLED such as the Adafruit 0.96" which uses the SSD1306 library

Hope this works for you and saves you some time

..a small update. If what you want is to see a representation of the display buffer in the terminal you can change print 0's and 1's to printing a space and the unicode character for full block \u2588 which exists in the consolas font used at least on Windows 11.

Change the Serial.print() in the above code snippet to:

if (bitRead((buffer[x + (y / 8) * SSD1325_LCDWIDTH]), (y % 8))) {
        Serial.print("\u2588");
      } else {
        Serial.print(" ");
      }

Then the serial console will display a quite readable representation of the display buffer directly that looks something like this:

1 Like

ingenious :+1:

Suggestion, have a 2nd argument to the function that specifies where to direct the output, instead of using Serial in the function. That would allow you to output to either Serial or an SD card, since printing on both inherits from the Stream class.

Don't you need to modify the .h file also?

The change to the .h file is in the line above.
My thoughts are that this comes under the category of quick hack rather than a fully functional request to extend the official library.

Oops, I read over it too quickly.