SPKDisplay - A mbed display class and processing imaging tools for 128x64 OLEDs using the SSD1305 driver, connected via SPI. This variant drives a Unigraphics oled on the same driver but in page mode. Includes a simple 5x7 ascii font

Dependents:   univision_oled

Fork of spk_oled_ssd1305 by Toby Harris

OLED driver and demo for Univision oled display 128x64.

/media/uploads/pegcjs/_scaled_20130128_133126.jpg

Modified Toby Harris' code to run page mode addressing in 4 wire SPI on the Univision UG-2864HSWEG01 128X64 unit - often found for sale on ebay. That's where I got mine anyhow.

Wiring this was fairly straightforward but you really do have to ground all the unused pins EXCEPT for number 8 to get it to work.

Here's the layout - I made a little carrier using a 2x8 connector and a couple of headers mounted on a small piece of stripboard. You can see all the wire links that are used to ground the unused pins. It was pretty awkward setting the display to run in 4 wire spi - had to desolder and resolder three smd o ohm links on the back o fhte pcb - ended up using a microscope to see them.

/media/uploads/pegcjs/_scaled_layout.jpg

Here is the output of the demo code.

/media/uploads/pegcjs/_scaled_itworks.jpg.jpg

In page mode the display is effectively divided up into 8 horizontal strips, each 8 pixels high so lends itself nicley to displaying text in a 5x7 font. I've included the 5x7 lcd font in the code below.

Code

Import programunivision_oled

driver demo for univision oled dispaly

#include "mbed.h"
#include "4spi_oled_ssd1305.h"

/* re writtten to cope with teh ssd1306 driven oled UG-2864HSWEG01 from univision
wiring for test circuit
OLED pins -FUNCTION-------MBED PINns
1 ----3.3V--- Vout (p40)
2 ----0.0V--- GND (p1)
3 ----------- GND (p1)
4 ----------- GND (p1)
5 ----------- GND (p1)
6 ----------- GND (p1)
7 ----------- GND (p1)
8 ----------- N/C
9 ----D1---- mosi (p5)
10 ---D0------sck(p7)
11 ----------- GND (p1)
12 ----------- GND (p1)
13 ---DC------ p10
14 ---RES----- p9
15 ---CS------ p8
*/



DigitalOut myled(LED1);

// Create object and load font
//SPKDisplay( mosiPin, clkPin,  csPin,  dcPin, resPin, Serial *debugSerial)
SPKDisplay screen(p5, p7, p8, p10, p9);
int main()
{
    char msg[22];
    sprintf(msg,"                      ");
//           01234567890abcdefghij

    int i=0;
    while(1==1) {
        myled=1;
        // nice logo output
        screen.welcome();
        wait(3);

        wait(2);
        for(i=0; i<5; i++) {
            myled=0;
            screen.inverse();
            wait(1);
            screen.normal();
            myled=1;
            wait(1);
        }

        screen.fontdemo();
        myled=0;
        wait(5);
        screen.clearBuffer();
        screen.sendBuffer();
        myled=1;
        wait(0.5);
        myled=0;
        wait(0.5);

        for(i=0; i<8; i++) {
            sprintf(msg,"HELLO WORLD %d",i);
            screen.textToBuffer(msg, i);
            screen.sendBuffer();
            screen.clearBuffer();
            myled=1;
            wait(1);
        }
    }


}
Committer:
tobyspark
Date:
Sun Apr 15 19:48:11 2012 +0000
Revision:
2:8187d69071f8
Parent:
1:dd3faa2ab1dd
Child:
3:ade83210ecf6
Documentation update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 0:76bb084fa033 1 // OLED display using SSD1305 driver
tobyspark 0:76bb084fa033 2 // Copyright *spark audio-visual 2012
tobyspark 1:dd3faa2ab1dd 3 //
tobyspark 1:dd3faa2ab1dd 4 // This library is free software; you can redistribute it and/or
tobyspark 1:dd3faa2ab1dd 5 // modify it under the terms of the GNU Lesser General Public
tobyspark 1:dd3faa2ab1dd 6 // License version 3 as published by the Free Software Foundation.
tobyspark 0:76bb084fa033 7
tobyspark 0:76bb084fa033 8 #ifndef SPK_OLED_SSD1305_h
tobyspark 0:76bb084fa033 9 #define SPK_OLED_SSD1305_h
tobyspark 0:76bb084fa033 10
tobyspark 0:76bb084fa033 11 #include "mbed.h"
tobyspark 0:76bb084fa033 12 #include <string>
tobyspark 0:76bb084fa033 13
tobyspark 0:76bb084fa033 14 #define bufferCount 1056
tobyspark 0:76bb084fa033 15 #define bufferWidth 132
tobyspark 0:76bb084fa033 16 #define pixelWidth 128
tobyspark 0:76bb084fa033 17 #define pixelHeight 64
tobyspark 0:76bb084fa033 18 #define pixInPage 8
tobyspark 0:76bb084fa033 19 #define pageCount 8
tobyspark 0:76bb084fa033 20
tobyspark 2:8187d69071f8 21 /** Display class for 128x64 OLEDs using the SSD1305 driver, connected via SPI
tobyspark 2:8187d69071f8 22 *
tobyspark 1:dd3faa2ab1dd 23 * Display ie. DENSITRON - DD-12864YO-3A
tobyspark 0:76bb084fa033 24 *
tobyspark 1:dd3faa2ab1dd 25 * This is a ground-up, minimal library. Further functionality as and when its needed or anybody wants to contribute.
tobyspark 0:76bb084fa033 26 *
tobyspark 0:76bb084fa033 27 * This library includes two processing sketches to create a font and full-screen image in the required byte representations.
tobyspark 2:8187d69071f8 28 * Without creating your font and any images, all this library will do is blank the screen and draw horizontal lines. But at least you'll know its working!
tobyspark 0:76bb084fa033 29 *
tobyspark 0:76bb084fa033 30 * Terminology:
tobyspark 0:76bb084fa033 31 * 'rows' are 8 pixel high rows across the display, 0 being the topmost and 7 the bottom.
tobyspark 2:8187d69071f8 32 * 'lines' are single pixel lines, origin top left.
tobyspark 0:76bb084fa033 33 *
tobyspark 0:76bb084fa033 34 * Example:
tobyspark 0:76bb084fa033 35 * @code
tobyspark 1:dd3faa2ab1dd 36 * // Create object and load font
tobyspark 0:76bb084fa033 37 * SPKDisplay screen(p5, p7, p8, p10, p9)
tobyspark 1:dd3faa2ab1dd 38 * screen.fontStartCharacter = &myStartChar;
tobyspark 1:dd3faa2ab1dd 39 * screen.fontEndCharacter = &myEndChar;
tobyspark 1:dd3faa2ab1dd 40 * screen.fontCharacters = myFontArray;
tobyspark 1:dd3faa2ab1dd 41 * // Draw
tobyspark 1:dd3faa2ab1dd 42 * screen.imageToBuffer(myImageByteArray);
tobyspark 0:76bb084fa033 43 * screen.textToBuffer("*spark OLED SSD1305",0);
tobyspark 0:76bb084fa033 44 * screen.textToBuffer("v01",1);
tobyspark 0:76bb084fa033 45 * screen.sendBuffer
tobyspark 0:76bb084fa033 46 * @endcode
tobyspark 0:76bb084fa033 47 */
tobyspark 0:76bb084fa033 48 class SPKDisplay
tobyspark 0:76bb084fa033 49 {
tobyspark 0:76bb084fa033 50 public:
tobyspark 0:76bb084fa033 51 /** Create a display object connected via SPI
tobyspark 0:76bb084fa033 52 *
tobyspark 0:76bb084fa033 53 * @param mosi SPI MOSI
tobyspark 0:76bb084fa033 54 * @param clk SPI SCK
tobyspark 0:76bb084fa033 55 * @param cs Chip Select - a digital out pin
tobyspark 0:76bb084fa033 56 * @param dc Data/Command - a digital out pin
tobyspark 0:76bb084fa033 57 * @param res Reset - a digital out pin
tobyspark 0:76bb084fa033 58 * @param debugSerial An optional serial object to log to
tobyspark 0:76bb084fa033 59 */
tobyspark 0:76bb084fa033 60 SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL);
tobyspark 0:76bb084fa033 61
tobyspark 1:dd3faa2ab1dd 62 /** Font - Assign the ASCII value of the character at the start of the implemented range */
tobyspark 1:dd3faa2ab1dd 63 const int *fontStartCharacter;
tobyspark 1:dd3faa2ab1dd 64
tobyspark 1:dd3faa2ab1dd 65 /** Font - Assign the ASCII value of the character at the end of the implemented range */
tobyspark 1:dd3faa2ab1dd 66 const int *fontEndCharacter;
tobyspark 1:dd3faa2ab1dd 67
tobyspark 1:dd3faa2ab1dd 68 /** Font - Assign the font, an array of 8x8px characters
tobyspark 1:dd3faa2ab1dd 69 *
tobyspark 1:dd3faa2ab1dd 70 * @note The processing sketch spk_oled_fontByteMaker--processing takes characterCount*8px x 8px images and creates the code to declare the font array needed by this method
tobyspark 1:dd3faa2ab1dd 71 */
tobyspark 1:dd3faa2ab1dd 72 uint8_t const **fontCharacters;
tobyspark 1:dd3faa2ab1dd 73
tobyspark 0:76bb084fa033 74 /** Completely clear the object's display representation */
tobyspark 0:76bb084fa033 75 void clearBuffer();
tobyspark 0:76bb084fa033 76
tobyspark 0:76bb084fa033 77 /** Clear a row of the object's display representation
tobyspark 0:76bb084fa033 78 *
tobyspark 0:76bb084fa033 79 * @param row The row to clear.
tobyspark 0:76bb084fa033 80 */
tobyspark 0:76bb084fa033 81 void clearBufferRow(int row);
tobyspark 0:76bb084fa033 82
tobyspark 1:dd3faa2ab1dd 83 /** Replace the object\s display representation with the contents of image
tobyspark 1:dd3faa2ab1dd 84 *
tobyspark 1:dd3faa2ab1dd 85 * @param image An array of 1056 bytes representing an image.
tobyspark 1:dd3faa2ab1dd 86 * @note The processing sketch spk_oled_screenByteMaker--processing takes 132x64 images and creates the code to declare such arrays
tobyspark 1:dd3faa2ab1dd 87 */
tobyspark 1:dd3faa2ab1dd 88 void imageToBuffer(const uint8_t* image);
tobyspark 0:76bb084fa033 89
tobyspark 0:76bb084fa033 90 /** Draw a horizontal line in the object's display representation
tobyspark 0:76bb084fa033 91 *
tobyspark 0:76bb084fa033 92 * @param y The y position of the line to draw
tobyspark 0:76bb084fa033 93 */
tobyspark 0:76bb084fa033 94 void horizLineToBuffer(int y);
tobyspark 0:76bb084fa033 95
tobyspark 0:76bb084fa033 96 /** Write a line of text in the object's display representation
tobyspark 1:dd3faa2ab1dd 97 * Requires the font to have been set
tobyspark 0:76bb084fa033 98 *
tobyspark 0:76bb084fa033 99 * @param message The text to write. The text will be truncated if longer than the screen's width.
tobyspark 0:76bb084fa033 100 * @param row The row in which to write the text
tobyspark 0:76bb084fa033 101 */
tobyspark 0:76bb084fa033 102 void textToBuffer(std::string message, int row);
tobyspark 0:76bb084fa033 103
tobyspark 0:76bb084fa033 104 /** Send the object's display representation to the OLED
tobyspark 0:76bb084fa033 105 *
tobyspark 0:76bb084fa033 106 * You can safely call this once per main loop, it will only transmit the buffer contents if there has been an update
tobyspark 0:76bb084fa033 107 */
tobyspark 0:76bb084fa033 108 void sendBuffer();
tobyspark 0:76bb084fa033 109
tobyspark 0:76bb084fa033 110 private:
tobyspark 0:76bb084fa033 111 SPI *spi;
tobyspark 0:76bb084fa033 112 DigitalOut *cs;
tobyspark 0:76bb084fa033 113 DigitalOut *dc;
tobyspark 0:76bb084fa033 114 DigitalOut *res;
tobyspark 0:76bb084fa033 115
tobyspark 0:76bb084fa033 116 Serial *debug;
tobyspark 0:76bb084fa033 117 uint8_t buffer[bufferCount];
tobyspark 0:76bb084fa033 118
tobyspark 0:76bb084fa033 119 bool bufferHasChanged;
tobyspark 0:76bb084fa033 120
tobyspark 0:76bb084fa033 121 void setup();
tobyspark 0:76bb084fa033 122 };
tobyspark 0:76bb084fa033 123
tobyspark 0:76bb084fa033 124 #endif