1.环境配置

Arduino下载TFT_eSPI和JPEGDecoder库
步骤:项目->加载库->管理库


修改User_Setup.h
驱动
#define ST7789_DRIVER
屏尺寸(我的是240*240)
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
连接引脚
#define TFT_CS PIN_D8 // Chip select control pin D8
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin)


2.示例显示图片

选择示例:
文件->TFT_eSPI->160×128->TFT_flas_jpg

其中jpeg1.h,jpeg2.h,jpeg3.h,jpeg4.h几个头文件里存的是图片的数据信息。

3.显示自己的图片

首先要注意一下自己图片的格式,我用的是png格式的(图片大小不要太大)。在线调整图像像素。
图片信息获取工具:https://notisrac.github.io/FileToCArray/

点击Copy to clipboard,复制框内的图片数据,粘贴到之前jpeg1.h中。

3.1 修改示例代码

删除jpeg2.h,jpeg3.h,jpeg4.h三个头文件,如果想多显示几张可以增加到后几个头文件中

其他的我没有修改,需要其他功能的再百度吧,俺还不会。

3.2 引脚连接

引脚连接

实物图展示

3.3 编译下载

工具设置

下载程序:

3.4 代码

这里不提供给jpeg1.h的代码啦,反正你们也能自己生成,对吧

#include <SPI.h>
#include <TFT_eSPI.h>TFT_eSPI tft = TFT_eSPI();// JPEG decoder library
#include <JPEGDecoder.h>// Return the minimum of two values a and b
#define minimum(a,b)     (((a) < (b)) ? (a) : (b))// Include the sketch header file that contains the image stored as an array of bytes
// More than one image array could be stored in each header file.
#include "jpeg1.h"// Count how many times the image is drawn for test purposes
uint32_t icount = 0;
//----------------------------------------------------------------------------------------------------//####################################################################################################
// Setup
//####################################################################################################
void setup() {Serial.begin(115200);tft.begin();
}//####################################################################################################
// Main loop
//####################################################################################################
void loop() {drawArrayJpeg(_1661000196384, sizeof(_1661000196384), 0, 0); // Draw a jpeg image stored in memory at x,ydelay(2000);
}//####################################################################################################
// Draw a JPEG on the TFT pulled from a program memory array
//####################################################################################################
void drawArrayJpeg(const uint8_t arrayname[], uint32_t array_size, int xpos, int ypos) {int x = xpos;int y = ypos;JpegDec.decodeArray(arrayname, array_size);jpegInfo(); // Print information from the JPEG file (could comment this line out)renderJPEG(x, y);Serial.println("#########################");
}//####################################################################################################
// Draw a JPEG on the TFT, images will be cropped on the right/bottom sides if they do not fit
//####################################################################################################
// This function assumes xpos,ypos is a valid screen coordinate. For convenience images that do not
// fit totally on the screen are cropped to the nearest MCU size and may leave right/bottom borders.
void renderJPEG(int xpos, int ypos) {// retrieve infomration about the imageuint16_t *pImg;uint16_t mcu_w = JpegDec.MCUWidth;uint16_t mcu_h = JpegDec.MCUHeight;uint32_t max_x = JpegDec.width;uint32_t max_y = JpegDec.height;// Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)// Typically these MCUs are 16x16 pixel blocks// Determine the width and height of the right and bottom edge image blocksuint32_t min_w = minimum(mcu_w, max_x % mcu_w);uint32_t min_h = minimum(mcu_h, max_y % mcu_h);// save the current image block sizeuint32_t win_w = mcu_w;uint32_t win_h = mcu_h;// record the current time so we can measure how long it takes to draw an imageuint32_t drawTime = millis();// save the coordinate of the right and bottom edges to assist image cropping// to the screen sizemax_x += xpos;max_y += ypos;// read each MCU block until there are no morewhile (JpegDec.readSwappedBytes()) {// save a pointer to the image blockpImg = JpegDec.pImage ;// calculate where the image block should be drawn on the screenint mcu_x = JpegDec.MCUx * mcu_w + xpos;  // Calculate coordinates of top left corner of current MCUint mcu_y = JpegDec.MCUy * mcu_h + ypos;// check if the image block size needs to be changed for the right edgeif (mcu_x + mcu_w <= max_x) win_w = mcu_w;else win_w = min_w;// check if the image block size needs to be changed for the bottom edgeif (mcu_y + mcu_h <= max_y) win_h = mcu_h;else win_h = min_h;// copy pixels into a contiguous blockif (win_w != mcu_w){uint16_t *cImg;int p = 0;cImg = pImg + win_w;for (int h = 1; h < win_h; h++){p += mcu_w;for (int w = 0; w < win_w; w++){*cImg = *(pImg + w + p);cImg++;}}}// draw image MCU block only if it will fit on the screenif (( mcu_x + win_w ) <= tft.width() && ( mcu_y + win_h ) <= tft.height()){tft.pushRect(mcu_x, mcu_y, win_w, win_h, pImg);}else if ( (mcu_y + win_h) >= tft.height()) JpegDec.abort(); // Image has run off bottom of screen so abort decoding}// calculate how long it took to draw the imagedrawTime = millis() - drawTime;// print the results to the serial portSerial.print(F(  "Total render time was    : ")); Serial.print(drawTime); Serial.println(F(" ms"));Serial.println(F(""));
}//####################################################################################################
// Print image information to the serial port (optional)
//####################################################################################################
void jpegInfo() {Serial.println(F("==============="));Serial.println(F("JPEG image info"));Serial.println(F("==============="));Serial.print(F(  "Width      :")); Serial.println(JpegDec.width);Serial.print(F(  "Height     :")); Serial.println(JpegDec.height);Serial.print(F(  "Components :")); Serial.println(JpegDec.comps);Serial.print(F(  "MCU / row  :")); Serial.println(JpegDec.MCUSPerRow);Serial.print(F(  "MCU / col  :")); Serial.println(JpegDec.MCUSPerCol);Serial.print(F(  "Scan type  :")); Serial.println(JpegDec.scanType);Serial.print(F(  "MCU width  :")); Serial.println(JpegDec.MCUWidth);Serial.print(F(  "MCU height :")); Serial.println(JpegDec.MCUHeight);Serial.println(F("==============="));
}//####################################################################################################
// Show the execution time (optional)
//####################################################################################################
// WARNING: for UNO/AVR legacy reasons printing text to the screen with the Mega might not work for
// sketch sizes greater than ~70KBytes because 16 bit address pointers are used in some libraries.// The Due will work fine with the HX8357_Due library.void showTime(uint32_t msTime) {//tft.setCursor(0, 0);//tft.setTextFont(1);//tft.setTextSize(2);//tft.setTextColor(TFT_WHITE, TFT_BLACK);//tft.print(F(" JPEG drawn in "));//tft.print(msTime);//tft.println(F(" ms "));Serial.print(F(" JPEG drawn in "));Serial.print(msTime);Serial.println(F(" ms "));
}

Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程相关推荐

  1. Arduino+esp8266+1.4寸TFT屏(st7735驱动)解决显示图片偏色以及屏幕边缘花边问题

    买回来的屏幕一跑例程出现这个情况? 原图: 屏幕显示: 首先偏色问题存在,且屏幕花边(没复现的出来,假装有). 解决方法: 主要问题出现在 Arduino\libraries\TFT_eSPI 这个库 ...

  2. 0.1.3 合宙CORE-ESP32-C3开发板用arduino点亮ST7735 1.8寸TFT屏【已更新失效链接2022.07.10】

    9.9的ESP32开发板想用arduino开发,无奈都是用luatos玩,于是折腾了下 目的 用arduino驱动合宙ESP32-C3开发板点亮S7735TFT屏 材料 CORE-ESP32-C3开发 ...

  3. Arduino ST7789 240*240 1.3寸 TFT —— 飞升之高效率显示驱动篇

    昨天的屏幕到了,也用之前"发现的"Arduino-ST7789-Library"专用驱动库"进行了点亮操作,但总是感觉屏幕显示的效率差强人意.因为在做TFT屏幕 ...

  4. 天马3.5寸TFT屏调试文档

    天马 3.5 寸 TFT 屏调试文档 王小涛 2009 年 6 月 12 日 修订版 1 .坐标定位 触摸屏点击时驱动读入的是ADC值,也就是电压值(AD后),一个是x坐标的ADC值,一个是y坐标的A ...

  5. 0.96寸OLED屏硬件驱动电路

    0.96寸OLED屏硬件驱动电路 该电路适合把OLED驱动电路集成到自己的板子上,最终的原理图和PCB已经上传CSDN,可直接点击链接下载: https://download.csdn.net/dow ...

  6. esp32 cam 1.44寸TFT彩屏 ST7735S驱动 TFT_eSPI库驱动

    ESP32 CAM引脚与TFT1.44(ST7735S)引脚接线 ESP32 CAM TFT 1.44 5V VCC GND GND GND NC NC 5V BLC D14 SCL D15 SDA ...

  7. TFT屏的驱动ST7735S使用实例

    首先引脚定义如下:我使用的是硬件spi2,SDA接的就是MCU的SDI引脚,CS对应spi2的CS,A0随便找一个io口,这个引脚设置高低决定是写数据还是写命令,SCK就是SPI的时钟,我使用的是主模 ...

  8. 树莓派驱动1.44寸TFT液晶并实时显示摄像头图像

    ** 需要什么 ** 一块lcd ,市面上大多数为spi ,i2c驱动的lcd,我这块是比赛剩下的模拟8080端口驱动.区别不大,仅需改动发送数据的函数 一个摄像头,我这里使用的是某宝17块钱买来的o ...

  9. 1.3寸OLED SH1106 IIC驱动显示错误解决方法

    网上买的1.3寸OLED 用的时候发现显示有问题,整体像素都往左两个,导致左边少两列像素,右边两列则为乱码. 解决方法 在设置光标函数中让x轴向右位移2个像素. void OLED_SetCursor ...

最新文章

  1. java startswith忽略大小写_Java String startsWith()方法与示例
  2. php去掉内部空格_php中去掉头尾空格3种方法
  3. leetcode981. 基于时间的键值存储(treemap)
  4. Cacti 使用安装详解-企业级实例
  5. smarty模板基础知识
  6. 解题报告:hdu 1556 Color the ball(区间修改,单点查询)
  7. 多项目Node版本控制
  8. 哈尔滨工程大学第十四届程序设计竞赛(同步赛)
  9. 勒索病毒GandCrab5.2解密工具
  10. 仿真软件Multisim 10下载地址与破解补丁
  11. hdmi接口和计算机连接,hdmi接口,手把手教你hdmi接口怎么连接电视
  12. 二、用于数据分析的Tableau技巧
  13. vb/vb.net开发技巧荟萃(九)
  14. 1.CPU体系架构-RISC指令集和CISC指令集
  15. html div里里h标签居中,html之块级标签h系列,div
  16. html [JS]随机密码生成[运维工具]
  17. feign 传 MultipartFile Error converting request body 序列化 错误
  18. 输入过压保护电路OVP原理和仿真
  19. 信号完整性分析-笔记
  20. 发送手机验证码,验证手机验证码,包括数据表的设计

热门文章

  1. docker网卡的IP地址修改
  2. 自组织神经网络聚类算法,神经网络聚类预测分析
  3. 巴塞尔委员会:加密产业的增长可能对银行和金融稳定性产生威胁
  4. ntoskrnl.exe占用大量cpu解决方法
  5. 多目标优化算法:多目标人工兔优化算法(Multi-Objective Artificial Rabbits Optimization ,MOARO)
  6. 分享内容:推荐大家一个靠谱的论文检测平台。重复的部分有详细出处以及具体修改意见,能直接在文章上做修改,全部改完一键下载就搞定了。怕麻烦的话,还能用它自带的降重功能。哦对了,他们现在正在做毕业季活动,
  7. Collaborative Diffusion
  8. c语言putchar和scanf,C语言学习——getchar()、putchar()、scanf和printf用法
  9. 未来的计算机 展望未来作文,以展望未来为题的作文(精选4篇)
  10. 狗熊掰棒子及井底之蛙