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:
Thu Aug 02 13:26:18 2012 +0000
Revision:
3:ade83210ecf6
Parent:
2:8187d69071f8
MIT License as per MBED guideline

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 2:8187d69071f8 1 // OLED display using SSD1305 driver
tobyspark 3:ade83210ecf6 2 // A library by *spark audio-visual
tobyspark 3:ade83210ecf6 3
tobyspark 3:ade83210ecf6 4 /* Copyright (c) 2011 Toby Harris, MIT License
tobyspark 3:ade83210ecf6 5 *
tobyspark 3:ade83210ecf6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tobyspark 3:ade83210ecf6 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tobyspark 3:ade83210ecf6 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tobyspark 3:ade83210ecf6 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tobyspark 3:ade83210ecf6 10 * furnished to do so, subject to the following conditions:
tobyspark 3:ade83210ecf6 11 *
tobyspark 3:ade83210ecf6 12 * The above copyright notice and this permission notice shall be included in all copies or
tobyspark 3:ade83210ecf6 13 * substantial portions of the Software.
tobyspark 3:ade83210ecf6 14 *
tobyspark 3:ade83210ecf6 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tobyspark 3:ade83210ecf6 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tobyspark 3:ade83210ecf6 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tobyspark 3:ade83210ecf6 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tobyspark 3:ade83210ecf6 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tobyspark 3:ade83210ecf6 20 */
tobyspark 2:8187d69071f8 21
tobyspark 2:8187d69071f8 22 int w = 132;
tobyspark 2:8187d69071f8 23 int h = 64;
tobyspark 2:8187d69071f8 24 int scaleFactor = 10;
tobyspark 2:8187d69071f8 25
tobyspark 2:8187d69071f8 26 PImage imgPixel;
tobyspark 2:8187d69071f8 27 color white = color(255, 255, 255, 255);
tobyspark 2:8187d69071f8 28 color black = color(0, 0, 0, 255);
tobyspark 2:8187d69071f8 29
tobyspark 2:8187d69071f8 30 void setup()
tobyspark 2:8187d69071f8 31 {
tobyspark 2:8187d69071f8 32 size(w*scaleFactor, h*scaleFactor);
tobyspark 2:8187d69071f8 33 imgPixel = loadImage("spk_dvimxr_screen.png");
tobyspark 2:8187d69071f8 34
tobyspark 2:8187d69071f8 35 noSmooth();
tobyspark 2:8187d69071f8 36 }
tobyspark 2:8187d69071f8 37
tobyspark 2:8187d69071f8 38 void draw()
tobyspark 2:8187d69071f8 39 {
tobyspark 2:8187d69071f8 40 background(0);
tobyspark 2:8187d69071f8 41 image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor);
tobyspark 2:8187d69071f8 42 }
tobyspark 2:8187d69071f8 43
tobyspark 2:8187d69071f8 44 void mouseDragged()
tobyspark 2:8187d69071f8 45 {
tobyspark 2:8187d69071f8 46 int x = mouseX/scaleFactor;
tobyspark 2:8187d69071f8 47 int y = mouseY/scaleFactor;
tobyspark 2:8187d69071f8 48
tobyspark 2:8187d69071f8 49 imgPixel.set(x, y, white);
tobyspark 2:8187d69071f8 50 }
tobyspark 2:8187d69071f8 51
tobyspark 2:8187d69071f8 52 void mousePressed()
tobyspark 2:8187d69071f8 53 {
tobyspark 2:8187d69071f8 54 int x = mouseX/scaleFactor;
tobyspark 2:8187d69071f8 55 int y = mouseY/scaleFactor;
tobyspark 2:8187d69071f8 56
tobyspark 2:8187d69071f8 57 if (imgPixel.get(x, y) == white)
tobyspark 2:8187d69071f8 58 {
tobyspark 2:8187d69071f8 59 imgPixel.set(x, y, black);
tobyspark 2:8187d69071f8 60 }
tobyspark 2:8187d69071f8 61 else
tobyspark 2:8187d69071f8 62 {
tobyspark 2:8187d69071f8 63 imgPixel.set(x, y, white);
tobyspark 2:8187d69071f8 64 }
tobyspark 2:8187d69071f8 65 }
tobyspark 2:8187d69071f8 66
tobyspark 2:8187d69071f8 67 void keyPressed()
tobyspark 2:8187d69071f8 68 {
tobyspark 2:8187d69071f8 69 println("{");
tobyspark 2:8187d69071f8 70 for (int page = 0; page < 8; page++)
tobyspark 2:8187d69071f8 71 {
tobyspark 2:8187d69071f8 72 for (int i = 0; i < w; i++)
tobyspark 2:8187d69071f8 73 {
tobyspark 2:8187d69071f8 74 byte theByte = 0;
tobyspark 2:8187d69071f8 75 for (int j = 0; j < 8; j++)
tobyspark 2:8187d69071f8 76 {
tobyspark 2:8187d69071f8 77 if (imgPixel.get(i, (page*8)+j) == white)
tobyspark 2:8187d69071f8 78 {
tobyspark 2:8187d69071f8 79 theByte += pow(2, j);
tobyspark 2:8187d69071f8 80 }
tobyspark 2:8187d69071f8 81 }
tobyspark 2:8187d69071f8 82 print("0x" + hex(theByte, 2));
tobyspark 2:8187d69071f8 83 print(", ");
tobyspark 2:8187d69071f8 84 }
tobyspark 2:8187d69071f8 85 println();
tobyspark 2:8187d69071f8 86 }
tobyspark 2:8187d69071f8 87 println("}");
tobyspark 2:8187d69071f8 88 }