极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6848|回复: 9

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

[复制链接]
发表于 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/Ladyada  for 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_WIDTH  16
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[NUMFLAKES][3];
  srandom(666);     // whatever seed

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

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], 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[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
        icons[f][XPOS] = random() % display.width();
        icons[f][YPOS] = 0;
        icons[f][DELTAY] = 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();
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-3-25 14:30:18 | 显示全部楼层
SSD1306 chip 果塊, 唔係 12864 嗎?  家陣變左 2864?  28 x 64 pixel?

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

使用道具 举报

发表于 2015-3-25 16:32:00 | 显示全部楼层
OLED啊?接线简单
回复 支持 反对

使用道具 举报

发表于 2015-3-25 21:57:22 | 显示全部楼层
你遇到什么问题了,请具体说明。提问时请说明你的接线,遇到的问题,采取解决的步骤等,越详细得到的帮助越具体。
回复 支持 反对

使用道具 举报

发表于 2015-3-26 09:58:14 | 显示全部楼层
这个模块不是有很好的例子吗。有什么问题?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-3-26 11:14:16 | 显示全部楼层
老胖熊 发表于 2015-3-26 09:58
这个模块不是有很好的例子吗。有什么问题?

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

使用道具 举报

 楼主| 发表于 2015-3-26 11:16:26 | 显示全部楼层
gongsixingxi 发表于 2015-3-26 11:14
我用的Arduino mega 2560的板子,接线老是不显示
SCL  -> SCL
     SDA  -> SDA

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

使用道具 举报

发表于 2015-3-26 11:41:46 | 显示全部楼层
gongsixingxi 发表于 2015-3-26 11:16
上面这个例程是Arduino uno的,那个接线是A4,A5,  这些接线我都试了,是不是我接线那里有问题哦


MEGA2560的SDA,SCL不在A4,A5
去看一下pinout吧!!
回复 支持 反对

使用道具 举报

发表于 2015-3-27 01:15:00 | 显示全部楼层
Super169 发表于 2015-3-25 14:30
SSD1306 chip 果塊, 唔係 12864 嗎?  家陣變左 2864?  28 x 64 pixel?

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

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

使用道具 举报

发表于 2015-3-30 11:23:17 | 显示全部楼层
gongsixingxi 发表于 2015-3-26 11:14
我用的Arduino mega 2560的板子,接线老是不显示
SCL  -> SCL
     SDA  -> SDA

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

OLED 软件SPI:
     D/C  DC     11
     RST  RESET  13
     SDA  MOSI   9
     SCL  CLK    10
     VCC         +5V
     GND         GND
           CS     12
   如果使用硬件SPI,按以下方式连接和定义
     D/C  DC     9
          CS     10
     RST  RESET  8
     SDA  MOSI   11   mini pro 已经定义,不需要再定义,这里是接线提示。
          MISO   12   mini pro 已经定义,不需要再定义,这里是接线提示。  
     SCL  CLK    13   mini pro 已经定义,不需要再定义,这里是接线提示。

中间那一列你不必介意,我用的是mini pro,你的板子端口定义要查一下接口图,坛子里有,自己找一下吧。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-7 23:34 , Processed in 0.043308 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表