esp32c3的SD库在这里下载:https://github.com/nhatuan84/esp32-micro-sdcard
显示屏库还是用Arduino_GFX:https://github.com/moononournation/Arduino_GFX/
硬件链接如下:
esp32c3 SD card Module
GPIO02---->SCK
GPIO03---->MOSI
GPIO10---->MISO
GPIO06---->CS
3.3V------>3V3
GND------->GND
esp32c3 1.8'TFT
GPIO02---->SCL
GPIO03---->SDA
GPIO05---->DC
GPIO07---->CS
GPIO04---->RES
3.3V------>VCC
GND------->GND
显示效果:
#include <SPI.h>
#include <mySD.h>
#include <Arduino_GFX_Library.h>
File bmpFile;
unsigned short pic[0x5000]; // 128*160图像0x5000像素
byte aByte; // 1字节数据
Arduino_DataBus *bus = new Arduino_ESP32SPI(5 /* DC */, 7 /* CS */, 2 /* SCK */, 3 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 2 /* 旋转屏幕180度 */, false);
void setup()
{
Serial.begin(115200);
//从SD卡读取图片
if (!SD.begin(6, 3, 10, 2))
{
Serial.println("initialization SD card failed!");
return;
}
Serial.println("initialization SD card done.");
bmpFile = SD.open("01.bmp", FILE_READ);
if (bmpFile)
{
Serial.println("Reading 01.bmp...");
//显示图片
while (bmpFile.available())
{
//跳过前0x36个字节的头
for (int i = 0; i < 0x36; i++)
{
Serial.print(bmpFile.read(), HEX);
Serial.print(" ");
}
//把rgb24转换成rgb16
for (int i = 0; i < 0x5000; i++)
{
aByte = bmpFile.read();
pic[i] = (aByte * 32 / 256) << 11;
aByte = bmpFile.read();
pic[i] |= (aByte * 64 / 256) << 5;
aByte = bmpFile.read();
pic[i] |= (aByte * 32 / 256);
}
Serial.println("OK");
}
bmpFile.close();
}
else
{
Serial.println("error Reading 01.bmp");
}
//显示图片
gfx->begin();
gfx->fillScreen(BLACK);
gfx->draw16bitRGBBitmap(0, 0, pic, 128, 160);
delay(1000);
}
void loop()
{
}