Oled display 0,96 inch

http://www.ebay.co.uk/itm/I2C-0-96-OLED-display-module-compatible-Arduino-/130566448551?pt=LH_DefaultDomain_0&hash=item1e665de5a7

Seems nice
the code is for arduino

At a glance, this is an i2c device that’s 3.3V compatible, so that’s promising! Adapting the generic Adafruit LCD library (seems to be what they’re using) to Squirrel shouldn’t be too hard - assuming someone hasn’t already done it.

Anyone working with these??

Got 2 and want to use them to do some basic text output.

What a coincidence
Today i tested the arduino code and it works.
Next days a will try to convert it to imp

Nice! Let’s work together…

Mine is running with the basic inits but i need a way to add a font
and later some bitmaps.

Writing the converted font-char directly is working but i failed on porting the
arduino font table to the imp.

fyi, i use a 10k pull-up resistor for sda and scl.

This is my Code right now…
`
hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);
oled <- hardware.i2c89;
local i2c_address = 0x3c<<1;

function sendChar(data) {
oled.write(i2c_address, format("%c%c",0x40, data));
}

function sendcommand(data) {
oled.write(i2c_address, format("%c%c",0x80, data));
}

function clear_display()
{
local i;
local k;
for(k=0;k<8;k++)
{
setXY(k,0);
{
for(i=0;i<128;i++)
{
sendChar(0);
}
}
}
}

function setXY(row, col)
{
sendcommand(0xb0+row); //set page address
sendcommand(0x00+(8col&0x0f)); //set low col address
sendcommand(0x10+((8
col>>4)&0x0f)); //set high col address
}

function init_OLED() {
sendcommand(0xa6); //turn display off
imp.sleep(0.01);
clear_display(); //clear garbage
sendcommand(0xae); //turn display on
imp.sleep(0.01);
sendcommand(0xaf); // set normal mode
imp.sleep(0.01);
}

function test() {
//this will print “Chrischi❤” on the Display
setXY(3,4);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00));
imp.sleep(0.01);setXY(3,5);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00));
imp.sleep(0.01);setXY(3,6);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00));
imp.sleep(0.01);setXY(3,7);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00));
imp.sleep(0.01);setXY(3,8);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x48,0x54,0x54,0x54,0x20,0x00,0x00));
imp.sleep(0.01);setXY(3,9);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x38,0x44,0x44,0x44,0x00,0x00,0x00));
imp.sleep(0.01);setXY(3,10);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00));
imp.sleep(0.01);setXY(3,11);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00));
imp.sleep(0.01);setXY(3,12);
oled.write(i2c_address, format("%c%c%c%c%c%c%c%c%c",0x40,0x0E,0x1F,0x3F,0x7E,0x3F,0x1F,0x0E,0x00));
//clear_display();
}

init_OLED();
//sendcommand(0xa0); //flip to default
//sendcommand(0xa1); //flip vertical
//sendcommand(0xc8); //flip horizontal
imp.sleep(0.05);
test();
`

Here is the original Arduino Code: http://pastebin.com/bBPfUcqH

Would love to see it completely ported to the imp.

Running the above Code looks like this:

Why did you shifted the i2c addr?

because the arduino uses 7bit addresses and the imp 8bit.

your example works with me

How do we add the font array

the arduino font array is this

`unsigned char myFont[][8]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};

and is accessed like this
void sendStr(unsigned char *string)
{
unsigned char i=0;
//setXY(0,0);
while(*string)
{
for(i=0;i<8;i++)
{
SendChar(myFont[*string-0x20][i]);

  // SendChar(*string);
  delay(10);
}
*string++;

}
}
`
how do we convert it to imp?

now i’am working with this:
function char_to_bin(c) { switch (c) { case "A": return "\\xE0\\x3C\\x23\\x23\\x3C\\xE0"; case "B": return "\\xFF\\x89\\x89\\x89\\x76"; case "C": return "\\x3C\\x42\\x81\\x81\\x81\\x81"; case "D": return "\\xFF\\x81\\x81\\x81\\x42\\x3C"; case "E": return "\\xFF\\x89\\x89\\x89\\x81"; case "F": return "\\xFF\\x09\\x09\\x09\\x09"; case "G": return "\\x3C\\x42\\x81\\x91\\x91\\xF1"; case "H": return "\\xFF\\x08\\x08\\x08\\x08\\xFF"; case "I": return "\\x81\\xFF\\x81"; case "J": return "\\x80\\x81\\x81\\x7F"; case "K": return "\\xFF\\x18\\x24\\x42\\x81"; case "L": return "\\xFF\\x80\\x80\\x80"; case "M": return "\\xFF\\x03\\x0C\\x30\\x0C\\x03\\xFF"; case "N": return "\\xFF\\x03\\x0C\\x30\\xC0\\xFF"; case "O": return "\\x3C\\x42\\x81\\x81\\x81\\x42\\x3C"; case "P": return "\\xFF\\x11\\x11\\x11\\x0E"; case "Q": return "\\x3C\\x42\\x81\\xA1\\xA1\\x42\\xBC"; case "R": return "\\xFF\\x11\\x11\\x31\\x4E\\x80"; case "S": return "\\x86\\x89\\x89\\x89\\x71"; case "T": return "\\x01\\x01\\xFF\\x01\\x01"; case "U": return "\\x7F\\x80\\x80\\x80\\x80\\x7F"; case "V": return "\\x07\\x38\\xC0\\x38\\x07"; case "W": return "\\x07\\x38\\xC0\\x38\\x07\\x38\\xC0\\x38\\x07"; case "X": return "\\xC3\\x24\\x18\\x24\\xC3"; case "Y": return "\\x03\\x0C\\xF0\\x0C\\x03"; case "Z": return "\\xC1\\xA1\\x99\\x85\\x83"; default: return "\\x00\\x00\\x00\\x00\\x00"; } }

and this function:
function sendChar(data) { local char = char_to_bin(data); oled.write(i2c_address, "\\x40"+char+"\\x00\\x00"); // 0x00 for some gap }

to print it:
sendChar("A"); sendChar("B"); sendChar("C"); ...

maybe you have to flip the Screen orientation…

P.S.: please use the code tag in your posts.

How did you generate the hex values?
i need numbers also

i tried dot factory to generate hex for numbers but the number 2 appears rotated 90 degrees counter clock.

i generated all chars but posted only a few to let not explode the post

how did you generate it? i tried with dot factory app but are all clockwised

i also used dot factory and created my own preset.

Done!
damn !

Do you think its possible to have multi size characters in the display?

I added a 24pts char and it seems to be shrinked in the display along the 8pts chars

i’am sure multi size will work. I tested GFX over 2 lines already.

i’am working right now on a print String function. Will post it later…

I’am also planning to put everything on GitHub.

I appreciate your work.
Thank you

Hey,

use this to print a string. Maybe you need to add some \x00 after your fonts for a
little gap.

The function works right now but isn’t perfect. Will further work on this…

function printText(textString) { local cString = blob(); foreach(character in textString) { local cBytes = char_to_bin(format("%c", character)); // char Bytes local cChar = blob(); // current Char foreach(byte in cBytes) { cChar.writen(byte, 'b'); } cString.writeblob(cChar); } oled.write(i2c_address, "\\x40"+cString); }

printText("Chrischi");

Thank you
i tested it and the characters overlap a litle in the display

That’s why i said

Maybe you need to add some \\x00 after your fonts for a little gap.
All my chars have this added.