I've created a few stand alone Python modules to help drive the SSD1306 and SSD1331 chipsets using the SPI. The primary reason was just to tinker, but I thought others could benefit from these too (I've already had a few requests on this forum and others). I also feel that these single file modules are a little easier, than trying to juggle Adafruit's GFX and OLED driver libraries together.
After wiring up a SSD1306 chipset, all you need to do is create an instance of the SSD1306 class specifying the GPIOs for the CS, D/C, and Reset pins. Then call the required member functions to draw your primitives, and finally call the Flip() member function to send the internal pixel buffer to the display.
Example output from an ASCII font test:
Code: Select all
device = SSD1306(SSD1306_PIN_DC, SSD1306_PIN_RST, SSD1306_PIN_CS) try: device.EnableDisplay(True) device.Clear() device.DrawCircle(20, 32, 16) device.DrawTriangle(47, 48, 79, 48, 63, 16) device.DrawRect(90, 16, 122, 48) device.Flip() time.sleep(60) device.EnableDisplay(False) finally: device.Remove()
Please note that the SSD1306 used for testing has two pages (16 pixel rows) of yellow/orange pixels along the bottom (or top) of the display.
The Python source code can be found here: https://gist.github.com/TheRayTracer/33 ... 4beac9cc37
If you are using a SSD1331 chipset, then you are in for more fun. Colours are supported! Again, after wiring up a SSD1331 chipset, all you need to do is create an instance of the SSD1331 class specifying the GPIOs for the CS, D/C, and Reset pins. Same as before, right? Then call the required member functions to draw your primitives (this time many of them are hardware accelerated).
A quick example:
The Python source code can be found here: https://gist.github.com/TheRayTracer/dd ... ecb9b8b47f
Code: Select all
device = SSD1331(SSD1331_PIN_DC, SSD1331_PIN_RST, SSD1331_PIN_CS) try: device.EnableDisplay(True) device.Clear() time.sleep(0.01) # Allow some time for the screen to wipe clean. device.DrawStringBg(18, 4, "Shape Test", COLOR_BLACK, COLOR_WHITE) device.DrawCircle(16, 32, 10, COLOR_RED) device.DrawTriangle(38, 42, 58, 42, 48, 22, COLOR_GREEN) device.DrawRect(70, 22, 90, 42, COLOR_BLUE) time.sleep(60) device.EnableDisplay(False) finally: device.Remove()
Within the source code I've also included the beginnings of a Space Invaders game to demonstrate usage of the above SSD1331 module. At the moment the game is all AI controlled and is non-interactive.
All of this is a work in progress, and I'll provide updates as they are made. Suggestions, comments, and questions are more than welcome.