转载自:零知开源快速入门23-OLED使用
http://www.lingzhilab.com/forum. ... d&tid=222&fromuid=2
(出处: 零知实验室)
当前在很多的电子制作中都使用OLED作为屏幕输出,因此它也是很常用的一个模块,我们在这一篇中就简单介绍下它的使用。1、硬件连接
对于OLED,即使使用同一个型号的芯片不同的厂商生产出来的模块接口也是有区别的,但是大体上差异不大,主要分I2C接口的和SPI接口的OLED模块,我们这次使用的是类似I2C接口的模块,如果我们使用具体的模块时候就需要按照对应的规格书进行连接硬件。
我使用的模块连接如下:
注:这里有几个引脚为了简单直接连接到了电源和地上,没有用IO去控制。
2、程序代码
主要代码如下:(这里为了方便,已经把一些基础的功能封装到了库中,可以直接下载附录中的完整的工程文件-OLED_DEMO.zip,复制到软件库的project目录中,然后在软件中打开这个工程文件夹即可)
- /**
- * 文件: OLED-TEST.ino by 零知实验室(www.lingzhilab.com)
- * -- 零知开源,让电子制作变得更简单! --
- * 时间: 2018/07/03 11:14
- * 说明:
- **/
- #include "oled_demo.h"
- unsigned char str1[] =
- {
- 0x00,0x00,0x80,0x80,0x80,0x80,0xC0,0xFC,0xF8,0xC0,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x41,0x39,0x1F,0x1F,0x0F,0x0F,0x1F,0x1F,0x71,0x01,0x00,0x00,0x00,/*"★"*/
- 0x00,0x00,0x80,0x80,0x80,0x80,0x60,0x1C,0x38,0x40,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x41,0x3E,0x22,0x10,0x08,0x08,0x10,0x2E,0x72,0x01,0x00,0x00,0x00,/*"☆"*/
- 0x00,0x00,0xC0,0x30,0x90,0xF0,0x54,0xFC,0x92,0x7A,0x08,0x08,0x28,0x10,0x00,0x00,
- 0x00,0x00,0x10,0x08,0x04,0x1A,0x09,0x36,0x6A,0x19,0x02,0x04,0x08,0x08,0x00,0x00,/*"零",0*/
- 0x00,0x00,0x00,0x00,0x3C,0xA0,0x50,0x30,0x00,0x80,0x00,0x80,0x80,0x40,0x80,0x00,
- 0x00,0x00,0x04,0x22,0x13,0x0E,0x09,0x09,0x01,0x03,0x0D,0x08,0x08,0x07,0x00,0x00,/*"知",1*/
- 0x00,0x00,0x00,0x00,0x80,0xE8,0x48,0x28,0x18,0x1C,0xE4,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x02,0x03,0x22,0x1E,0x01,0x01,0x01,0x01,0x7F,0x01,0x01,0x00,0x00,0x00,/*"开",2*/
- 0x00,0x00,0x40,0x84,0x18,0x08,0xC0,0xB8,0x48,0x34,0xC4,0xA4,0xE0,0x00,0x00,0x00,
- 0x00,0x00,0x1F,0x7E,0x1A,0x06,0x31,0x13,0x25,0x43,0x3F,0x0B,0x10,0x30,0x00,0x00,/*"源",3*/
- 0x00,0x00,0x80,0x80,0x80,0x80,0x60,0x1C,0x38,0x40,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x41,0x3E,0x22,0x10,0x08,0x08,0x10,0x2E,0x72,0x01,0x00,0x00,0x00,/*"☆"*/
- 0x00,0x00,0x80,0x80,0x80,0x80,0xC0,0xFC,0xF8,0xC0,0x80,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x41,0x39,0x1F,0x1F,0x0F,0x0F,0x1F,0x1F,0x71,0x01,0x00,0x00,0x00,/*"★"*/
- };
- uint8_t str2[] = "www.lingzhilab.com";
- unsigned char str3[] =
- {
- 0x00,0x00,0x00,0x20,0x20,0xD8,0x56,0x48,0xF8,0x48,0x48,0x20,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x02,0x02,0x02,0x03,0x02,0x02,0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"年",0*/
- 0x00,0x00,0x00,0x00,0x00,0x88,0x78,0x48,0x48,0x04,0xFC,0x0C,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x40,0x20,0x18,0x07,0x02,0x02,0x01,0x20,0x7F,0x00,0x00,0x00,0x00,0x00,/*"月",1*/
- 0x00,0x00,0x00,0x00,0x30,0xD0,0x10,0x90,0x88,0x08,0xF8,0x18,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x0E,0x11,0x11,0x08,0x08,0x10,0x3F,0x00,0x00,0x00,0x00,0x00,/*"日",2*/
- };
- #define OLED_DC 1
- #define OLED_RST 0
- #define OLED_SCL A5
- #define OLED_SDA A4
- OLED_DEMO myoled(OLED_SDA, OLED_SCL, OLED_DC, OLED_RST);
- // the setup routine runs once when you press reset:
- void setup() {
- // put your setup code here, to run once:
- myoled.begin();
- //显示自定义中文
- for(int i=0; i<8; i++){
- myoled.print_p16x16(i, 0, str1);//显示在第0行的第0-8列,这里一共可以显示4行
- }
- uint8_t str4[] = "2018";
- uint8_t str5[] = "7";
- uint8_t str6[] = "3";
- myoled.print_p8x16(0, 4, str4);
- myoled.print_p16x16(2, 2, str3, 0);//年
- myoled.print_p8x16(56, 4, str5);
- myoled.print_p16x16(4, 2, str3, 1);//月
- myoled.print_p8x16(86, 4, str6);
- myoled.print_p16x16(6, 2, str3, 2);//日
- myoled.print_p6x8(16,7,str2);//显示英文字符
- delay(2000);
- }
- // the loop routine runs over and over again forever:
- void loop() {
- // put your main code here, to run repeatedly:
- }
[color=rgb(51, 102, 153) !important]复制代码
3、结果演示
把上面的工程进行编译后上传到零知开发板中,然后就可以看到如下OLED的界面:
4、自己创作
在这里我们可以直接修改上面的str1,str2...等内容,修改为自己需要的内容即可,这里说明下汉字的取模方法,先下载附件中的取模软件:PC-LCD.ZIP文件,打开后设置如下:
然后填写你需要的汉字再取模,复制到上面的str1的数组里面,这样你就可以显示出你自己的内容了。
注:附件请到原贴下载。
|