Electric Imp driving a small OLED display

Electric Imp driving an OLED display

Electric Imp driving an OLED display

I made some little functions for the Electric Imp to make it easier to drive a OLED display rom Digole (for example the 0.96″ Serial: UART/I2C/SPI 128×64 OLED Module Blue CN (DS12864OLED-2B), but they also come in other sizes and colours). They cost around $10, so it’s a pretty cheap display option that’s also easy to work with and looks nice. The display on the picture is a 1,3″ white OLED (DS12864OLED-3W).

The functions should be self explaining, eg. to draw a rectangle you use “LCDRect(x,y,width,height)” where x & y are the starting coordinates and width & height are the size of the figure. An example could be “LCDRect(5,40,100,10);“. They go in the “Device” tab in the Electric Imp environment.

But before you use the functions you need to setup the communication with the display like this:

hardware.uart12.configure(9600, 8, PARITY_NONE, 1, NO_RX);

Then the functions:

function LCDClear()
{
hardware.uart12.write(“CL”);
hardware.uart12.write(0×01);
}

function LCDSetFont(fontnr)
{
hardware.uart12.write(“SF”);
hardware.uart12.write(fontnr);
hardware.uart12.write(0×01);
}

function LCDWriteMessage(LCDMessage)
{
hardware.uart12.write(“TT” + LCDMessage);
hardware.uart12.write(0×00);
}

function LCDNewLine()
{
hardware.uart12.write(“TRT”);
hardware.uart12.write(0×01);
}

function LCDRot(Rot)
{
hardware.uart12.write(“SD” + Rot);
hardware.uart12.write(0×01);
}

function LCDRect(x,y,width,height)
{
x2 <- x + width;
y2 <- y + height;
hardware.uart12.write(“DR”);
hardware.uart12.write(x);
hardware.uart12.write(y);
hardware.uart12.write(x2);
hardware.uart12.write(y2);
hardware.uart12.write(0×01);
}

function LCDRectFilled(x,y,width,height)
{
x2 <- x + width;
y2 <- y + height;
hardware.uart12.write(“FR”);
hardware.uart12.write(x);
hardware.uart12.write(y);
hardware.uart12.write(x2);
hardware.uart12.write(y2);
hardware.uart12.write(0×01);
}

function LCDCircle(x,y,r,f)
{
hardware.uart12.write(“CC”);
hardware.uart12.write(x);
hardware.uart12.write(y);
hardware.uart12.write(r);
hardware.uart12.write(f);
hardware.uart12.write(0×01);
}

DiggDeliciousGoogle BuzzSlashdotRedditShare

Related Posts:

  • No Related Posts

This entry was posted in Electric Imp, Electronics and tagged , , , . Bookmark the permalink.

4 Responses to Electric Imp driving a small OLED display

  1. bld says:

    I bought this display after seeing this post, I got it to work with my Electric Imp, using your functions.

    The only problem I got is that when I draw a rectangle or circle, it is “black”, instead of lighting up like text does. So if I write text and put a rectangle over, I can see the pixels where the rectangle is getting turned off.

    Any idea how I can make the graphics light up instead of “turn off”?

    • bld says:

      And I can answer it myself too…

      For some reason, as default in the display text was set to white, graphics was set to black.

      Sending SC1 made everything white, so now it all works as intended. :)

      • nkh says:

        Hehe, I’m glad you figured it out! There is an element of trial and error with these displays, but you’ll get there in the end :)

        Your projects look very interesting over at captain-slow.dk !

  2. Pingback: captain-slow.dk » OLED + Electric Imp = <3

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>