用OLED屏显示图片(制作篇)
今天给大家带来OLED屏显示图片的制作方法需要图片的请看https://mc.dfrobot.com.cn/thread-299362-1-1.html
需要代码的请看https://mc.dfrobot.com.cn/thread-299357-1-1.html
那么话不多说,开始。
首先,先从网上找到需要的图片(注意,图片要简洁,背景最好是白色)
(自己画的)如果你是从网上找得彩色图片,比如这个
或者这个
(这个不推荐用)
那么你就需要进行转换
先把背景扣掉
再打开画图
点重新调整大小中像素一栏,调整像素(方照片为64x64,长照片为128x64,最多不超过128x64)
然后另存为BMP格式
选单色位图
稍微改一下图
完成,打开取模软件Img2Lcd。
打开你的图片,点保存。把C文件改成TXT文件
十六进制模如下
const unsigned char gImage_bb =
{ 0X00,0X01,0X80,0X00,0X40,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X00,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X07,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XF7,0XFE,0X00,0X00,0X01,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XF0,0X7F,0X03,0XC0,0X01,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XE0,0X01,0XF8,0X00,0X1F,0X83,0XC0,0X03,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XE0,0X01,0XF0,0X00,0X0F,0X83,0XC0,0X03,0XC0,0X00,0X07,0XFE,0X00,0X00,
0X00,0X01,0XE0,0X03,0XF0,0X00,0X07,0X81,0XE0,0X07,0XC0,0X00,0X1F,0XFF,0XC0,0X00,
0X00,0X01,0XE0,0X03,0XE0,0X00,0X03,0X81,0XE0,0X0F,0X80,0X00,0X7F,0XFF,0XE0,0X00,
0X00,0X01,0XC0,0X07,0XC0,0X00,0X03,0X81,0XE0,0X0F,0X80,0X00,0XFF,0X0F,0XE0,0X00,
0X00,0X01,0XC0,0X07,0XC0,0X00,0X03,0X80,0XE0,0X1F,0X00,0X00,0XFC,0X01,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X80,0X00,0X03,0X80,0XF0,0X1E,0X00,0X01,0XF0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X80,0X00,0X03,0X80,0XF8,0X3E,0X00,0X03,0XE0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X00,0X00,0X03,0X80,0XF8,0X3C,0X00,0X07,0XE0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X00,0X00,0X03,0X80,0X78,0X3C,0X00,0X0F,0XC0,0X03,0XE0,0X00,
0X00,0X01,0XC0,0X1F,0X00,0X00,0X03,0X80,0X3C,0X38,0X00,0X1F,0X80,0X03,0XE0,0X00,
0X00,0X01,0XC0,0X1F,0X00,0X00,0X03,0X80,0X3C,0X38,0X00,0X1F,0X00,0X1F,0XE0,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X3C,0X78,0X00,0X3E,0X00,0XFF,0X80,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X1C,0X78,0X00,0X3C,0X3F,0XFF,0X80,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X1E,0XF8,0X00,0X3F,0XFF,0XFC,0X00,0X00,
0X00,0X03,0X80,0X1F,0X00,0X00,0X07,0X00,0X1E,0XF0,0X00,0X3B,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X80,0X1F,0X80,0X00,0X0F,0X00,0X1F,0XF0,0X00,0X3B,0XF8,0X00,0X00,0X00,
0X00,0X03,0X80,0X07,0X80,0X00,0X1F,0X00,0X0F,0XE0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X80,0XE7,0XC0,0X00,0X3F,0X00,0X0F,0XE0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X81,0XE3,0XE0,0X00,0X7E,0X00,0X0F,0XC0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X87,0XE3,0XF8,0X00,0X7C,0X00,0X0F,0XC0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0XE1,0XFF,0X01,0XF8,0X00,0X07,0X80,0X00,0X3C,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0XC0,0XFF,0XFF,0XF0,0X00,0X07,0X80,0X00,0X3E,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0X00,0X3F,0XFF,0XF0,0X00,0X00,0X00,0X00,0X3F,0X00,0X01,0XF8,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XC0,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFF,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,0XFF,0XFF,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XC0,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
把前六位十六进制码删掉,只留剩下的十六进制码。
打开ARDUINO IDE,输入以下代码。
=#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 14
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
//取16X16汉字字模 逐行式 顺向高位在前
static const unsigned char PROGMEM str1[] =
{
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X38,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X00,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X07,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X01,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XF7,0XFE,0X00,0X00,0X01,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF0,0X01,0XFF,0XF0,0X7F,0X03,0XC0,0X01,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XE0,0X01,0XF8,0X00,0X1F,0X83,0XC0,0X03,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X01,0XE0,0X01,0XF0,0X00,0X0F,0X83,0XC0,0X03,0XC0,0X00,0X07,0XFE,0X00,0X00,
0X00,0X01,0XE0,0X03,0XF0,0X00,0X07,0X81,0XE0,0X07,0XC0,0X00,0X1F,0XFF,0XC0,0X00,
0X00,0X01,0XE0,0X03,0XE0,0X00,0X03,0X81,0XE0,0X0F,0X80,0X00,0X7F,0XFF,0XE0,0X00,
0X00,0X01,0XC0,0X07,0XC0,0X00,0X03,0X81,0XE0,0X0F,0X80,0X00,0XFF,0X0F,0XE0,0X00,
0X00,0X01,0XC0,0X07,0XC0,0X00,0X03,0X80,0XE0,0X1F,0X00,0X00,0XFC,0X01,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X80,0X00,0X03,0X80,0XF0,0X1E,0X00,0X01,0XF0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X80,0X00,0X03,0X80,0XF8,0X3E,0X00,0X03,0XE0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X00,0X00,0X03,0X80,0XF8,0X3C,0X00,0X07,0XE0,0X00,0XE0,0X00,
0X00,0X01,0XC0,0X0F,0X00,0X00,0X03,0X80,0X78,0X3C,0X00,0X0F,0XC0,0X03,0XE0,0X00,
0X00,0X01,0XC0,0X1F,0X00,0X00,0X03,0X80,0X3C,0X38,0X00,0X1F,0X80,0X03,0XE0,0X00,
0X00,0X01,0XC0,0X1F,0X00,0X00,0X03,0X80,0X3C,0X38,0X00,0X1F,0X00,0X1F,0XE0,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X3C,0X78,0X00,0X3E,0X00,0XFF,0X80,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X1C,0X78,0X00,0X3C,0X3F,0XFF,0X80,0X00,
0X00,0X03,0XC0,0X1F,0X00,0X00,0X07,0X80,0X1E,0XF8,0X00,0X3F,0XFF,0XFC,0X00,0X00,
0X00,0X03,0X80,0X1F,0X00,0X00,0X07,0X00,0X1E,0XF0,0X00,0X3B,0XFF,0XE0,0X00,0X00,
0X00,0X03,0X80,0X1F,0X80,0X00,0X0F,0X00,0X1F,0XF0,0X00,0X3B,0XF8,0X00,0X00,0X00,
0X00,0X03,0X80,0X07,0X80,0X00,0X1F,0X00,0X0F,0XE0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X80,0XE7,0XC0,0X00,0X3F,0X00,0X0F,0XE0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X81,0XE3,0XE0,0X00,0X7E,0X00,0X0F,0XC0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0X87,0XE3,0XF8,0X00,0X7C,0X00,0X0F,0XC0,0X00,0X38,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0XE1,0XFF,0X01,0XF8,0X00,0X07,0X80,0X00,0X3C,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0XC0,0XFF,0XFF,0XF0,0X00,0X07,0X80,0X00,0X3E,0X00,0X00,0X00,0X00,
0X00,0X03,0XFF,0X00,0X3F,0XFF,0XF0,0X00,0X00,0X00,0X00,0X3F,0X00,0X01,0XF8,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XC0,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFF,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,0XFF,0XFF,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XC0,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
void setup() {
// put your setup code here, to run once:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);//开像素点发光
display.clearDisplay();//清屏
display.drawBitmap(0,0 , str1, 128, 64, 1);
}
void loop() {
// put your main code here, to run repeatedly:
}
注意,如果是128x64的图
最后一句为
display.drawBitmap(0,0 , str1, 128, 64, 1);
如果是64x64的图
最后一句为
display.drawBitmap(0,32, str1, 64, 64, 1);
感谢大家
不好意思,贴没发全。 木事,以后补全就行了
页:
[1]