MannyC
Published

Getting Started With OLED Displays

An OLED is a type of diode that consists of an organic compound that emits light when current flows through it.

IntermediateProtip1,632
Getting Started With OLED Displays

Story

Read more

Code

Code snippet #1

C/C++
#include<Wire.h> //Include Wire library for I2C communication
#define HEIGHT 64
#define WIDTH 128
const int RST = 10; //Assign pin 10 for Reset  
int i; //Set variable i as integer
static unsigned char array[1024]; //buffer array/>
 
void setup() {
  pin_init(); //Initialize pins
  initialize_OLED(); //Initialize screen
  memset(array, 0, sizeof(array)); //Clear array
  draw_pixel(63,31); //Store pixel at (x,y) location
  Flush(); //Send data
}
 
void loop() {
  //Nothing happens here
}
 
void pin_init(){
  Serial.begin(9600); //Set baud for serial transmission
  pinMode(RST, OUTPUT); //Set RST as output
}
 
void initialize_OLED(){
  Wire.begin(); //Initialize I2C interface
  digitalWrite(RST, LOW); //Set reset pin low (active)
  delay(10); //Wait 100 ms
  digitalWrite(RST, HIGH); //Set reset pin high (inactive)  
  Wire.beginTransmission(0x3D); // Start communication with slave
  Wire.write(0x00); //Command stream
  Wire.write(0xAE); //Set display Off
  Wire.write(0xD5); //Set display clock divide ratio/oscillator frequency
  Wire.write(0x80);
  Wire.write(0xA8); //Set multiplex ratio
  Wire.write(0x3F);
  Wire.write(0xD3); //Set display offset
  Wire.write(0x00);
  Wire.write(0x40); //Set display start line
  Wire.write(0x8D); //Set charge pump
  Wire.write(0x14); //VCC generated by internal DC/DC circuit
  Wire.write(0xA1); //Set segment re-map 
  Wire.write(0xC0); //Set COM output scan direction
  Wire.write(0xDA); //Set COM pins hardware configuration
  Wire.write(0x12);
  Wire.write(0x81); //Set contrast control
  Wire.write(0xCF);
  Wire.write(0xD9); //Set pre-changed period
  Wire.write(0xF1);
  Wire.write(0xDB); //Set VCOMH Deselected level
  Wire.write(0x40);
  Wire.write(0xA4); //Set entire display on/off
  Wire.write(0xA6); //Set normal display 
  Wire.write(0x20); //Set memory address mode
  Wire.write(0x00); //Horizontal
  Wire.write(0xAF); //Set display on
  Wire.endTransmission(); //End communicaiton with slave
}
 
void draw_pixel(int x, int y)
  if((x<0) || (x>=WIDTH) || (y<0) || (y>=HEIGHT)){ //Check for boundaries
    return;
  }
  else{
    array[x+(y/8)*WIDTH] |= _BV((y%8)); //Store pixel in array
  }
}
 
void Flush(){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x00); //Command stream
 Wire.write(0x00); //Set lower column start address for page addressing mode
 Wire.write(0x10); //Set higher column start address for page addressing mode
 Wire.write(0x40); //Set display start line
 Wire.endTransmission(); //End communication with slave
 
 unsigned char twbrbackup = TWBR; //Two wire bit rate register
 TWBR = 12; //Set to 400 kHz
 
 for(unsigned short q=0; q<(WIDTH*HEIGHT/8); q++){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x40); //Data stream
 for(unsigned char w=0; w<16; w++){
    Wire.write(array[q]); //Transmit data to be displayed
    q++;
 }
 q--;
  Wire.endTransmission(); //End communication with slave
}
TWBR = twbrbackup;
}

Code snippet #2

C/C++
#include<Wire.h> //Include Wire library for I2C communication
#define HEIGHT 64
#define WIDTH 128
const int RST = 10; //Assign pin 10 for Reset  
int i; //Set variable i as integer
static unsigned char array[1024]; //Buffer array
 
void setup() {
  pin_init(); //Initialize pins
  initialize_OLED(); //Initialize screen
  memset(array, 0, sizeof(array)); //Initialize array with 0s
  line(0,63,0,31); //Draw line
  Flush(); //Send data
}
 
void loop() { 
}
 
void pin_init(){
  Serial.begin(9600); //Set baud for serial transmission
  pinMode(RST, OUTPUT); //Set RST as output
}
 
void initialize_OLED(){
  Wire.begin(); //Initialize I2C interface
  digitalWrite(RST, LOW); //Set RST pin low
  delay(100); //Wait 100 ms
  digitalWrite(RST, HIGH); //Set RST pin high
  Wire.beginTransmission(0x3D); // Start communication with slave
  Wire.write(0x00); //Command stream
  Wire.write(0xAE); //Set display Off
  Wire.write(0xD5); //Set display clock divide ratio/oscillator frequency
  Wire.write(0x80);
  Wire.write(0xA8); //Set multiplex ratio
  Wire.write(0x3F);
  Wire.write(0xD3); //Set display offset
  Wire.write(0x00);
  Wire.write(0x40); //Set display start line
  Wire.write(0x8D); //Set charge pump
  Wire.write(0x14); //VCC generated by internal DC/DC circuit
  Wire.write(0xA1); //Set segment re-map 
  Wire.write(0xC0); //Set COM output scan direction
  Wire.write(0xDA); //Set COM pins hardware configuration
  Wire.write(0x12);
  Wire.write(0x81); //Set contrast control
  Wire.write(0xCF);
  Wire.write(0xD9); //Set pre-changed period
  Wire.write(0xF1);
  Wire.write(0xDB); //Set VCOMH Deselected level
  Wire.write(0x40);
  Wire.write(0xA4); //Set entire display on/off
  Wire.write(0xA6); //Set normal/inverse display 
  Wire.write(0x20); //Set memory address mode
  Wire.write(0x00); //Horizontal
  Wire.write(0xAF); //Set display on
  Wire.endTransmission(); //End communicaiton with slave
}
 
/*Bresenham's line drawing algorithm*/
 
void line(int x1, int x2, int y1, int y2){
  int cx = x1;
  int cy = y1;
 
  int dx = x2-cx;
  int dy = y2-cy;
 
  if(dx<0){
   dx = 0-dx;
  }
  if(dy<0){
    dy = 0-dy;
  }
 
  int sx = 0;
  int sy = 0; 
  if(cx<x2){
   sx = 1; 
  }
  else{
   sx = -1;
  }
  if(cy<y2){
   sy = 1;
  }
  else{
   sy = -1;
  }
  int err = dx-dy;
 
  for(int n=0; n<1000; n++){
   draw_pixel(cx,cy);
  if((cx==x2) && (cy==y2)){ 
   return;
  }
  int e2 =2*err;
  if(e2>(0-dy)){
   err = err-dy;
   cx = cx+sx;
  }
  if(e2<dx){ 
   err = err+dx;
   cy = cy+sy;
   }
  }
 }
 
void draw_pixel(int x, int y){
  if((x<0) || (x>=WIDTH) || (y<0) || (y>=HEIGHT)){ //Check for boundaries
    return;
  }
  else{
    array[x+(y/8)*WIDTH] |= _BV((y%8)); //Store pixel in array
  }
}
 
void Flush(){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x00); //Command stream
 Wire.write(0x00);  //Set lower column start address for page addressing mode
 Wire.write(0x10); //Set higher column start address for page addressing mode
 Wire.write(0x40); //Set display start line
 Wire.endTransmission(); //End communication with slave
 
 unsigned char twbrbackup = TWBR; //Two wire bit rate register
 TWBR = 12; //Set to 400 kHz
 
 for(unsigned short q=0; q<(WIDTH*HEIGHT/8); q++){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x40); //Data stream
 for(unsigned char w=0; w<16; w++){
    Wire.write(array[q]); //Transmit data to be displayed
    q++;
 }
 q--;
  Wire.endTransmission(); //End communication with slave
}
TWBR = twbrbackup;
}

Code snippet #3

C/C++
#include<Wire.h> //Include Wire library for I2C communication
#define HEIGHT 64
#define WIDTH 128
const int RST = 10; //Assign pin 10 for Reset  
int i; //Set variable i as integer
static unsigned char array[1024]; //Buffer array
 
void setup() { 
  pin_init(); //Initialize pins
  initialize_OLED(); //Initialize screen
  memset(array, 0, sizeof(array)); //Initialize array with 0s
  square(117,127,53,63); //Draw square 
  Flush(); //Send data
}
 
void loop() { 
}
 
void pin_init(){
  Serial.begin(9600); //Set baud for serial transmission
  pinMode(RST, OUTPUT); //Set RST as output
}
 
void initialize_OLED(){
  Wire.begin(); //Initialize I2C interface
  digitalWrite(RST, LOW); //Set RST pin low
  delay(100); //Wait 100 ms
  digitalWrite(RST, HIGH); //Set RST pin high
  Wire.beginTransmission(0x3D); // Start communication with slave
  Wire.write(0x00); //Command stream
  Wire.write(0xAE); //Set display Off
  Wire.write(0xD5); //Set display clock divide ratio/oscillator frequency
  Wire.write(0x80);
  Wire.write(0xA8); //Set multiplex ratio
  Wire.write(0x3F);
  Wire.write(0xD3); //Set display offset
  Wire.write(0x00);
  Wire.write(0x40); //Set display start line
  Wire.write(0x8D); //Set charge pump
  Wire.write(0x14); //VCC generated by internal DC/DC circuit
  Wire.write(0xA1); //Set segment re-map 
  Wire.write(0xC0); //Set COM output scan direction
  Wire.write(0xDA); //Set COM pins hardware configuration
  Wire.write(0x12);
  Wire.write(0x81); //Set contrast control
  Wire.write(0xCF);
  Wire.write(0xD9); //Set pre-changed period
  Wire.write(0xF1);
  Wire.write(0xDB); //Set VCOMH Deselected level
  Wire.write(0x40);
  Wire.write(0xA4); //Set entire display on/off
  Wire.write(0xA6); //Set normal/inverse display 
  Wire.write(0x20); //Set memory address mode
  Wire.write(0x00); //Horizontal
  Wire.write(0xAF); //Set display on
  Wire.endTransmission(); //End communication with slave
}
 
/*Function to draw square*/
 
void square(int x1, int x2, int y1, int y2){
 
  int x, y; //Define x and y as integer variables
 
  Wire.beginTransmission(0x3D); //Start communication with slave
  for(x=x1; x<x2; x++){ //Iterate over x range, draw line on y1
    draw_pixel(x,y1); //Draw pixel
  }
  Wire.endTransmission(); //End communication with slave
 
  Wire.beginTransmission(0x3D); //Start communication with slave
  for(x=x1; x<x2; x++){ //Iterate over x range, draw line on y2
    draw_pixel(x,y2); //Draw pixel
  }
  Wire.endTransmission(); //End communication with slave
 
  Wire.beginTransmission(0x3D); //Start communication
  for(y=y1; y<y2; y++){ //Iterate over y range, draw line on x1
    draw_pixel(x1,y); //Draw pixel
  }
  Wire.endTransmission(); //End communication with slave
 
  Wire.beginTransmission(0x3D); //Start communication with slave
  for(y=y1; y<y2; y++){ //Iterate over y range, draw line on x2 
    draw_pixel(x2,y); //Draw pixel
  }
  Wire.endTransmission(); //End communication with slave
}
 
void draw_pixel(int x, int y){
  if((x<0) || (x>=WIDTH) || (y<0) || (y>=HEIGHT)){ //Check for boundaries
    return;
  }
  else{
    array[x+(y/8)*WIDTH] |= _BV((y%8)); //Store pixel in array
  }
}
 
void Flush(){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x00); //Command stream
 Wire.write(0x00); //Set lower column start address for page addressing mode
 Wire.write(0x10); //Set higher column start address for page addressing mode
 Wire.write(0x40); //Set display start line
 Wire.endTransmission(); //End communication with slave
 
 unsigned char twbrbackup = TWBR; //Two wire bit rate register
 TWBR = 12; //Set to 400 kHz
 
 for(unsigned short q=0; q<(WIDTH*HEIGHT/8); q++){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x40); //Data stream
 for(unsigned char w=0; w<16; w++){
    Wire.write(array[q]); //Transmit data to be displayed
    q++;
 }
 q--;
  Wire.endTransmission(); //End communication with slave
}
TWBR = twbrbackup;
}

Code snippet #4

C/C++
#include<Wire.h> //Include Wire library for I2C communication
#define HEIGHT 64
#define WIDTH 128
const int RST = 10; //Assign pin 10 for Reset 
int i; //Set variable i as integer
static unsigned char array[1024]; //Buffer array
 
void setup() {
  pin_init(); //Initialize pins
  initialize_OLED(); //Initialize screen
  memset(array, 0, sizeof(array)); //Initialize array with 0s
  circle(63,31,10); //Draw circle, (x,y,R)
  Flush(); //Send data
}
 
void loop() {   
}
 
void pin_init(){
  Serial.begin(9600); //Set baud for serial transmission
  pinMode(RST, OUTPUT); //Set RST as output
}
 
void initialize_OLED(){
  Wire.begin(); //Initialize I2C interface
  digitalWrite(RST, LOW); //Set RST pin low
  delay(100); //Wait 100 ms
  digitalWrite(RST, HIGH); //Set RST pin high
  Wire.beginTransmission(0x3D); // Start communication with slave
  Wire.write(0x00); //Command stream
  Wire.write(0xAE); //Set display Off
  Wire.write(0xD5); //Set display clock divide ratio/oscillator frequency
  Wire.write(0x80);
  Wire.write(0xA8); //Set multiplex ratio
  Wire.write(0x3F);
  Wire.write(0xD3); //Set display offset
  Wire.write(0x00);
  Wire.write(0x40); //Set display start line
  Wire.write(0x8D); //Set charge pump
  Wire.write(0x14); //VCC generated by internal DC/DC circuit
  Wire.write(0xA1); //Set segment re-map 
  Wire.write(0xC0); //Set COM output scan direction
  Wire.write(0xDA); //Set COM pins hardware configuration
  Wire.write(0x12);
  Wire.write(0x81); //Set contrast control
  Wire.write(0xCF);
  Wire.write(0xD9); //Set pre-changed period
  Wire.write(0xF1);
  Wire.write(0xDB); //Set VCOMH Deselected level
  Wire.write(0x40);
  Wire.write(0xA4); //Set entire display on/off
  Wire.write(0xA6); //Set normal/inverse display 
  Wire.write(0x20); //Set memory address mode
  Wire.write(0x00); //Horizontal
  Wire.write(0xAF); //Set display on
  Wire.endTransmission(); //End communication with slave
}
 
/*Midpoint circle algorithm*/
 
void circle(int x0, int y0, int R){
  int x = R; //Set x equal to radius
  int y = 0;
  int de = 1-x; 
 
  while(x>=y){
    draw_pixel(x+x0, y+y0); //First octant
    draw_pixel(y+x0, x+y0); //Second octant 
    draw_pixel(-y+x0, x+y0); //Third octant
    draw_pixel(-x+x0, y+y0); //Fourth octant
    draw_pixel(-x+x0, -y+y0); //Fifth octant
    draw_pixel(-y+x0, -x+y0); //Sixth octant
    draw_pixel(y+x0, -x+y0); //Seventh octant
    draw_pixel(x+x0, -y+y0); //Eight octant                 
    y++; 
    if(de<=0){
      de += 2*y+1;
    }
    else{ 
      x--;
      de += 2*(y-x)+1; 
   }
  }
}
 
void draw_pixel(int x, int y){
  if((x<0) || (x>=WIDTH) || (y<0) || (y>=HEIGHT)){ //Check for boundaries
    return;
  }
  else{
    array[x+(y/8)*WIDTH] |= _BV((y%8)); //Store pixel in array
  }
}
 
void Flush(){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x00); //Command stream
 Wire.write(0x00); //Set lower column start address for page addressing mode
 Wire.write(0x10); //Set higher column start address for page addressing mode
 Wire.write(0x40); //Set display start line
 Wire.endTransmission(); //End communication with slave
 
 unsigned char twbrbackup = TWBR; //Two wire bit rate register
 TWBR = 12; //Set to 400kHz
 
 for(unsigned short q=0; q<(WIDTH*HEIGHT/8); q++){
 Wire.beginTransmission(0x3D); //Start communication with slave
 Wire.write(0x40); //Data stream
 for(unsigned char w=0; w<16; w++){
    Wire.write(array[q]); //Transmit data to be displayed
    q++;
 }
 q--;
  Wire.endTransmission(); //End communication with slave
}
TWBR = twbrbackup;
}
 

Code snippet #5

C/C++
#include<Wire.h> //Include Wire library for I2C communication
 
const int RST = 10; //Assign pin 10 for Reset
int i; //Set variable i as integer
const unsigned char js[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0,
0x80, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0F, 0x1F,
0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x1F, 0x3F, 0x3F,
0x3F, 0x3F, 0x1F, 0x1F, 0x3F, 0x3F, 0x1F, 0x1F, 0x3F, 0x3F, 0x1F, 0x1F, 0x3F, 0x3F, 0x1F, 0x1F,
0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x80, 0x60,
0x50, 0xA0, 0xA8, 0x50, 0xA0, 0x5C, 0xA4, 0x48, 0xA8, 0x50, 0xA6, 0x58, 0x90, 0x64, 0x58, 0xA4,
0x58, 0x24, 0x98, 0x68, 0xA8, 0x54, 0x68, 0x22, 0x50, 0xA4, 0x48, 0xB4, 0xA0, 0x5C, 0x94, 0x48,
0x94, 0x68, 0xA4, 0x50, 0x58, 0xA4, 0x58, 0x94, 0x24, 0x58, 0xA4, 0x58, 0xA0, 0x58, 0x04, 0x00,
0x54, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x84, 0x00, 0x60, 0x2A, 0x90, 0x64, 0x58, 0xA4, 0x58, 0x24, 0x98, 0x68, 0xA8, 0x54, 0x68, 0x24,
0x24, 0x58, 0xA4, 0x58, 0xA4, 0x48, 0x94, 0x68, 0x90, 0x6A, 0xD4, 0x28, 0x20, 0xD4, 0x68, 0x12,
0x50, 0xA4, 0x48, 0xB4, 0xA4, 0x18, 0x50, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x25, 0x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0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF0, 0xF0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xF0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xF0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x03, 0x03, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x07, 0x0F, 0x07, 0x0F, 0x07, 0x07, 0x0F, 0x07, 0x0F, 0x0F, 0x07, 0x0F, 0x07, 0x07, 0x0F, 0x07, 0x0F, 0x0F, 0x07, 0x0F, 0x07, 0x07, 0x0F, 0x07, 0x0F, 0x0F, 0x07, 0x0F, 0x07, 0x07, 0x0F, 0x07, 0x0F, 0x0F, 0x07, 0x0F, 0x07, 0x07, 0x07, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x03, 0x07, 0x07, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };   void setup() { 
  pin_init(); //Initialize pins 
  initialize_OLED(); //Initialize screen 
  pattern(); //Display image 
} 
  void loop() {
} 
  void pin_init(){
  Serial.begin(9600); //Set baud for serial transmission 
  pinMode(RST, OUTPUT); //Set RST as output 
} 
  void initialize_OLED(){ 
  Wire.begin(); //Initialize I2C interface 
  digitalWrite(RST, LOW); //Set RST pin low 
  delay(100); //Wait 100 ms 
  digitalWrite(RST, HIGH); //Set RST pin high 
  Wire.beginTransmission(0x3D); // Start communication with slave 
  Wire.write(0x00); //Command stream 
  Wire.write(0xAE); //Set display Off 
  Wire.write(0xD5); //Set display clock divide ratio/oscillator frequency   Wire.write(0x80); 
  Wire.write(0xA8); //Set multiplex ratio 
  Wire.write(0x3F); 
  Wire.write(0xD3); //Set display offset 
  Wire.write(0x00); 
  Wire.write(0x40); //Set display start line 
  Wire.write(0x8D); //Set charge pump 
  Wire.write(0x14); //VCC generated by internal DC/DC circuit 
  Wire.write(0xA1); //Set segment re-map  
  Wire.write(0xC8); //Set COM output scan direction 
  Wire.write(0xDA); //Set COM pins hardware configuration 
  Wire.write(0x12); 
  Wire.write(0x81); //Set contrast control 
  Wire.write(0xCF); 
  Wire.write(0xD9); //Set pre-changed period 
  Wire.write(0xF1); 
  Wire.write(0xDB); //Set VCOMH Deselected level 
  Wire.write(0x40); 
  Wire.write(0xA4); //Set entire display on/off 
  Wire.write(0xA6); //Set normal/inverse display  
  Wire.write(0x20); //Set memory address mode 
  Wire.write(0x00); //Vertical 
  Wire.write(0xAF); //Set display on 
  Wire.endTransmission(); //End communication with slave 
} 
  
void pattern(){ 
  for(i=0; i<1024; i++){ 
  Wire.beginTransmission(0x3D); //Start communication with slave 
  Wire.write(0x40); //Data stream 
  for(unsigned char x=0; x<16; x++){
     Wire.write(js[i]); //Transmit data to be displayed
     i++;
  }
  i--;
  Wire.endTransmission(); //End communication with slave
 }
}
 

Credits

MannyC

MannyC

1 project • 0 followers

Comments