零知开源小项目-Bad Apple 零知版本-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3282|回复: 1

零知开源小项目-Bad Apple 零知版本

[复制链接]
发表于 2018-7-17 21:04 | 显示全部楼层 |阅读模式
本帖最后由 零知实验室-roc 于 2018-7-17 21:14 编辑

原文:零知开源小项目-Bad Apple 零知版本http://www.lingzhilab.com/forum. ... d&tid=323&fromuid=2
(出处: 零知实验室)

“有屏的地方就有Bad Apple”,现在我们零知开发板上也移植了这个Bad Apple,使用的是SD卡存储,OLED显示画面,主要是为了大家熟悉下OLED和SD卡这两个常用模块的应用。我们零知开发板刚好有两个硬件SPI接口,因此在这里两个设备都是使用的硬件SPI,速度都是大概是10兆,因此效果还不错。
1、硬件连接
  • 零知标准板
  • OLED-ssd1036
  • SD卡(网络扩展板带)

OLED的连接直接参照之前oled的显示教程,不过我在这里该到了SPI2上,因此需要把MOSI,SCLK这两根线连接到SPI2对应的脚上(34,32);
SD卡使用的是网络扩展板的SD卡,使用的micro SD卡,容量4g,直接把网络扩展板和零知板对接即可。 23.jpg

2、软件代码
程序很简单,就是SD卡上文件的读取,然后是OLED的图片显示。
说明:这里我使用的是BMP图片格式,较为简单,图片属性如下:

主要应用了PS软件进行批量更改图片为单色BMP格式。代码如下:
  • /*
  •   读取sd卡的bmp图片
  • */
  • #include <SPI.h>
  • #include <SD.h>
  • #include <Adafruit_SSD1306.h>
  • //sd卡使用spi1
  • //oled使用spi2
  • #define OLED_DC    1
  • #define OLED_CS    2
  • #define OLED_RESET 0
  • Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
  • const int chipSelect = SS;
  • unsigned char buff[1086] = {0};
  • //Lingzhi logo
  • static const unsigned char pic[] =
  • {
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x70,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xA9,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x06,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x0F,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x1F,0x80,0x4F,0xE0,0x06,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0xFF,0x80,0x00,0x00,0x00,0x3F,0xC1,0x3A,0x38,0x04,0x00,0x00,0x00,0x00,
  • 0x00,0x01,0xFF,0xC0,0x00,0x00,0x00,0xFF,0xE0,0x04,0x00,0x04,0x00,0x00,0x00,0x00,
  • 0x00,0x03,0xFF,0xE0,0x00,0x00,0x01,0xFF,0xF8,0x0C,0x00,0x0F,0x80,0x00,0x00,0x00,
  • 0x00,0x07,0xFF,0xF0,0x00,0x00,0x03,0xFF,0xFC,0x04,0x00,0x12,0x06,0x00,0x00,0x00,
  • 0x00,0x1F,0xFF,0xF8,0x00,0x00,0x07,0xFF,0xFE,0x00,0x00,0x02,0x73,0x00,0x00,0x00,
  • 0x00,0x1F,0xFF,0xFC,0x00,0x00,0x07,0xFF,0xFF,0x00,0x00,0x07,0xE2,0x00,0x00,0x00,
  • 0x00,0x6F,0xFF,0xFE,0x00,0x00,0x13,0xFF,0xFF,0x80,0x00,0x74,0x22,0x00,0x00,0x00,
  • 0x00,0xF3,0xFF,0xFF,0x00,0x00,0x39,0xFF,0xFF,0xC0,0x00,0x06,0x26,0x00,0x00,0x00,
  • 0x01,0xF9,0xFF,0xFF,0x80,0x00,0xFC,0xFF,0xFF,0xE0,0x00,0x0D,0xBC,0x00,0x00,0x00,
  • 0x03,0xFC,0xFF,0xFF,0xC0,0x01,0xFE,0x7F,0xFF,0xF0,0x00,0x08,0xA0,0x00,0x00,0x00,
  • 0x07,0xFE,0x7F,0xFF,0xF0,0x03,0xFF,0x3F,0xFF,0xF8,0x00,0x10,0x00,0x00,0x00,0x00,
  • 0x0F,0xFF,0x3F,0xFF,0xF8,0x07,0xFF,0x81,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x1F,0xFF,0x83,0xFF,0xFC,0x0F,0xFF,0xC6,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x7F,0xFF,0xC1,0xFF,0xFE,0x1F,0xFF,0xCF,0x7F,0xFF,0x00,0x00,0x00,0x00,0x20,0x00,
  • 0x7F,0xFF,0x81,0xFF,0xFE,0x1F,0xFF,0xDF,0x3F,0xFF,0x80,0x00,0x00,0x00,0x30,0x00,
  • 0x7F,0xFF,0xC1,0xFF,0xFE,0x1F,0xFF,0xCF,0x7F,0xFF,0x80,0x00,0x00,0x00,0x3F,0x00,
  • 0x3F,0xFF,0xC1,0xFF,0xFC,0xCF,0xFF,0xE6,0x7F,0xFF,0x00,0x00,0x00,0x03,0xE3,0x00,
  • 0x1F,0xFF,0xFC,0xFF,0xF9,0xE7,0xFF,0xF0,0x3F,0xFE,0x00,0x00,0x00,0x02,0x10,0x00,
  • 0x0F,0xFF,0xFE,0x7F,0xF7,0xF3,0xFF,0xFF,0x9F,0xF8,0x00,0x00,0x00,0x00,0xD0,0x00,
  • 0x03,0xFF,0xFF,0x3F,0xEF,0xF9,0xFF,0xFF,0xCF,0xF0,0x00,0x00,0x00,0x00,0x10,0x00,
  • 0x01,0xFF,0xFF,0x9F,0xDF,0xFC,0xFF,0xFF,0xE7,0xE0,0x00,0x00,0x00,0x00,0x90,0x00,
  • 0x00,0xFF,0xFF,0xC7,0x3F,0xFF,0x3F,0xFF,0xF3,0xC0,0x00,0x00,0x00,0x00,0x3F,0x80,
  • 0x00,0x7F,0xFF,0xF2,0x7F,0xFF,0x9F,0xFF,0xF9,0x80,0x00,0x00,0x00,0x07,0xA0,0x00,
  • 0x00,0x3F,0xFF,0xF8,0xFF,0xFF,0xCF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x28,0x00,
  • 0x00,0x1F,0xFF,0xF9,0xFF,0xFF,0xC7,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x4C,0x00,
  • 0x00,0x0F,0xFF,0xF3,0xFF,0xFF,0x93,0xFF,0xF8,0x00,0x00,0x00,0x00,0x01,0x86,0x00,
  • 0x00,0x07,0xFF,0xE7,0xFF,0xFF,0x39,0xFF,0xF0,0x00,0x00,0x00,0x00,0x02,0x02,0x00,
  • 0x00,0x03,0xFF,0xCF,0xFF,0xFC,0x7C,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x01,0xFF,0x9F,0xFF,0xF9,0xFE,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0xFF,0x3F,0xFF,0xF3,0xFF,0x3F,0x80,0x00,0x00,0x04,0x60,0x00,0x00,0x00,
  • 0x00,0x00,0x7E,0x7F,0xFF,0xE7,0xFF,0x9F,0x00,0x00,0x00,0x3E,0x60,0x00,0x00,0x00,
  • 0x00,0x00,0x3D,0xFF,0xFE,0x0F,0xFF,0xCE,0x00,0x00,0x00,0x14,0x50,0x00,0x00,0x00,
  • 0x00,0x00,0x03,0xFF,0xFC,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x14,0x88,0x00,0x00,0x00,
  • 0x00,0x00,0x03,0xFF,0xFC,0x0F,0xFF,0xF0,0x00,0x00,0x00,0x15,0x0C,0x00,0x00,0x00,
  • 0x00,0x00,0x03,0xFF,0xFC,0x0F,0xFF,0xF0,0x00,0x00,0x00,0x14,0xF7,0x00,0x00,0x00,
  • 0x00,0x00,0x01,0xFF,0xFC,0x1F,0xFF,0xE0,0x00,0x40,0x00,0x1E,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0xFF,0xF9,0xFF,0xFF,0xC0,0x00,0x60,0x00,0x32,0x48,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x7F,0xF3,0xFF,0xFF,0x80,0x00,0x3E,0x00,0x0E,0xA8,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x3F,0xE7,0xFF,0xFF,0x00,0x0F,0xC3,0x00,0x62,0x90,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x1F,0xCF,0xFF,0xFC,0x00,0x08,0x00,0x00,0x04,0x10,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x07,0x9F,0xFF,0xF8,0x00,0x09,0xF0,0x00,0x0F,0xFE,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x03,0x3F,0xFF,0xF0,0x00,0x00,0x80,0x00,0x0D,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0xFF,0xFF,0xE0,0x00,0x01,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0xFF,0xFF,0xC0,0x00,0x03,0xD8,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x7F,0xFF,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x3F,0xFF,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x1F,0xFE,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x0F,0xFC,0x00,0x00,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x07,0xF8,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  • 0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  • };
  • void setup() {
  •   Serial.begin(9600);
  •   display.begin(SSD1306_SWITCHCAPVCC);
  •         //oled显示logo
  •         display.drawBitmap(0,0,pic,128,64,1);//
  •         display.display();
  •         display.clearDisplay();
  •         delay(3000);
  •   Serial.print("Initializing SD card...");
  •   //sd卡启动
  •   if (!SD.begin(chipSelect)) {
  •     Serial.println("Card failed, or not present");
  •     // don't do anything more:
  •     return;
  •   }
  •   Serial.println("card initialized.");
  • }
  • uint32_t fileNum = 0;
  • int i = 0;
  • void loop() {
  •         //循环读取sd卡上的图片,并显示到oled
  •         for(fileNum=0; fileNum<=5355;fileNum++)
  •         {
  •                 //0000-5355.bmp 图片名字
  •                 char filen[4] = {0};
  •                 sprintf(filen, "%04d", fileNum);
  • //                Serial.println("open file:");
  • //                Serial.println(String(filen)+String(".bmp"));
  •                 //打开图片
  •                 File dataFile = SD.open(String(filen)+String(".bmp"));
  •                 if (dataFile)
  •                 {
  •                         //读取图片,并把图片的数据存放到buff中
  •                         i=0;
  •                         while (dataFile.available())
  •                         {
  •                                 buff = dataFile.read();
  •                                 i++;
  •                         }
  •                         dataFile.close();
  •                         display.clearDisplay();
  •                         //62个字节是图片文件中的头信息,62之后的是真实图片数据
  •                         //data: 40+14+4*2 -> end
  •                         display.drawBitmap(0,0,buff+62,128,64,1);//
  •                         display.display();
  •                 }
  •                 // 图片打开失败
  •                 else {
  •                         Serial.println("error opening file");
  •                 }
  •   }
  • }

代码注释写的很清楚,就不再详细解释了。最后我们下载到零知标准板上,可以看看播放的效果(视频录制较大就不上传了,主要还是为了大家自己能动手)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 04:45 , Processed in 0.103464 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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