• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
Previous Next

Use SPI OLED on pcDuino

Posted by: , December 25, 2014

[vc_row][vc_column][vc_column_text]OLED is the organic Light Emitting Diode. For the OLED has the good feature of self-luminous, no needing back-light,high contrast ratio, thin,wide visual angle, rapid reaction speed, can use at flexural board, wide temperature range, structure and sample processing manufacture  ect , which is regarded as the next generation flat surface display new applied technology. LCD need back light, but OLED do not need, for it is self-luminous. So the same display, OLED is much better. To the recent technology, OLED size is hard to large scale, but the resolution ratio can improve. This screen can use the drive IC SSD1306, every page of SSD1306 include 128 byte, total 8 pages, the matrix array is just exactly 128*64.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”The definition of Pin” tab_id=”1419519551-1-58″][vc_column_text]

  • GND
  • VCC:positive(3V~5.5V)
  • DO:SPI clock  line pin
  • DI:SPI data line pin
  • RES:reset pin
  • DC:data and order pin
  • CS:chip selection pin

[/vc_column_text][/vc_tab][vc_tab title=”Hardware prepare” tab_id=”1419519551-2-71″][vc_column_text]1  x  pcDuino3 

1  x OLED

Jumper lines

1  x  board[/vc_column_text][/vc_tab][vc_tab title=”Test Code” tab_id=”1419519602013-2-8″][vc_column_text]

#include "SSD1306.h"
 
#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13
 
SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
 
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00, 
0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };
 
void setup()   {                
  Serial.begin(9600);
 
  // If you want to provide external 7-9V VCC, uncomment next line and comment the one after
  //oled.ssd1306_init(SSD1306_EXTERNALVCC);
 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
  // init done
 
  oled.display(); // show splashscreen
  //while(1);
  delay(3000);
     // clears the screen and buffer
 
  // Fill screen
  oled.fillrect(0, 0, SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, WHITE);
  oled.display();
  delay(500);
 
  // draw a single pixel
  oled.setpixel(10, 10, WHITE);
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw many lines
  testdrawline();
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw rectangles
  testdrawrect();
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw multiple rectangles
  testfillrect();
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw mulitple circles
  testdrawcircle();
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw a white circle, 10 pixel radius, at location (32,32)
  oled.fillcircle(32, 32, 10, WHITE);
  oled.display();
  delay(3000);
  oled.clear();
 
  // draw the first ~12 characters in the font
  testdrawchar();
  oled.display();
  delay(3000);
  oled.clear();
 
  // miniature bitmap display
  oled.drawbitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  oled.display();
 
}
 
void loop()                     
{
  // draw a string at location (0,0)
  oled.clear();
  oled.drawstring(0, 1, "Hello pcDuino");
  oled.drawstring(0, 4, "www.LinkSprite.com");
  oled.display();
  while(1);
}
 
void testdrawchar(void) {
  for (uint8_t i=0; i < 168; i++) {
    oled.drawchar((i % 21) * 6, i/21, i);
  }    
}
 
void testdrawcircle(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
    oled.drawcircle(63, 31, i, WHITE);
  }
}
 
void testdrawrect(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
    oled.drawrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, WHITE);
  }
}
 
void testfillrect(void) {
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i++) {
      // alternate colors for moire effect
    oled.fillrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, i%2);
  }
}
 
void testdrawline() {
  for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
    oled.drawline(0, 0, i, SSD1306_LCDHEIGHT-1, WHITE);
    oled.display();
  }
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
    oled.drawline(0, 0, SSD1306_LCDWIDTH-1, i, WHITE);
    oled.display();
  }
 
  delay(1000);
 
  for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
    oled.drawline(i, SSD1306_LCDHEIGHT-1, 0, 0, BLACK);
    oled.display();
  }
  for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
    oled.drawline(SSD1306_LCDWIDTH - 1, i, 0, 0, BLACK);
    oled.display();
  }
}

[/vc_column_text][/vc_tab][vc_tab title=”Run test” tab_id=”1419519603075-3-0″][vc_column_text]1. wire according to the following instruction: 

OLED GND –> pcDuino GND

OLED VCC –> pcDuino 3.3V

OLED D0  –> pcDuino D10

OLED DI –> pcDuino D9

OLED RES –> pcDuino D13

OLED D/C –> pcDuino D11

OLED CS –> pcDuino D12

图片1

 

2. download the test code in the attachment, then open in the Arduino IDE, click and compile:

3. Run effect as the following picture: 

Display the  character

图片6图片2

Display the round dot:

图片3

Display segment:

图片4图片5[/vc_column_text][/vc_tab][vc_tab title=”Download the attachment” tab_id=”1419520469897-4-5″][vc_column_text]Test Code: spi_olde_test

SSD1306 Datasheet :SSD1306[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Share!
Tweet

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors