Driving an OLED SSD1306 Display

Want to use your SSD1306 display with just a few lines of code?

Sometimes you just need the basics, or want to use a different micro. The aim of this project was to drive the display using just the Wire.h library on Arduino, or by implementing i2c on another micro (PIC for my particular application). The library may be too large or simply takes too much time to go thru and translate.

Using a protocol analyzer I copied the init routine for the display, then proceeded to generate graphics for it.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Creating Images for the Display

This is the init routine for the display:

void config_lcd() {<br>  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xae);
  Wire.write(0xd5);
  Wire.write(0x80);
  Wire.write(0xa8);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0x1f);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xd3);
  Wire.write(0x00);
  Wire.write(0x40);
  Wire.write(0x8d);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0x14);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0x20);
  Wire.write(0x00);
  Wire.write(0xa1);
  Wire.write(0xc8);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xda);
  Wire.write(0x02);
  Wire.write(0x81);
  Wire.write(0x8f);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xd9);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xf1);
  Wire.endTransmission();
  //
  Wire.beginTransmission(0x3c);
  Wire.write(0x00);
  Wire.write(0xdb);
  Wire.write(0x40);
  Wire.write(0xa4);
  Wire.write(0xa6);
  Wire.write(0x2e);
  Wire.write(0xaf);
  Wire.endTransmission();

}

To create and edit graphics I used some html and Javascript, the app generates the hex array to paste into the code. It also has a text field where you can paste in an array and view it graphically... otherwise all your work would be lost when you close the browser.

The file is included as a .txt, as .html was blocked.

Please keep in mind there's little to no error checking, as the app is designed to be used a certain way, but you can edit the code to meet your needs.

I found out later that the data is arranged differently in the default image provided by the library, maybe it's a part of the initialization i left out.

If anyone wants me to edit the code to be able the edit and save to the same format, please let me know in the comments!.

Hope this is useful to someone.

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions