深圳晶彩智能ESP32-3248S035R介绍
深圳晶彩智能出品ESP32-3248S035R为3.5寸彩色屏采用分辨率480x320彩色液晶屏,驱动芯片是ST7796。板载乐鑫公司出品ESP-WROOM-32,Flash 4M。型号尾部“R”标识电阻膜的感压式触摸屏,驱动芯片是XPT2046。板载mini SD卡槽。
ArduinoGFX库介绍
Arduino_GFX是一个Arduino图形库。
目前支持GC9A01轮显、HX8347C、HX8347D、HX8352C、HX8357B、ILI9225、ILI9341、M5Stack、ILI9481、ILI9486、ILI9488、JBT6K71、R61529、SEPS525、SSD1283A、SSD1331、SSD1351、ST7735、ST7789、ST7796,具有软硬件SPI。ESP32还支持9位SPI、8位和16位并行接口。
PlatformIO IDE使用的ArduinoGFX库地址
moononournation/GFX Library for Arduino
ESP32-3248S035R管脚分布
MOSI | MISO | CLK | CS | DC | RST | |
ST7796 | 12 | 13 | 14 | 15 | 2 | -1 |
XPT2046 | 12 | 13 | 14 | 33 | ||
SD | 23 | 19 | 18 | 5 |
platformIO.ini设置
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
upload_speed = 921600
board_build.f_flash = 80000000L
board_build.flash_mode = dio
monitor_speed = 115200
;upload_port = COM3
board_build.mcu = esp32
upload_protocol = esptool
; change MCU frequency
board_build.f_cpu = 240000000L
lib_ldf_mode = deep
board_build.partitions = huge_app.csv
build_flags = -DCORE_DEBUG_LEVEL=3
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
lib_deps = moononournation/GFX Library for Arduino@^1.4.6
bitbank2/JPEGDEC@^1.4.2
使用ArduinoGFX库实现SD卡JPEG格式图片显示程序
#include <Arduino.h>
#include <Arduino_GFX_Library.h>
const char *jpeg[6] = {"/0.jpg", "/1.jpg", "/2.jpg", "/3.jpg", "/4.jpg","/5.jpg"};
#define GFX_BL 27 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
Arduino_DataBus *bus = new Arduino_ESP32SPI(2 /* DC */, 15 /* CS */, 14 /* SCK */, 13 /* MOSI */, 12 /* MISO */, HSPI /* spi_num */);
Arduino_GFX *gfx = new Arduino_ST7796(bus, -1 /* RST */, 3 /* rotation */, false /* IPS */,
320 /* width */, 480 /* height */,
0 /* col offset 1 */, 0 /* row offset 1 */);
#include <SD.h>
#define SD_MOSI 23
#define SD_MISO 19
#define SD_SCK 18
#define SD_CS 5
SPIClass SDSPI(VSPI);
#include "JpegFunc.h"
// pixel drawing callback
static int jpegDrawCallback(JPEGDRAW *pDraw)
{
// Serial.printf("Draw pos = %d,%d. size = %d x %d\n", pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight);
gfx->draw16bitBeRGBBitmap(pDraw->x, pDraw->y, pDraw->pPixels, pDraw->iWidth, pDraw->iHeight);
return 1;
}
void setup()
{
Serial.begin(115200);
// Serial.setDebugOutput(true);
// while(!Serial);
Serial.println("Arduino_GFX JPEG Image Viewer example");
// Init Display
if (!gfx->begin())
{
Serial.println("gfx->begin() failed!");
}
gfx->fillScreen(BLACK);
pinMode(GFX_BL, OUTPUT);
digitalWrite(GFX_BL, HIGH);
pinMode(5 /* CS */, OUTPUT);
digitalWrite(5 /* CS */, HIGH);
SDSPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
// Initialise SD before TFT
if (!SD.begin(SD_CS, SDSPI, 40000000))
{
Serial.println(F("ERROR: File System Mount Failed!"));
gfx->println(F("ERROR: File System Mount Failed!"));
}
delay(5000);
}
void loop()
{
int w = gfx->width();
int h = gfx->height();
for (int i = 0; i < 6; i++)
{
jpegDraw(jpeg[i], jpegDrawCallback, true /* useBigEndian */, 0, 0, w, h);
delay(5000);
gfx->fillScreen(BLUE);
}
}
项目上传地址:
https://gitlab.com/pdtopdog/jczn-esp32-3248s035r/-/tree/main/JCZN_35R_Arduino_GFX_SD_ImgViewerJpeg