极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 188683|回复: 64

Arduino驱动OLED显示屏试验

  [复制链接]
发表于 2012-3-11 14:22:21 | 显示全部楼层 |阅读模式
本帖最后由 thomas 于 2012-3-11 16:45 编辑

Arduino入手快一个月了,总想尝试做点儿什么。距离我上一次接触单片机已经是15年前了,不知怎么就鬼使神差的买了Arduino开发板。以前我用的是更简单的PIC58,用BASIC编程的机器,非常好用,后来没有卖了。
言归正传,雪季快结束了,我想做个显示时速、海拔、坡度的滑雪镜。于是,把目光放在了OLED显示屏上。这东西小巧,华丽,耗电低,同时低温性能非常出色。淘宝败了几个,主要是用96*16的微型显示屏。同时也败了个大点儿的128*64屏,双色的(分两色显示,不是真正的双色概念)非常便宜,96*16的15米一块,128*64的驱动板才32米。

板子的到手,先拿大的试验。焊接好排针,接上电,按照普通12864的接法接上了。然后满怀期待的刷入测试程序。。。屏幕一片黑。Arduino板子的led灯全黑,计算机提示未知硬件。木瓜一样发了10秒呆,然后闻到一股久违的糊味。。。果断拔电,板子已经发烫了。
(待续)
很明显接近短路状态,用表一量,也没短路。
莫非是我焊针时焊坏了?可是我很谨慎啊,或者买来就是坏的?幸好买了两块,另一块先不焊,直接接电看看。
Arduino板子又黑了,还是短路现象,立即断电。
反复查看资料,发现一行红字。
----------------------------------------------------
MCU Bus Interface Pin Selection
Pin Name
I2C
Interface
6800-parallel
interface (8 bit)
8080-parallel
4-wire Serial
interface
3-wire Serial
interface
BS0 0 0 0 0 1
BS1 1 0 1 0 0
BS2 0 1 1 0 0
Note
(1) 0 is connected to VSS
(2) 1 is connected to VDD
interface(8 bit)
(3) Default interface is 80 80-parallel.(4) Please tell us the specific requirement of your company,we will provide appropriate interface to you.
----------------------------------------------------
数据模式分4种,用3组跳线选取,默认是80 80-parallel。
我小心翼翼的把贴片跳线改动了一下,把默认的011改成了000。
可,这绝不可能是短路的原因啊?我拿着板子仔细琢磨,发现了惊人的问题。
按照常识,电路板大面积覆铜的应该为GND,而按照资料显示,VSS的是PIN1,VDD是PIN2。不会是出厂图纸有问题吧,反正烧就烧把,我把电源极性换了一下,漂亮的图案出现了~
原厂资料有错误,标错了引脚极性,注意!!!





















本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2012-3-11 14:36:57 | 显示全部楼层
上个代码呗
回复 支持 反对

使用道具 举报

发表于 2012-3-11 15:02:44 | 显示全部楼层
这个比1602真的是强呀!!
回复 支持 反对

使用道具 举报

发表于 2012-3-11 15:52:46 | 显示全部楼层
我想做个显示时速、海拔、坡度的滑雪镜

难道你要把他装在镜片上?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-3-11 16:04:41 | 显示全部楼层
本帖最后由 thomas 于 2015-2-2 23:37 编辑

编辑帖子老出错。先说接线图。
由于OLED多工作于3.3v,因此为了匹配输入端电压,用了一块缓冲器CD4050.
介绍
CD4050是非反相六缓冲器,具有仅用一电源电压(VCC)进行逻辑电平转换的特征。用作逻辑电平转换时,输入高电平电压(VIH)超过电源电压VCC。该器件主要用作COS/MOS到DTL/TTL的转换器,能直接驱动两个DTL/TTL负载。16引出端是空脚 ,与内部电路无连接。

接线

Arduino IO端口         CD4050引脚
DIGITAL
9    ----------------------   14  
10  ----------------------   11
11  ----------------------   9
12  ----------------------   5
13  ----------------------   3
+5v     ------------------  1
GND   -------------------  8



LM096-128064引脚/ 功能        CD4050引脚
1  ------VDD---------------------------   1
2  ------VSS----------------------------   8
3 ------- CS# --------------------------  4
4 --------RES# -----------------------   2
5 --------D/C#------------------------  10
8--------- D0   -----------------------   12
9 -------- D1 --------------------------  15


代码

  1. #define OLED_DC 11
  2. #define OLED_CS 12
  3. #define OLED_CLK 10
  4. #define OLED_MOSI 9
  5. #define OLED_RESET 13

  6. #include <SSD1306.h>

  7. SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

  8. #define NUMFLAKES 10
  9. #define XPOS 0
  10. #define YPOS 1
  11. #define DELTAY 2


  12. #define LOGO16_GLCD_HEIGHT 16
  13. #define LOGO16_GLCD_WIDTH  16
  14. static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
  15. 0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
  16. 0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };


  17. void setup()   {               
  18.   Serial.begin(9600);
  19.   
  20.   // If you want to provide external 7-9V VCC, uncomment next line and comment the one after
  21.   //oled.ssd1306_init(SSD1306_EXTERNALVCC);
  22.   
  23.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  24.   oled.ssd1306_init(SSD1306_SWITCHCAPVCC);

  25.   // init done
  26.   
  27.   oled.display(); // show splashscreen
  28.   delay(2000);
  29.   oled.clear();   // clears the screen and buffer

  30.   // Fill screen
  31.   oled.fillrect(0, 0, SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, WHITE);
  32.   oled.display();
  33.   delay(2000);

  34.   // draw a single pixel
  35.   oled.setpixel(10, 10, WHITE);
  36.   oled.display();
  37.   delay(2000);
  38.   oled.clear();

  39.   // draw many lines
  40.   testdrawline();
  41.   oled.display();
  42.   delay(2000);
  43.   oled.clear();

  44.   // draw rectangles
  45.   testdrawrect();
  46.   oled.display();
  47.   delay(2000);
  48.   oled.clear();

  49.   // draw multiple rectangles
  50.   testfillrect();
  51.   oled.display();
  52.   delay(2000);
  53.   oled.clear();

  54.   // draw mulitple circles
  55.   testdrawcircle();
  56.   oled.display();
  57.   delay(2000);
  58.   oled.clear();

  59.   // draw a white circle, 10 pixel radius, at location (32,32)
  60.   oled.fillcircle(32, 32, 10, WHITE);
  61.   oled.display();
  62.   delay(2000);
  63.   oled.clear();

  64.   // draw the first ~12 characters in the font
  65.   testdrawchar();
  66.   oled.display();
  67.   delay(2000);
  68.   oled.clear();

  69.   // draw a string at location (0,0)
  70.   oled.drawstring(0, 0, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation");
  71.   oled.display();
  72.   delay(2000);
  73.   oled.clear();

  74.   // miniature bitmap display
  75.   oled.drawbitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  76.   oled.display();

  77.   // invert the display
  78.   oled.ssd1306_command(SSD1306_INVERTDISPLAY);
  79.   delay(1000);
  80.   oled.ssd1306_command(SSD1306_NORMALDISPLAY);
  81.   delay(1000);

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


  85. void loop()                     
  86. {
  87.   for (uint8_t i=0; i<SSD1306_LCDWIDTH; i++) {
  88.     for (uint8_t j=0; j<SSD1306_LCDHEIGHT; j++) {
  89.       oled.setpixel(i, j, WHITE);
  90.       oled.display();
  91.     }
  92.   }
  93.   

  94. }


  95. void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  96.   uint8_t icons[NUMFLAKES][3];
  97.   srandom(666);     // whatever seed

  98.   // initialize
  99.   for (uint8_t f=0; f< NUMFLAKES; f++) {
  100.     icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
  101.     icons[f][YPOS] = 0;
  102.     icons[f][DELTAY] = random() % 5 + 1;
  103.    
  104.     Serial.print("x: ");
  105.     Serial.print(icons[f][XPOS], DEC);
  106.     Serial.print(" y: ");
  107.     Serial.print(icons[f][YPOS], DEC);
  108.     Serial.print(" dy: ");
  109.     Serial.println(icons[f][DELTAY], DEC);
  110.   }

  111.   while (1) {
  112.     // draw each icon
  113.     for (uint8_t f=0; f< NUMFLAKES; f++) {
  114.       oled.drawbitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
  115.     }
  116.     oled.display();
  117.     delay(200);
  118.    
  119.     // then erase it + move it
  120.     for (uint8_t f=0; f< NUMFLAKES; f++) {
  121.       oled.drawbitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
  122.       // move it
  123.       icons[f][YPOS] += icons[f][DELTAY];
  124.       // if its gone, reinit
  125.       if (icons[f][YPOS] > SSD1306_LCDHEIGHT) {
  126.         icons[f][XPOS] = random() % SSD1306_LCDWIDTH;
  127.         icons[f][YPOS] = 0;
  128.         icons[f][DELTAY] = random() % 5 + 1;
  129.       }
  130.     }
  131.   }
  132. }


  133. void testdrawchar(void) {
  134.   for (uint8_t i=0; i < 168; i++) {
  135.     oled.drawchar((i % 21) * 6, i/21, i);
  136.   }   
  137. }

  138. void testdrawcircle(void) {
  139.   for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
  140.     oled.drawcircle(63, 31, i, WHITE);
  141.   }
  142. }

  143. void testdrawrect(void) {
  144.   for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=2) {
  145.     oled.drawrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, WHITE);
  146.   }
  147. }

  148. void testfillrect(void) {
  149.   for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i++) {
  150.       // alternate colors for moire effect
  151.     oled.fillrect(i, i, SSD1306_LCDWIDTH-i, SSD1306_LCDHEIGHT-i, i%2);
  152.   }
  153. }

  154. void testdrawline() {
  155.   for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
  156.     oled.drawline(0, 0, i, SSD1306_LCDHEIGHT-1, WHITE);
  157.     oled.display();
  158.   }
  159.   for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
  160.     oled.drawline(0, 0, SSD1306_LCDWIDTH-1, i, WHITE);
  161.     oled.display();
  162.   }

  163.   delay(1000);

  164.   for (uint8_t i=0; i<SSD1306_LCDWIDTH; i+=4) {
  165.     oled.drawline(i, SSD1306_LCDHEIGHT-1, 0, 0, BLACK);
  166.     oled.display();
  167.   }
  168.   for (uint8_t i=0; i<SSD1306_LCDHEIGHT; i+=4) {
  169.     oled.drawline(SSD1306_LCDWIDTH - 1, i, 0, 0, BLACK);
  170.     oled.display();
  171.   }
  172. }
复制代码

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-3-11 16:22:10 | 显示全部楼层
视频演示





处理图像的工具
http://en.radzio.dxp.pl/bitmap_converter/LCDAssistant.zip

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-3-11 16:28:32 | 显示全部楼层
本帖最后由 thomas 于 2012-3-11 16:29 编辑
Malc 发表于 2012-3-11 15:52
难道你要把他装在镜片上?


当然不是装这个
我要装的是 96*16,0.69寸大小
微型屏,初步计划以反相的形式投影显示在镜片上。这个屏不配电路,需要自己做一块。

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

发表于 2012-3-11 16:34:52 | 显示全部楼层
请问,屏和转接电路板是分开买的还是,原来就是一起的,我也想搞一块,玩玩!
回复 支持 反对

使用道具 举报

发表于 2012-3-11 16:37:41 | 显示全部楼层
怎么看,怎么喜欢呀!没有想到,Arduino可以驱动OLED显示屏!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-3-11 16:43:49 | 显示全部楼层
本帖最后由 thomas 于 2012-3-11 16:44 编辑

这块128064是一体的,0.96寸,32米一块。
别的都是需要精细焊接的,15米一块,需要自己做板子焊接,不建议实验用。
我不喜欢普通LED屏,太粗糙了。
喜欢OLED和VFD屏,做设计特别有感觉。
回复 支持 反对

使用道具 举报

发表于 2012-3-11 16:57:10 | 显示全部楼层
thomas 发表于 2012-3-11 16:28
当然不是装这个
我要装的是 96*16,0.69寸大小
微型屏,初步计划以反相的形式投影显示在镜片上。这 ...

额。。从没试过
不过我觉得能在镜片上显示很酷啊~
赶紧做个出来看看呗~{:soso_e128:}
回复 支持 反对

使用道具 举报

发表于 2012-3-13 12:51:54 | 显示全部楼层
看到thomas用arduino驱动此OLED模块的效果,非常好。

呵呵,我是此OLED模块的厂家。资料中第1pin和第2pin的定义错误已修改。
如果有需要的朋友,可以直接在此购买:
http://item.taobao.com/item.htm?id=13651995352
谢谢!
回复 支持 反对

使用道具 举报

发表于 2012-3-14 21:10:42 | 显示全部楼层
请教一下为啥不用I2C?是因为刷新速度有差异么?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-3-14 22:49:21 | 显示全部楼层

RE: Arduino驱动OLED显示屏试验

黑马 发表于 2012-3-14 21:10
请教一下为啥不用I2C?是因为刷新速度有差异么?

4-wire Serial熟悉些。arduino刚上手,底子也不好,摸索着来的。我感兴趣的应用似乎都是别人没兴趣的,全是自己摸索或从外网搜资料
回复 支持 反对

使用道具 举报

发表于 2012-3-20 17:14:02 | 显示全部楼层
请教一下,我用4线SPI连接到MEGA,你的库文件,发现刷新一次数据要220ms左右,怎么都觉得不应该这么慢啊……抓狂ing……
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-18 19:33 , Processed in 0.049554 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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