gongsixingxi 发表于 2015-3-25 14:04:28

哪为高手用过这个模块,求指教

/*********************************************************************
// #
// # Editor   : Lauren from DFRobot
// # Date       : 14.11.2012
// # E-Mail                : [email protected]

// # Product name: OLED 2864 Display module
// # Product SKU : TOY0007
// # Version   : 1.0

// # Update the Adafruit SSD1306 library to make it work
// # Description:
// #                 show a simple animation

// # Connection:
// #      SCL-> A5(Uno)/D3(Leonardo)
// #      SDA-> A4(Uno)/D2(Leonardo)
// #      RST-> D4
// #      DC-> GND
// #      3.3-> 3.3v
// #      g-> GND
// #
// # Product page:
// #                 http://www.dfrobot.com/index.php?route=product/product&product_id=802#.UKyOjE09ha0

This is an example for our Monochrome OLEDs based on SSD1306 drivers

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98

This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyadafor Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH16
static unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {               
Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC, 0x3c);// initialize with the I2C addr 0x3C (for the 128x64)
// init done

display.display(); // show splashscreen
delay(2000);
display.clearDisplay();   // clears the screen and buffer

// draw a single pixel
display.drawPixel(10, 10, WHITE);
display.display();
delay(2000);
display.clearDisplay();

// draw many lines
testdrawline();
display.display();
delay(2000);
display.clearDisplay();

// draw rectangles
testdrawrect();
display.display();
delay(2000);
display.clearDisplay();

// draw multiple rectangles
testfillrect();
display.display();
delay(2000);
display.clearDisplay();

// draw mulitple circles
testdrawcircle();
display.display();
delay(2000);
display.clearDisplay();

// draw a white circle, 10 pixel radius
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
display.display();
delay(2000);
display.clearDisplay();

testdrawroundrect();
delay(2000);
display.clearDisplay();

testfillroundrect();
delay(2000);
display.clearDisplay();

testdrawtriangle();
delay(2000);
display.clearDisplay();
   
testfilltriangle();
delay(2000);
display.clearDisplay();

// draw the first ~12 characters in the font
testdrawchar();
display.display();
delay(2000);
display.clearDisplay();

// draw scrolling text
testscrolltext();
delay(2000);
display.clearDisplay();

// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.display();
delay(2000);

// miniature bitmap display
display.clearDisplay();
display.drawBitmap(30, 16,logo16_glcd_bmp, 16, 16, 1);
display.display();

// invert the display
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);

// draw a bitmap icon and 'animate' movement
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}


void loop() {

}


void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons;
srandom(666);   // whatever seed

// initialize
for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons = random() % display.width();
    icons = 0;
    icons = random() % 5 + 1;
   
    Serial.print("x: ");
    Serial.print(icons, DEC);
    Serial.print(" y: ");
    Serial.print(icons, DEC);
    Serial.print(" dy: ");
    Serial.println(icons, DEC);
}

while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons, icons, logo16_glcd_bmp, w, h, WHITE);
    }
    display.display();
    delay(200);
   
    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons, icons,logo16_glcd_bmp, w, h, BLACK);
      // move it
      icons += icons;
      // if its gone, reinit
      if (icons > display.height()) {
        icons = random() % display.width();
        icons = 0;
        icons = random() % 5 + 1;
      }
    }
   }
}


void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);

for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    if ((i > 0) && (i % 21 == 0))
      display.println();
}   
display.display();
}

void testdrawcircle(void) {
for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
    display.display();
}
}

void testfillrect(void) {
uint8_t color = 1;
for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
}
}

void testdrawtriangle(void) {
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    display.display();
}
}

void testfilltriangle(void) {
uint8_t color = WHITE;
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, WHITE);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
}
}

void testdrawroundrect(void) {
for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
    display.display();
}
}

void testfillroundrect(void) {
uint8_t color = WHITE;
for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
}
}
   
void testdrawrect(void) {
for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
    display.display();
}
}

void testdrawline() {
for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, WHITE);
    display.display();
}
for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, WHITE);
    display.display();
}
delay(250);

display.clearDisplay();
for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, WHITE);
    display.display();
}
for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
    display.display();
}
delay(250);

display.clearDisplay();
for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
    display.display();
}
for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
    display.display();
}
delay(250);

display.clearDisplay();
for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, WHITE);
    display.display();
}
for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
    display.display();
}
delay(250);
}

void testscrolltext(void) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.clearDisplay();
display.println("scroll");
display.display();

display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);   
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
}

Super169 发表于 2015-3-25 14:30:18

SSD1306 chip 果塊, 唔係 12864 嗎?家陣變左 2864?28 x 64 pixel?

樓主會唔會懶左 D, 連有乜問題都唔講, 只係 copy 段 code 再貼張相出黎, geek-workshop 幾時變左 猜謎區?

suoma 发表于 2015-3-25 16:32:00

OLED啊?接线简单

沧海笑1122 发表于 2015-3-25 21:57:22

你遇到什么问题了,请具体说明。提问时请说明你的接线,遇到的问题,采取解决的步骤等,越详细得到的帮助越具体。

老胖熊 发表于 2015-3-26 09:58:14

这个模块不是有很好的例子吗。有什么问题?

gongsixingxi 发表于 2015-3-26 11:14:16

老胖熊 发表于 2015-3-26 09:58 static/image/common/back.gif
这个模块不是有很好的例子吗。有什么问题?

我用的Arduino mega 2560的板子,接线老是不显示
SCL-> SCL
   SDA-> SDA
      RST-> D4
      DC-> GND
      3.3-> 3.3v
      g-> GND
这是我的接线图

gongsixingxi 发表于 2015-3-26 11:16:26

gongsixingxi 发表于 2015-3-26 11:14 static/image/common/back.gif
我用的Arduino mega 2560的板子,接线老是不显示
SCL-> SCL
   SDA-> SDA


上面这个例程是Arduino uno的,那个接线是A4,A5,这些接线我都试了,是不是我接线那里有问题哦

hsr18299 发表于 2015-3-26 11:41:46

gongsixingxi 发表于 2015-3-26 11:16 static/image/common/back.gif
上面这个例程是Arduino uno的,那个接线是A4,A5,这些接线我都试了,是不是我接线那里有问题哦

MEGA2560的SDA,SCL不在A4,A5
去看一下pinout吧!!

布列松 发表于 2015-3-27 01:15:00

Super169 发表于 2015-3-25 14:30 static/image/common/back.gif
SSD1306 chip 果塊, 唔係 12864 嗎?家陣變左 2864?28 x 64 pixel?

樓主會唔會懶左 D, 連有乜問題都唔 ...

请问这个是什么模块来的,有无具体的代码例子,这个OLED好似我最近都想买个

老胖熊 发表于 2015-3-30 11:23:17

gongsixingxi 发表于 2015-3-26 11:14 static/image/common/back.gif
我用的Arduino mega 2560的板子,接线老是不显示
SCL-> SCL
   SDA-> SDA


问问题的时候,应该把你的问题写清楚,这样看起来稍微明白你想问什么了。我用过类似的模块,不过我买的那个模块字印错了,把我的接线方式告诉你,供参考。

OLED 软件SPI:
   D/CDC   11
   RSTRESET13
   SDAMOSI   9
   SCLCLK    10
   VCC         +5V
   GND         GND
         CS   12
   如果使用硬件SPI,按以下方式连接和定义
   D/CDC   9
          CS   10
   RSTRESET8
   SDAMOSI   11   mini pro 已经定义,不需要再定义,这里是接线提示。
          MISO   12   mini pro 已经定义,不需要再定义,这里是接线提示。
   SCLCLK    13   mini pro 已经定义,不需要再定义,这里是接线提示。

中间那一列你不必介意,我用的是mini pro,你的板子端口定义要查一下接口图,坛子里有,自己找一下吧。
页: [1]
查看完整版本: 哪为高手用过这个模块,求指教