SSD1306驱动芯片简介
SSD1306是一个单片机CMOS OLED/PLED驱动芯片,可以驱动有机聚合发光二极管点阵图形显示系统。由128 segments和64 Commons组成。该芯片专为共阴极OLED面板设计。SSD1306中嵌入了对比度控制器、显示RAM和晶振,减少了外部器件和功耗。有三种可选的接口用于发送数据/命令:6800/8080并口、I2C、SPI接口,适用于多数简单的应用。
U8g2库驱动SSD1306
U8g2是一个非常强大的显示器控制库,且操作简单、资料丰富,GitHub上有非常详细的库函数讲解**传送门**,支持市面上绝大部分的OLED屏。可以快速测试SSD1306的OLED串口屏的好坏。现在就用Arduino中的U8g2库实现一个简单的SSD1306 OLED屏幕测试和在屏幕上显示自己喜欢的照片。
SSD1306 128*64 OLED屏幕
材料准备
- SSD1306 OLED屏幕(我这里用到的是I2C接口的单色、128*64的屏幕);
- Arduino UNO 板;
- 杜邦线;
- 图片取模软件;
测试屏幕
-
接线
-
打开Arduino IDE在库管理中下载好U8g2库文件
-
打开U8g2的LOGO示例
-
打开示例LOGO示例文件后你会发现,在头文件下面有很多被注释了的构造函数对象,在其中找到合适自己屏幕驱动、分辨率和通讯方式的构造函数对象去除注释。(我这里选择的是SSD1306,128*64,I2C的那一个构造函数,然后解注释)
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE);
上面构造函数对象中16为定义I2C时钟接口,17为I2C的数据接口,倘若你的Arduino单片机没有这个接口就改一下,我这里把clock改成了9号IO口,数据接口改成了8号IO口。
- 烧录测试
利用U8g2显示自己喜欢的图片
- 首先需要准备好一个取模软件,用取模软件打开要显示的图片进行取模,或者在各大论坛里有大佬们利用开源代码做的在线取模进行取模。
然后点击保存,生成一个.c文件,里面是一个数组,这个数组就是图片取模后的数据。
2. 程序
/*
使用u8g2显示数据
图形显示器:OpenJumper 12864 OLED
设备核心:SSD1306
*/
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 9, /* data=*/ 8, /* reset=*/ U8X8_PIN_NONE);
/*************
*取模得到的数组*
*************/
const unsigned char Image[]U8X8_PROGMEM = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf5,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0x1f,0x0a,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0xf8,0xff,0xff,0xff,0xff,0xff,0xe7,0x37,0xfc,0xff,0xff,0xff,
0xff,0xff,0x3f,0xfe,0xe2,0xff,0xff,0xff,0xff,0xff,0x59,0xe5,0xf3,
0xff,0xff,0xff,0xff,0xff,0xdf,0xb7,0x9d,0xff,0xff,0xff,0xff,0x7f,
0xb6,0xd8,0xe5,0xff,0xff,0xff,0xff,0xff,0xa7,0xfd,0x32,0xfe,0xff,
0xff,0xff,0xbf,0x6d,0x7f,0xdf,0xff,0xff,0xff,0xff,0xff,0xfb,0xd7,
0xe7,0xfc,0xff,0x3f,0xff,0x9f,0x9b,0xea,0x9d,0xff,0xff,0xff,0xff,
0xff,0x59,0xbd,0xce,0xf9,0xff,0xcf,0xff,0x6f,0xe5,0x5f,0xb7,0xff,
0xff,0xff,0xff,0xff,0xfe,0xf7,0x5b,0xfb,0xff,0xf3,0xff,0xe7,0xb6,
0xfa,0xbd,0xff,0xff,0xff,0xff,0xff,0x56,0x5d,0x97,0xf7,0xff,0xfc,
0xff,0x5b,0xd9,0xaf,0x77,0xff,0xff,0xff,0xff,0x7f,0xfd,0xf7,0xbd,
0xea,0x3f,0xff,0xfd,0xeb,0x7e,0xfd,0x6e,0xff,0xff,0xff,0xff,0xbf,
0x57,0xbb,0x77,0xcd,0xcf,0x07,0xff,0x35,0xea,0xab,0xbb,0xfe,0xff,
0xff,0xff,0xbf,0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0x77,
0x75,0xff,0xff,0xff,0xff,0xdf,0x75,0x95,0xb7,0xb5,0xed,0xb7,0x75,
0xdb,0xee,0xdc,0x5f,0xff,0xff,0xff,0xff,0xdf,0xdf,0x3f,0x68,0x73,
0x58,0x6d,0xd5,0xb6,0xbc,0x76,0xb5,0xff,0xff,0xff,0xff,0x9f,0x7a,
0xeb,0xdd,0x2e,0x77,0xdb,0xaa,0xed,0x75,0xdd,0xbf,0xff,0xff,0xff,
0xff,0xbf,0xef,0xfe,0xb4,0xdd,0xa7,0x6d,0x6e,0x5b,0x89,0xf7,0x96,
0xff,0xff,0xff,0xff,0xbf,0xdd,0xdb,0x6e,0xab,0x6f,0x5b,0xdf,0x76,
0x6b,0xbd,0xdb,0xff,0xff,0xff,0xff,0x7f,0x7b,0xbf,0xda,0xd6,0xcf,
0xb6,0x5f,0xdb,0xfa,0xf7,0xee,0xff,0xff,0xff,0xff,0x7f,0x6e,0x60,
0xb6,0xdd,0xdf,0xad,0xdf,0xb6,0xd3,0xae,0xe7,0xff,0xff,0xff,0xff,
0xff,0xde,0x0f,0xdb,0xd6,0x5f,0xbb,0x9f,0x6d,0xf5,0xfd,0xf6,0xff,
0xff,0xff,0xff,0xff,0xf5,0x76,0x6d,0xdb,0xd8,0x96,0xb0,0xdb,0xb7,
0xab,0xfb,0xff,0xff,0xff,0xff,0xff,0xdb,0xbb,0xdb,0xd6,0x58,0xbd,
0x50,0x6d,0x05,0xfe,0xf9,0xff,0xff,0xff,0xff,0xff,0x67,0x3f,0x6d,
0x5f,0xd2,0xd7,0xd2,0xdb,0xee,0xdb,0xfc,0xff,0xff,0xff,0xff,0xff,
0xcf,0xb5,0xb6,0x41,0x10,0xa0,0x50,0xb4,0x65,0x77,0xff,0xff,0xff,
0xff,0xff,0xff,0x3f,0xaf,0xed,0x9a,0xca,0x9f,0x94,0x6e,0xef,0x9d,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x38,0x5b,0xb7,0x78,0xf0,0x6b,
0xb5,0xa5,0xd7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x47,0xf6,0x5a,
0x1f,0xf4,0xd7,0xdb,0xee,0xf2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x7f,0x5b,0xb7,0x9f,0x60,0xb7,0xb6,0xad,0xfc,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0x7f,0xbd,0xad,0x36,0xf2,0x65,0x6d,0x83,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0x40,0xdb,0xfd,0x7e,0xef,0xf7,
0xf6,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x5f,0x80,0xfa,
0x5b,0x02,0x00,0x69,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
0xeb,0x77,0xc7,0xaf,0x3f,0x7f,0x59,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0x5e,0x79,0x0f,0xd0,0x71,0xd4,0xfb,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xea,0x80,0xdb,0xd7,0x8f,0xbf,0xfc,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0a,0xf5,0xbe,0xac,
0x3f,0x68,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x2f,0xe8,
0xf6,0xbf,0xeb,0xbd,0xd3,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xef,0xbb,0xcf,0x2d,0xf2,0xcf,0x16,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xd3,0x9a,0xff,0xbc,0xab,0x6d,0xfc,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xb7,0x35,0xf7,0xef,0x76,
0x9b,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xcf,0x6e,
0xfe,0xfb,0xab,0xcd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x9f,0xdb,0x69,0xff,0x74,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0x7f,0xb6,0xc2,0x0f,0xed,0xf8,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd8,0x3f,0xe0,0x36,0xfe,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x63,0xd5,
0x5f,0x9b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x1f,0x7d,0xf5,0xe2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0x80,0x0a,0xfe,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xf5,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
void setup(void) {
u8g2.begin(); //初始化
u8g2.clearBuffer(); //清空显示缓冲区
for(int b=0;b<=64;b++)
{
u8g2.clearBuffer(); // 清空显示缓冲区
u8g2.drawXBMP( 0 , 0 , 128 , 64 , Image ); //128,64为图片尺寸,根据你的图片尺寸修改
u8g2.sendBuffer(); // 显示缓冲区内容
}
}
void loop(void) {
}
- 效果展示
结束
利用强大的U8g2函数库去把手中的显示屏点亮、显示照片、画图等等,结合GitHub里对U8g2库函数的讲解,发挥自己的头脑甚至能利用手中的显示屏制作一段属于您自己的动画。
转载:https://blog.csdn.net/qq_42250136/article/details/117280743