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:
pegcjs
Date:
Tue Jan 29 09:56:25 2013 +0000
Revision:
5:6d2aded0cf41
Library updated to allow page mode driving on a unigraphics OLED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pegcjs 5:6d2aded0cf41 1 // OLED display using SSD1305 driver
pegcjs 5:6d2aded0cf41 2 // A library by *spark audio-visual
pegcjs 5:6d2aded0cf41 3
pegcjs 5:6d2aded0cf41 4 /* Copyright (c) 2011 Toby Harris, MIT License
pegcjs 5:6d2aded0cf41 5 *
pegcjs 5:6d2aded0cf41 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
pegcjs 5:6d2aded0cf41 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
pegcjs 5:6d2aded0cf41 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
pegcjs 5:6d2aded0cf41 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
pegcjs 5:6d2aded0cf41 10 * furnished to do so, subject to the following conditions:
pegcjs 5:6d2aded0cf41 11 *
pegcjs 5:6d2aded0cf41 12 * The above copyright notice and this permission notice shall be included in all copies or
pegcjs 5:6d2aded0cf41 13 * substantial portions of the Software.
pegcjs 5:6d2aded0cf41 14 *
pegcjs 5:6d2aded0cf41 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
pegcjs 5:6d2aded0cf41 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
pegcjs 5:6d2aded0cf41 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
pegcjs 5:6d2aded0cf41 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pegcjs 5:6d2aded0cf41 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pegcjs 5:6d2aded0cf41 20 */
pegcjs 5:6d2aded0cf41 21
pegcjs 5:6d2aded0cf41 22
pegcjs 5:6d2aded0cf41 23 /* rewritten to work with the SSD1306 driver JCY-MCU oled (from ebay). chris stevens 2013
pegcjs 5:6d2aded0cf41 24
pegcjs 5:6d2aded0cf41 25 */
pegcjs 5:6d2aded0cf41 26
pegcjs 5:6d2aded0cf41 27
pegcjs 5:6d2aded0cf41 28 #ifndef SPK_OLED_SSD1305_h
pegcjs 5:6d2aded0cf41 29 #define SPK_OLED_SSD1305_h
pegcjs 5:6d2aded0cf41 30
pegcjs 5:6d2aded0cf41 31 #include "mbed.h"
pegcjs 5:6d2aded0cf41 32 #include <string>
pegcjs 5:6d2aded0cf41 33
pegcjs 5:6d2aded0cf41 34 #define bufferCount 1024
pegcjs 5:6d2aded0cf41 35 #define bufferWidth 128
pegcjs 5:6d2aded0cf41 36 #define pixelWidth 128
pegcjs 5:6d2aded0cf41 37 #define pixelHeight 64
pegcjs 5:6d2aded0cf41 38 #define pixInPage 8
pegcjs 5:6d2aded0cf41 39 #define pageCount 8
pegcjs 5:6d2aded0cf41 40
pegcjs 5:6d2aded0cf41 41
pegcjs 5:6d2aded0cf41 42
pegcjs 5:6d2aded0cf41 43 /** Display class for 128x64 OLEDs using the SSD1305 driver, connected via SPI
pegcjs 5:6d2aded0cf41 44 *
pegcjs 5:6d2aded0cf41 45 * Display ie. DENSITRON - DD-12864YO-3A
pegcjs 5:6d2aded0cf41 46 *
pegcjs 5:6d2aded0cf41 47 * This is a ground-up, minimal library. Further functionality as and when its needed or anybody wants to contribute.
pegcjs 5:6d2aded0cf41 48 *
pegcjs 5:6d2aded0cf41 49 * This library includes two processing sketches to create a font and full-screen image in the required byte representations.
pegcjs 5:6d2aded0cf41 50 * 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!
pegcjs 5:6d2aded0cf41 51 *
pegcjs 5:6d2aded0cf41 52 * Terminology:
pegcjs 5:6d2aded0cf41 53 * 'rows' are 8 pixel high rows across the display, 0 being the topmost and 7 the bottom.
pegcjs 5:6d2aded0cf41 54 * 'lines' are single pixel lines, origin top left.
pegcjs 5:6d2aded0cf41 55 *
pegcjs 5:6d2aded0cf41 56 */
pegcjs 5:6d2aded0cf41 57 class SPKDisplay
pegcjs 5:6d2aded0cf41 58 {
pegcjs 5:6d2aded0cf41 59 public:
pegcjs 5:6d2aded0cf41 60 /** Create a display object connected via SPI
pegcjs 5:6d2aded0cf41 61 *
pegcjs 5:6d2aded0cf41 62 * @param mosi SPI MOSI
pegcjs 5:6d2aded0cf41 63 * @param clk SPI SCK
pegcjs 5:6d2aded0cf41 64 * @param cs Chip Select - a digital out pin
pegcjs 5:6d2aded0cf41 65 * @param dc Data/Command - a digital out pin
pegcjs 5:6d2aded0cf41 66 * @param res Reset - a digital out pin
pegcjs 5:6d2aded0cf41 67 * @param debugSerial An optional serial object to log to
pegcjs 5:6d2aded0cf41 68 */
pegcjs 5:6d2aded0cf41 69 SPKDisplay(PinName mosi, PinName clk, PinName cs, PinName dc, PinName res, Serial *debugSerial = NULL);
pegcjs 5:6d2aded0cf41 70
pegcjs 5:6d2aded0cf41 71 /** Font - Assign the ASCII value of the character at the start of the implemented range */
pegcjs 5:6d2aded0cf41 72 const int *fontStartCharacter;
pegcjs 5:6d2aded0cf41 73
pegcjs 5:6d2aded0cf41 74 /** Font - Assign the ASCII value of the character at the end of the implemented range */
pegcjs 5:6d2aded0cf41 75 const int *fontEndCharacter;
pegcjs 5:6d2aded0cf41 76
pegcjs 5:6d2aded0cf41 77 /** Font - Assign the font, an array of 8x8px characters
pegcjs 5:6d2aded0cf41 78 *
pegcjs 5:6d2aded0cf41 79 * @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
pegcjs 5:6d2aded0cf41 80 */
pegcjs 5:6d2aded0cf41 81 uint8_t const **fontCharacters;
pegcjs 5:6d2aded0cf41 82
pegcjs 5:6d2aded0cf41 83 // set display for black on white
pegcjs 5:6d2aded0cf41 84 void inverse();
pegcjs 5:6d2aded0cf41 85
pegcjs 5:6d2aded0cf41 86 // display a welcopme message encoded in tab0 in spk_ole_ssd1305.h
pegcjs 5:6d2aded0cf41 87 void welcome();
pegcjs 5:6d2aded0cf41 88 // output the entire font as a bitmap
pegcjs 5:6d2aded0cf41 89 void fontdemo();
pegcjs 5:6d2aded0cf41 90
pegcjs 5:6d2aded0cf41 91 //set display for white on black (normal state after reset)
pegcjs 5:6d2aded0cf41 92 void normal();
pegcjs 5:6d2aded0cf41 93
pegcjs 5:6d2aded0cf41 94 // power on / power off the display - this puts the display to sleep - but doesn turn off tha actuall power pin.
pegcjs 5:6d2aded0cf41 95 void displayPower(int P);
pegcjs 5:6d2aded0cf41 96
pegcjs 5:6d2aded0cf41 97 /** Completely clear the object's display representation */
pegcjs 5:6d2aded0cf41 98 void clearBuffer();
pegcjs 5:6d2aded0cf41 99
pegcjs 5:6d2aded0cf41 100 /** Clear a row of the object's display representation
pegcjs 5:6d2aded0cf41 101 *
pegcjs 5:6d2aded0cf41 102 * @param row The row to clear.
pegcjs 5:6d2aded0cf41 103 */
pegcjs 5:6d2aded0cf41 104 void clearBufferRow(int row);
pegcjs 5:6d2aded0cf41 105
pegcjs 5:6d2aded0cf41 106 /** Replace the object\s display representation with the contents of image
pegcjs 5:6d2aded0cf41 107 *
pegcjs 5:6d2aded0cf41 108 * @param image An array of 1056 bytes representing an image.
pegcjs 5:6d2aded0cf41 109 * @note The processing sketch spk_oled_screenByteMaker--processing takes 132x64 images and creates the code to declare such arrays
pegcjs 5:6d2aded0cf41 110 */
pegcjs 5:6d2aded0cf41 111 void imageToBuffer(const uint8_t* image);
pegcjs 5:6d2aded0cf41 112
pegcjs 5:6d2aded0cf41 113 /** Draw a horizontal line in the object's display representation
pegcjs 5:6d2aded0cf41 114 *
pegcjs 5:6d2aded0cf41 115 * @param y The y position of the line to draw
pegcjs 5:6d2aded0cf41 116 */
pegcjs 5:6d2aded0cf41 117 void horizLineToBuffer(int y);
pegcjs 5:6d2aded0cf41 118
pegcjs 5:6d2aded0cf41 119
pegcjs 5:6d2aded0cf41 120 /** Send the object's display representation to the OLED
pegcjs 5:6d2aded0cf41 121 *
pegcjs 5:6d2aded0cf41 122 * You can safely call this once per main loop, it will only transmit the buffer contents if there has been an update
pegcjs 5:6d2aded0cf41 123 */
pegcjs 5:6d2aded0cf41 124 void sendBuffer();
pegcjs 5:6d2aded0cf41 125
pegcjs 5:6d2aded0cf41 126 // send text to the buffer to write inthe tiny 5x7 font
pegcjs 5:6d2aded0cf41 127 void textToBuffer(char *message, int row);
pegcjs 5:6d2aded0cf41 128
pegcjs 5:6d2aded0cf41 129 private:
pegcjs 5:6d2aded0cf41 130 SPI *spi;
pegcjs 5:6d2aded0cf41 131 DigitalOut *cs;
pegcjs 5:6d2aded0cf41 132 DigitalOut *dc;
pegcjs 5:6d2aded0cf41 133 DigitalOut *res;
pegcjs 5:6d2aded0cf41 134
pegcjs 5:6d2aded0cf41 135 Serial *debug;
pegcjs 5:6d2aded0cf41 136 uint8_t buffer[bufferCount];
pegcjs 5:6d2aded0cf41 137
pegcjs 5:6d2aded0cf41 138 bool bufferHasChanged;
pegcjs 5:6d2aded0cf41 139
pegcjs 5:6d2aded0cf41 140 void setup();
pegcjs 5:6d2aded0cf41 141 };
pegcjs 5:6d2aded0cf41 142
pegcjs 5:6d2aded0cf41 143 #endif