[UNO] 【UNO R3 SMD试用】+4.驱动OLED

[复制链接]
513|2
 楼主 | 2018-3-7 17:43 | 显示全部楼层 |阅读模式
本帖最后由 看看小小说 于 2018-3-29 08:42 编辑

ARDUINO UNO R3 SMD

1.SPI方式驱动
硬件依然借助的是MICOKIT的EXT板,库文件我是下载的Adafruit的,点击下载,还是将其解压到IDE安装路径下的library下

这里说明一下,该库默认是128*32的屏,需要手动修改Adafruit_SSD1306-master文件下的Adafruit_SSD1306.h,将pixel定义为128*64

编译运行ssd1306_128x64_spi该DEMO,部分截图显示如下:




2.I2C驱动,编译运行ssd1306_128x64_i2c该DEMO即可,该库IIC的引脚定义是A5是SCL,A4是SDA,然后还要注意的是IIC地址,有些是0x3C,有些是0x3D,按需修改就好。

编译运行,部分截图如下:



有库文件支持,还是非常方便的。

3.显示字符以及中文中文显示需要自己做字库,这里我用的16*16大小的。
打开软件,输入要显示的字符(不需要修改字体,不然像素点不好匹配),取模,生成即可,非常方便


我是基于IIC驱动的基础下做的,代码如下
  1. #include <SPI.h>  
  2. #include <Wire.h>  
  3. #include <Adafruit_GFX.h>  
  4. #include <Adafruit_SSD1306.h>  
  5.   
  6. #define OLED_RESET 4  
  7. Adafruit_SSD1306 display(OLED_RESET);  
  8.   
  9. #define LOGO16_GLCD_HEIGHT 16 //定义显示高度  
  10. #define LOGO16_GLCD_WIDTH  16 //定义显示宽度  
  11.   
  12. /*--  文字:  U  --*/
  13. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  14. static const unsigned char PROGMEM str_1[] =
  15. {   
  16. 0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
  17. 0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  18. };

  19. /*--  文字:  N  --*/
  20. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  21. static const unsigned char PROGMEM str_2[] =
  22. {
  23. 0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x00,0x63,0x00,0x73,0x00,0x7B,0x00,0x6F,0x00,
  24. 0x67,0x00,0x63,0x00,0x63,0x00,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  25. };

  26. /*--  文字:  O  --*/
  27. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  28. static const unsigned char PROGMEM str_3[] =
  29. {
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x66,0x00,
  31. 0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32. };

  33. /*--  文字:     --*/
  34. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  35. static const unsigned char PROGMEM str_4[] =
  36. {
  37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  39. };

  40. /*--  文字:  R  --*/
  41. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  42. static const unsigned char PROGMEM str_5[] =
  43. {
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x7C,0x00,
  45. 0x6C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  46. };

  47. /*--  文字:  3  --*/
  48. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  49. static const unsigned char PROGMEM str_6[] =
  50. {
  51. 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x1C,0x00,
  52. 0x06,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  53. };

  54. /*--  文字:  试  --*/
  55. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  56. static const unsigned char PROGMEM str_7[] =
  57. {
  58. 0x00,0x28,0x20,0x24,0x10,0x24,0x10,0x20,0x07,0xFE,0x00,0x20,0xF0,0x20,0x17,0xE0,
  59. 0x11,0x20,0x11,0x10,0x11,0x10,0x15,0x10,0x19,0xCA,0x17,0x0A,0x02,0x06,0x00,0x02
  60. };

  61. /*--  文字:  用  --*/
  62. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  63. static const unsigned char PROGMEM str_8[] =
  64. {
  65. 0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,
  66. 0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x41,0x08,0x41,0x28,0x80,0x10
  67. };

  68. /*--  文字:  感  --*/
  69. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  70. static const unsigned char PROGMEM str_10[] =
  71. {
  72. 0x00,0x28,0x00,0x24,0x3F,0xFE,0x20,0x20,0x2F,0xA4,0x20,0x24,0x2F,0xA8,0x28,0x98,
  73. 0x28,0x92,0x4F,0xAA,0x40,0x46,0x80,0x82,0x01,0x00,0x48,0x84,0x48,0x12,0x87,0xF2
  74. };

  75. /*--  文字:  谢  --*/
  76. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  77. static const unsigned char PROGMEM str_11[] =
  78. {
  79. 0x01,0x08,0x42,0x08,0x27,0x88,0x24,0x88,0x07,0xBE,0x04,0x88,0xE7,0x88,0x24,0xC8,
  80. 0x24,0xA8,0x2F,0xA8,0x21,0x88,0x2A,0x88,0x34,0x88,0x28,0x88,0x02,0xA8,0x01,0x10
  81. };

  82. /*--  文字:  2  --*/
  83. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  84. static const unsigned char PROGMEM str_12[] =
  85. {
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x06,0x00,0x0C,0x00,
  87. 0x18,0x00,0x30,0x00,0x60,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  88. };

  89. /*--  文字:  1  --*/
  90. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  91. static const unsigned char PROGMEM str_13[] =
  92. {
  93. 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x1C,0x00,0x7C,0x00,0x0C,0x00,0x0C,0x00,
  94. 0x0C,0x00,0x0C,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  95. };

  96. /*--  文字:  I  --*/
  97. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  98. static const unsigned char PROGMEM str_14[] =
  99. {
  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
  101. 0x18,0x00,0x18,0x00,0x18,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  102. };

  103. /*--  文字:  C  --*/
  104. /*--  Fixedsys12;  此字体下对应的点阵为:宽x高=16x16   --*/
  105. static const unsigned char PROGMEM str_15[] =
  106. {
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x60,0x00,0x60,0x00,
  108. 0x60,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  109. };

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

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

  115.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  116.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  117.   // init done

  118.   display.clearDisplay();
  119.   
  120.   //英文字符显示
  121.   display.setTextSize(1);             //设置字体大小
  122.   display.setTextColor(WHITE);        //设置字体颜色白色
  123.   display.setCursor(0,0);             //设置字体的起始位置
  124.   display.println("Hello, world!");   //输出字符并换行
  125.   
  126.   display.setTextColor(BLACK, WHITE); // 设置字体黑色,字体背景白色
  127.   display.println("3.141592");        // 输出数字并换行
  128.   
  129.   display.setTextSize(2);             // 设置字体大小
  130.   display.setTextColor(WHITE);        // 设置字体白色
  131.   display.print("0x");                // 输出字符
  132.   display.println(0xDEADBEEF, HEX);   // 输出为ASCII编码的十六进制
  133.   
  134.   //中文字符显示
  135.   display.drawBitmap(  0, 32, str_1, 16, 16, 1);  // 在坐标X:0  Y:32的位置显示中文字
  136.   display.drawBitmap( 16, 32, str_2, 16, 16, 1);
  137.   display.drawBitmap( 32, 32, str_3, 16, 16, 1);
  138.   display.drawBitmap( 48, 32, str_4, 16, 16, 1);
  139.   display.drawBitmap( 64, 32, str_5, 16, 16, 1);
  140.   display.drawBitmap( 80, 32, str_6, 16, 16, 1);
  141.   display.drawBitmap( 96, 32, str_7, 16, 16, 1);
  142.   display.drawBitmap(112, 32, str_8, 16, 16, 1);

  143.   display.drawBitmap( 16, 48, str_10, 16, 16, 1);
  144.   display.drawBitmap( 32, 48, str_11, 16, 16, 1);
  145.   display.drawBitmap( 48, 48, str_12, 16, 16, 1);
  146.   display.drawBitmap( 64, 48, str_13, 16, 16, 1);
  147.   display.drawBitmap( 80, 48, str_14, 16, 16, 1);
  148.   display.drawBitmap( 96, 48, str_15, 16, 16, 1);
  149.   
  150.   display.display();  // 把缓存的都显示
  151. }

  152. void loop() {  

  153. }
复制代码
显示效果如下:


4.OVER






本帖子中包含更多资源

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

x
| 2018-3-7 21:07 | 显示全部楼层
你试用的什么东东?
 楼主 | 2018-3-8 15:07 | 显示全部楼层
dirtwillfly 发表于 2018-3-7 21:07
你试用的什么东东?

昨天发帖老是URL链接权限不够的问题,测试来着。
扫描二维码,随时随地手机跟帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复

您需要登录后才可以回帖
登录 | 注册
高级模式
我要创建版块 申请成为版主

论坛热帖

关闭

热门推荐上一条 /4 下一条

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