oled12864 0.96寸显示屏4线spi 显示的时候图像错乱-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8354|回复: 7

[已解决] oled12864 0.96寸显示屏4线spi 显示的时候图像错乱

[复制链接]
发表于 2019-6-22 12:07 | 显示全部楼层 |阅读模式
这个不知道是我的oled硬件的问题,还是说可以oled设置的问题,请各位大佬能够指正并赐教!

几个星期前看了 奈何col 的用 MINI12864显示熊猫表情包的帖子觉得很cool
https://www.arduino.cn/thread-42174-1-1.html
然后点击链接上某宝的时候发现《Arduino程序设计基础》上面所说u8glib库完全兼容的两块板子都没得卖了,于是自己买了块7针的0.96寸的oled。
本人是计算机学院的大一学生,对于硬件完全一点基础都没有,纯粹是感兴趣。

搜了很多帖子,怀着试探地生怕不兼容的心情用了以下帖子的方法:
https://blog.csdn.net/chenchen2360060/article/details/85220115
我的oled12864显示屏是默认的是四线spi,按照这个帖子接了线,成功地打出了hello world。
微信图片_201906221116402.jpg

于是,乘胜追击,想把熊猫表情的显示做出来,下载了熊猫表情,然后右键编辑把分辨率调成小于oled的分辨率大小,在ADsee官方免费版
打开图片 ->工具 ->修改->更改色深->黑白, 然后另存为将图片改为了黑白的单色图片。(我的oled是单白色显示的)
用奈何col的工具集,位图取模之后编写程序,然后烧录......可怕的事情发生了。

微信图片_20190622111640.jpg

熊猫的图片显示错乱,但是还是有层次感的....为了弄清楚是哪错了,我先从最简单的‘北’字入手。结果又让我大跌眼镜....

微信图片_201906221116401.jpg

这这这....怎么肥事?!
为了继续探究根源,我先去了解了那些取模后的数字到底表示什么,这样子才好确定到底哪出了问题。
https://blog.csdn.net/e_wsq/article/details/70885668

‘北’字是16X16的点阵构成的,而每一行的16个点分成了两个十六进制数代表显示的位置,然后我仔细用 字模提取v2.2 这个软件仔细对比点阵之后发现:每一个十六进制数代表的八个点阵的亮暗在oled上是从右往左显示的!  比如Ox7c, 从左往右是 暗亮亮亮 亮亮暗暗(0111 1100) 但是在屏幕上显示了 暗暗亮亮 亮亮亮暗(从右往左反了)!

研究出规律,我自己用c++写了个程序,把那些数字按规律转换了一下(将每个十六进制数表示的亮暗倒过来),然后再将新的数字复制黏贴到数组上,编写程序后烧录。

[mw_shl_code=arduino,true]#include<U8glib.h>
U8GLIB_SSD1306_128X64 oled(13, 11, 10, 9); //SW SPI Com: SCK(D0) = 13, MOSI(D1) = 11, CS = 10, A0(DC) = 9

//转换后的数字数字

const unsigned char col[] U8G_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,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,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,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xdf,0xff,
0xff,0xff,0xff,0xff,0xff,0x7f,0xc0,0xff,0x03,0xfe,0x17,0xe2,0xff,0xff,0xff,0x3f,0x80,0x7f,0x00,0x5c,0xfe,0x5f,0xfc,0xdb,0xff,0x1f,0x00,
0x1f,0x00,0xf0,0xff,0xff,0xef,0x80,0xff,0x0f,0x80,0x0f,0x00,0xf8,0xff,0xff,0x1f,0x00,0xfc,0x0f,0x00,0x1f,0x00,0xf8,0xff,0xff,0x1f,0x00,
0xf8,0x0f,0x00,0x0f,0x00,0xfc,0xff,0xff,0x3f,0x00,0xf8,0x07,0x80,0x0f,0x00,0xfe,0xff,0xff,0xff,0x00,0xf0,0x03,0x80,0x0f,0x80,0xff,0xff,
0xff,0xff,0x00,0xf0,0x07,0x80,0x0f,0x80,0xff,0xff,0xff,0xff,0x01,0xf0,0x03,0xc0,0x0f,0x80,0xff,0xff,0xff,0xff,0x01,0xf0,0x01,0x80,0x0b,
0xc0,0xff,0x0f,0xfc,0xfb,0x03,0xf0,0x01,0x00,0x00,0xe0,0xff,0x01,0xfc,0xc5,0x07,0xf0,0x01,0x00,0x40,0xe0,0xff,0x7f,0x75,0xaa,0x0f,0xf0,
0x00,0x00,0x60,0xf0,0xff,0xff,0x78,0xbe,0x0f,0xf0,0x01,0x00,0xf0,0xf1,0xff,0xbf,0xbb,0xff,0x1f,0xf8,0x01,0x00,0xfc,0xfb,0xff,0x81,0xff,
0xf9,0x1f,0xfc,0x01,0x00,0xfc,0xfb,0xff,0x81,0xff,0xf9,0x1f,0xfc,0x01,0x80,0xff,0xfb,0xff,0xdf,0xff,0xe7,0xdf,0xff,0x01,0x80,0xff,0xfd,
0xff,0xff,0xff,0xf7,0xff,0xff,0x03,0xc0,0xff,0xff,0xff,0xff,0xff,0xf7,0xdf,0xff,0x01,0xc0,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0x03,
0xe0,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0x01,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xf0,0x7f,0xfe,0xff,0xbf,0xff,0xff,
0xbf,0xff,0x01,0xf0,0x7f,0xfe,0xff,0xdf,0xff,0xff,0xff,0xff,0x03,0xe0,0x7f,0xfe,0xff,0xdf,0xeb,0xe9,0xbf,0xff,0x01,0xe0,0x87,0xff,0xff,
0xe3,0x03,0xee,0xbf,0xff,0x03,0x80,0x80,0xff,0xff,0xf7,0x9f,0xff,0x3f,0xfc,0x01,0x00,0x80,0xff,0xff,0xfb,0xff,0xff,0x3f,0xfc,0x07,0x00,
0x80,0xff,0xff,0xff,0xff,0xff,0x7f,0xf8,0x03,0x00,0x80,0xff,0xff,0x5f,0xab,0xfd,0x3f,0xf8,0x07,0x00,0x00,0xfe,0xff,0x5f,0x29,0xf8,0x3f,
0xf0,0x07,0x00,0x00,0xfe,0xff,0xff,0xff,0xff,0x3f,0xf0,0x07,0x00,0x00,0xfe,0xff,0xff,0xff,0xff,0x3f,0xe0,0x0f,0x00,0x00,0xfc,0xff,0xff,
0xfd,0xff,0x1f,0xe0,0x1f,0x00,0x00,0xf8,0xff,0xff,0x07,0xfe,0x0f,0x80,0x1f,0x00,0x00,0xf8,0xff,0xff,0x07,0xfe,0x0f,0x80,0x1f,0x00,0x00,
0xe0,0xff,0xff,0x8f,0xff,0x03,0xc0,0x3f,0x00,0x00,0x80,0xff,0xff,0xff,0xff,0x01,0x80,0x3f,0x00,0x00,0x80,0xff,0xff,0xff,0xff,0x01,0x80,
0xff,0x01,0x00,0x00,0xfe,0xff,0xff,0x3f,0x00,0x00,0xff,0x01,0x00,0x00,0xf8,0xff,0xff,0x0f,0x00,0x00,0xff,0x03,0x00,0x00,0x00,0xfe,0x6f,
0x00,0x00,0x00,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x3f,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00
};
   
void setup() {
  oled.begin();
}

void loop() {
   oled.firstPage();
   do{
    oled.drawXBMP(0,0,80,60,col);
   }while(oled.nextPage());
   delay(500);
}[/mw_shl_code]


然后成功了:
微信图片_20190622120029.jpg                微信图片_201906221200291.jpg

但是每次取完模之后还要来一次转换,感觉十分麻烦。
希望各位用过类似的oled的朋友能告诉我是硬件的问题还是设置的问题,小白在此谢过啦。



发表于 2019-6-22 13:37 | 显示全部楼层
取模工具里,有一项“切换大小端”,把打开
 楼主| 发表于 2019-6-22 14:51 | 显示全部楼层
奈何col 发表于 2019-6-22 13:37
取模工具里,有一项“切换大小端”,把打开

感谢感谢  昨天没注意到弄得挺折腾的哈哈
发表于 2020-8-12 16:30 | 显示全部楼层
奈何col 发表于 2019-6-22 13:37
取模工具里,有一项“切换大小端”,把打开

牛×,膜拜大佬!!!
发表于 2020-8-12 18:05 | 显示全部楼层
换个取模工具就行了
发表于 2020-9-17 02:47 来自手机 | 显示全部楼层
66666666666666
发表于 2021-9-20 23:23 来自手机 | 显示全部楼层
各位大佬,用那个取模工具比较好。我用卖OLED送的取模工具显示乱的,但例程显示正常。
发表于 2021-9-21 09:44 | 显示全部楼层
doraemon2099 发表于 2021-9-20 23:23
各位大佬,用那个取模工具比较好。我用卖OLED送的取模工具显示乱的,但例程显示正常。 ...

取模工具乱码是因为你没有设置对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 23:56 , Processed in 0.082079 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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