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);

}

Related Posts: