ESP32驱动microSD_SSD1351显示图片很慢求大神帮忙-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5559|回复: 3

ESP32驱动microSD_SSD1351显示图片很慢求大神帮忙

[复制链接]
发表于 2018-11-30 23:04 | 显示全部楼层 |阅读模式
WechatIMG1.jpeg
 楼主| 发表于 2018-11-30 23:05 | 显示全部楼层
本帖最后由 qhdyang 于 2018-12-1 08:21 编辑


#include <Ucglib.h>

/*
   MicroSD card 与 esp32 SPI引脚连接:

   MicroSD Card | ESP32

      GND        GND
      VCC        3.3V
      SCK        D2 SCK
      MOSI       D4 MOSI
      MISO       D3 MISO
      CS         D5 CS
             -
*/
#include "FS.h"
#include "SD.h"
#include "SPI.h"


/*
   SSD1351 OLED | ESP32 SPI 4线或5线引脚连接

       GND        GND
       VCC        3.3V
       SCL .      A3 SCL1 | A5 SCK1
       SDA .      A4 SDA1 | A8 MOSI1
       RES .      A9 | GDIO--
       DC .       A6 MISO1
       CS         A7 CS1
*/
#define my_sclk 25
#define my_mosi 26
#define my_dc   12
#define my_cs   15
#define my_rst  2
/*
   本例程使用的scl sda 5线连接
*/
Ucglib_SSD1351_18x128x128_FT_SWSPI ucg(/*sclk=*/ my_sclk, /*data=*/ my_mosi, /*cd=*/ my_dc, /*cs=*/ my_cs, /*reset=*/ my_rst);

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

#include <dht11.h>
#define test_led LED_BUILTIN

dht11 DHT11;
#define DHT11PIN 14
String text;
// the file itself
File bmpFile;

// information we extract about the bitmap file
int bmpWidth, bmpHeight;
uint8_t bmpDepth, bmpImageoffset;

unsigned long startTime, endTime; // For calculating FPS.
unsigned int frames;

#define ATN 5         // 定义MicroSD card CS片选引脚
#define SD_CS ATN     // 定义SD卡的CS片选
#define sd_led D6

void setup() {
  Serial.begin(115200);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  pinMode(test_led,OUTPUT);
  digitalWrite(test_led,HIGH);
  pinMode(sd_led, OUTPUT);
  digitalWrite(sd_led, HIGH);
  pinMode(SD_CS, OUTPUT);
  digitalWrite(SD_CS, LOW);
  delay(1000);
  ucg.begin(UCG_FONT_MODE_TRANSPARENT);
  ucg.clearScreen();
  /***********检查装载MicroSD是是否成功**********/
  if (!SD.begin(SD_CS)) {
    Serial.println("Card Mount Failed-SD卡装载失败");
    DrawFoneStr(0, 15, 8, "SD Card Failed!" );
    digitalWrite(sd_led, LOW);
    return;
  }

  DrawFoneStr(0, 15, 8, "SD Card OK!" );
  Serial.println("SD卡装载完成");
  sdType();//验证SD卡类型
  /***********装载DH11温湿度和验证是否装载***********/
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
      Serial.println("OK");
      DrawFoneStr(0, 75, 8, "DH11 OK!" );
      break;
    case DHTLIB_ERROR_CHECKSUM:
      Serial.println("Checksum error");
      DrawFoneStr(0, 85, 8, "DH11 Checksum error" );
      break;
    case DHTLIB_ERROR_TIMEOUT:
      Serial.println("Time out error");
      DrawFoneStr(0, 95, 8, "DH11 Time out error" );
      break;
    default:
      Serial.println("Unknown error");
      DrawFoneStr(0, 105, 8, "DH11 Unknown error" );
      break;
  }
  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);
  DrawFoneStr(0, 55, 8, "SD Size:" );
  ucg.setFont(ucg_font_helvB08_tr);
  ucg.setColor(255, 255, 255);
  ucg.setPrintPos(60, 55);
  ucg.print((int)cardSize);
  DrawFoneStr(90, 55, 8, "MB" );
  //readFile(SD, "/1.bmp");
  delay(300);
  //readFile(SD, "/2.bmp");
  /*
    listDir(SD, "/", 0);
    createDir(SD, "/mydir");
    listDir(SD, "/", 0);
    removeDir(SD, "/mydir");
    listDir(SD, "/", 2);
    writeFile(SD, "/hello.txt", "Hello1111 ");
    appendFile(SD, "/hello.txt", "World! chine\n");
    readFile(SD, "/hello.txt");
    deleteFile(SD, "/foo.txt");
    renameFile(SD, "/hello.txt", "/foo.txt");
    readFile(SD, "/foo.txt");
    testFileIO(SD, "/test.txt");
  */
  Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
  Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}

void loop() {

delay(50);

  startTime = millis();
  frames = 0;

  for (int n = 0; n < 1; n++) { // .46 FPS before SPI_FULL_SPEED was added to SDClass::begin in SD.cpp in SD library.  .56 fps after.  1.46 FPS after adding block transfer to SD lib.

    bmpDraw("/1.bmp", 0, 0);
    bmpDraw("/2.bmp", 0, 0);
    bmpDraw("/3.bmp", 0, 0);

    frames = frames + 3;

}

  endTime = millis();
  ucg.setColor(255,255,255);
  ucg.drawFrame(0,0,127,127);

}
发表于 2019-1-31 14:16 | 显示全部楼层
使用软件模拟的SPI速度肯定慢,U8GLIB中SSD1351支持硬件SPI
  U8GLIB_SSD1351_128X128_4X_332(uint8_t cs, uint8_t a0, uint8_t reset = U8G_PIN_NONE)
      : U8GLIB(&u8g_dev_ssd1351_128x128_4x_332_hw_spi, cs, a0, reset)
发表于 2019-8-28 16:14 | 显示全部楼层
zxm39161 发表于 2019-1-31 14:16
使用软件模拟的SPI速度肯定慢,U8GLIB中SSD1351支持硬件SPI
  U8GLIB_SSD1351_128X128_4X_332(uint8_t cs,  ...

用8266能不能刷动128*128分辨率的SSD1351的OLED呢。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 04:29 , Processed in 0.154457 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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