Thanks for help of JPMandon, we have OLED Display working
with libi2c on pinguino Board!
Pinguino full sourcecode here:
OLED.zip
//Program for I2C communication with a 128x64 OLED Display (http://www.seeedstudio.com)
//Marcus Fazzi 2010
#define LED 13
#define I2C_address 0x3c //i2c address of Display
#include <libI2C.c>
//For working with strings strlen() function
// #include <string.h>
#include "data.c"
unsigned char fill_OLED = 0x55;
unsigned char fill_string1[13]="Pinguino OLED";
unsigned char fill_string2[11]="OLED 128x64";
unsigned char fill_string3[16]="0123456789ABCDEF";
unsigned char fill_string4[2]="SS";
//=======================
void sendcommand(unsigned char com)
{
short dt[2] = { 0x80, com }; //command mode
I2C_write(I2C_address, dt, 2);
I2C_STOP(); //stop transmitting
}
//===================================
void SendChar(unsigned char dat)
{
short dt[2] = { 0x40, dat }; //data mode
I2C_write(I2C_address, dt, 2);
I2C_STOP(); //stop transmitting
}
//===================================
void setXY(unsigned char row,unsigned char col)
{
sendcommand(0xb0 + row); //set page address
sendcommand(0x00 + (8 * col & 0x0f)); //set low col address
sendcommand(0x10 + ((8 * col >> 4) & 0x0f)); //set high col address
}
//==================================
void clear_display()
{
unsigned char i,k;
for(k=0;k<8;k++)
{
setXY(k,0);
{
for(i=0;i<128;i++) //clear all COL
{
SendChar(0);
}
}
}
}
//==================================
void printChar(unsigned char ascii)
{
unsigned char i;
for(i=0;i<8;i++)
{
SendChar(myFont[ascii-0x20][i]);
}
}
//==================================
void sendStr(unsigned char *string, unsigned char len)
{
unsigned char i, j;
//setXY(0,0);
for(i=0;i<len;i++)
{
for(j=0;j<8;j++)
{
SendChar(myFont[*string-0x20][j]);
//SendChar(*string);
delay(10);
}
*string++;
}
}
//=================================
void init_OLED(void)
{
sendcommand(0xae); //display off
delay(50);
// sendcommand(0xa0); //seg re-map 0->127(default)
// sendcommand(0xa1); //seg re-map 127->0
// sendcommand(0xc8);
// delay(1000);
sendcommand(0xaf); //display on
delay(50);
}
void setup()
{
delay(500);
init_I2C();
//SSPADD=19; //Slow mode
init_OLED();
delay(10);
clear_display();
delay(50);
pinMode(LED, OUTPUT);
}
//========================
void loop()
{
short i;
clear_display();
delay(50);
sendcommand(0x20); //Set Memory Addressing Mode
sendcommand(0x02); //Set Memory Addressing Mode ab Page addressing mode(RESET)
sendcommand(0xa6); //Set Normal Display (default)
setXY(3,2);
sendStr(fill_string1, 13);
setXY(4,3);
sendStr(fill_string2, 11);
delay(2000);
sendcommand(0xa7); //Set Inverse Display
delay(2000);
clear_display();
delay(50);
setXY(0,0);
sendcommand(0xa6); //Set Normal Display
sendcommand(0xae); //display off
sendcommand(0x20); //Set Memory Addressing Mode
sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode
for(i=0;i<128*8;i++) //write a 128x64 picture
{
SendChar(logo[i]);
}
sendcommand(0xaf); //display on
delay(2000);
sendcommand(0xa7); //Set Inverse Display
delay(2000);
/*
while(1)
{
//sendcommand(0xa6); Set Normal Display
sendcommand(0x29); //Vertical and Horizontal Scroll Setup
sendcommand(0x00); //dummy byte
sendcommand(0x00); //define page0 as startpage address
sendcommand(0x00); //set time interval between each scroll ste as 6 frames
sendcommand(0x07); //define page7 as endpage address
sendcommand(0x01); //set vertical scrolling offset as 1 row
sendcommand(0x2f); //active scrolling
delay(3000);
};
*/
}