Introduction: 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.
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.
5 Comments
2 years ago
I have not reached that level, I rely heavily on finding something close to what I am looking to do, and then make the changes I need to make it work. I spend hours and hours learning from others....Instructables is AWESOME! There just aren't enough hours in the day to learn and create the way I would like to.
I am very impressed with your skill set, and your presentation here on Instructables.
Please keep sharing your knowledge; it is greatly appreciated.
Have you worked much with the ESP32 / ESP8266 or the WeMos D1? They are my "go To" now...but I am working on a project with a 555 timer...and no micro. It is fun to play with toys from years ago. It does use a TP4056 and a 18650 battery though...gotta love that combo now. It was hard not to reach for the ATTiny85 this time...it is such a problem solver for many small projects.
Bob D
Reply 2 years ago
Hi Bob :) this is great I've never had such great feedback on my projects.
Yes I've played around with the ESP32 and the WeMos D1. They're great I agree, but often now my goto device is the PSoC from Cypress. it is quite cheap and I love that it allows you to build digital circuits.
The ATTiny is cool, but often I don't like the 30s lag after power-up while it checks for a bootloader connection :/
Reply 2 years ago
I just looked up the Cypress PSoC, looks neat...but for my skill set I will stick with the Arduino environment. I am hoping to find some time today to get to the hobby bench and play around some more. Mind you the weather is supposed to be unseasonably warm today, so I better enjoy that as much as I can. Take care!
Bob D
2 years ago
I can't believe that there are no other comments...this is very interesting. I have used the SSD1306, and it is a great display. That is one on my signature photo actually. I will be checking out the rest of your Instructables.
Thanks for sharing,
Bob D
Reply 2 years ago
I guess most people are more than happy to use the provided libraries. Typically I like to write my own code for all my projects and try to get the most out of my micro :D