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 16:51:01 2012 +0000
Revision:
0:76bb084fa033
Child:
1:dd3faa2ab1dd
Initial commit after internal dev as part of SPK-DVIMXR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tobyspark 0:76bb084fa033 1 int w = 132;
tobyspark 0:76bb084fa033 2 int h = 64;
tobyspark 0:76bb084fa033 3 int scaleFactor = 5;
tobyspark 0:76bb084fa033 4
tobyspark 0:76bb084fa033 5 PImage imgPixel;
tobyspark 0:76bb084fa033 6 color white = color(255, 255, 255, 255);
tobyspark 0:76bb084fa033 7 color black = color(0, 0, 0, 255);
tobyspark 0:76bb084fa033 8
tobyspark 0:76bb084fa033 9 void setup()
tobyspark 0:76bb084fa033 10 {
tobyspark 0:76bb084fa033 11 imgPixel = loadImage("spk_dvimxr_font.png");
tobyspark 0:76bb084fa033 12 w = imgPixel.width;
tobyspark 0:76bb084fa033 13 h = imgPixel.height;
tobyspark 0:76bb084fa033 14
tobyspark 0:76bb084fa033 15 size(w*scaleFactor, h*scaleFactor);
tobyspark 0:76bb084fa033 16
tobyspark 0:76bb084fa033 17 noSmooth();
tobyspark 0:76bb084fa033 18 }
tobyspark 0:76bb084fa033 19
tobyspark 0:76bb084fa033 20 void draw()
tobyspark 0:76bb084fa033 21 {
tobyspark 0:76bb084fa033 22 background(0);
tobyspark 0:76bb084fa033 23 image(imgPixel, 0, 0, w*scaleFactor, h*scaleFactor);
tobyspark 0:76bb084fa033 24 }
tobyspark 0:76bb084fa033 25
tobyspark 0:76bb084fa033 26 void mouseDragged()
tobyspark 0:76bb084fa033 27 {
tobyspark 0:76bb084fa033 28 int x = mouseX/scaleFactor;
tobyspark 0:76bb084fa033 29 int y = mouseY/scaleFactor;
tobyspark 0:76bb084fa033 30
tobyspark 0:76bb084fa033 31 imgPixel.set(x, y, white);
tobyspark 0:76bb084fa033 32 }
tobyspark 0:76bb084fa033 33
tobyspark 0:76bb084fa033 34 void mousePressed()
tobyspark 0:76bb084fa033 35 {
tobyspark 0:76bb084fa033 36 int x = mouseX/scaleFactor;
tobyspark 0:76bb084fa033 37 int y = mouseY/scaleFactor;
tobyspark 0:76bb084fa033 38
tobyspark 0:76bb084fa033 39 if (imgPixel.get(x, y) == white)
tobyspark 0:76bb084fa033 40 {
tobyspark 0:76bb084fa033 41 imgPixel.set(x, y, black);
tobyspark 0:76bb084fa033 42 }
tobyspark 0:76bb084fa033 43 else
tobyspark 0:76bb084fa033 44 {
tobyspark 0:76bb084fa033 45 imgPixel.set(x, y, white);
tobyspark 0:76bb084fa033 46 }
tobyspark 0:76bb084fa033 47 }
tobyspark 0:76bb084fa033 48
tobyspark 0:76bb084fa033 49 void keyPressed()
tobyspark 0:76bb084fa033 50 {
tobyspark 0:76bb084fa033 51 int startID = 33;
tobyspark 0:76bb084fa033 52 int stopID = 126;
tobyspark 0:76bb084fa033 53
tobyspark 0:76bb084fa033 54 for (int charID = startID; charID <= stopID; charID++)
tobyspark 0:76bb084fa033 55 {
tobyspark 0:76bb084fa033 56 boolean blank = false;
tobyspark 0:76bb084fa033 57 String output = "";
tobyspark 0:76bb084fa033 58 int counter = 0;
tobyspark 0:76bb084fa033 59 while (blank == false)
tobyspark 0:76bb084fa033 60 {
tobyspark 0:76bb084fa033 61 int x = (charID-startID)*8 + counter;
tobyspark 0:76bb084fa033 62
tobyspark 0:76bb084fa033 63 byte theByte = 0;
tobyspark 0:76bb084fa033 64 for (int b = 0; b < 8; b++)
tobyspark 0:76bb084fa033 65 {
tobyspark 0:76bb084fa033 66 if (imgPixel.get(x, b) == white)
tobyspark 0:76bb084fa033 67 {
tobyspark 0:76bb084fa033 68 theByte += pow(2, b);
tobyspark 0:76bb084fa033 69 }
tobyspark 0:76bb084fa033 70 }
tobyspark 0:76bb084fa033 71
tobyspark 0:76bb084fa033 72 if (theByte > 0)
tobyspark 0:76bb084fa033 73 {
tobyspark 0:76bb084fa033 74 if (output.length() > 0) output = output + ", ";
tobyspark 0:76bb084fa033 75 output = output + "0x" + hex(theByte, 2);
tobyspark 0:76bb084fa033 76 }
tobyspark 0:76bb084fa033 77 else
tobyspark 0:76bb084fa033 78 {
tobyspark 0:76bb084fa033 79 blank = true;
tobyspark 0:76bb084fa033 80 println("const uint8_t char" + charID + "[] = {" + counter + ", " + output + "};");
tobyspark 0:76bb084fa033 81 }
tobyspark 0:76bb084fa033 82
tobyspark 0:76bb084fa033 83 counter++;
tobyspark 0:76bb084fa033 84 }
tobyspark 0:76bb084fa033 85 }
tobyspark 0:76bb084fa033 86 println();
tobyspark 0:76bb084fa033 87 println("const int characterBytesStartChar = " + startID + ";");
tobyspark 0:76bb084fa033 88 println("const int characterBytesEndChar = " + stopID + ";");
tobyspark 0:76bb084fa033 89 print("const uint8_t* characterBytes[] = {");
tobyspark 0:76bb084fa033 90 for (int charID = startID; charID <= stopID; charID++)
tobyspark 0:76bb084fa033 91 {
tobyspark 0:76bb084fa033 92 print("char" + charID + ", ");
tobyspark 0:76bb084fa033 93 }
tobyspark 0:76bb084fa033 94 println("};");
tobyspark 0:76bb084fa033 95 }