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

这篇具有很好参考价值的文章主要介绍了Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.环境配置

Arduino下载TFT_eSPI和JPEGDecoder库
步骤:项目->加载库->管理库
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
修改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)
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程

2.示例显示图片

选择示例:
文件->TFT_eSPI->160×128->TFT_flas_jpg
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
其中jpeg1.h,jpeg2.h,jpeg3.h,jpeg4.h几个头文件里存的是图片的数据信息。

3.显示自己的图片

首先要注意一下自己图片的格式,我用的是png格式的(图片大小不要太大)。在线调整图像像素。
图片信息获取工具:https://notisrac.github.io/FileToCArray/
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
点击Copy to clipboard,复制框内的图片数据,粘贴到之前jpeg1.h中。
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程

3.1 修改示例代码

删除jpeg2.h,jpeg3.h,jpeg4.h三个头文件,如果想多显示几张可以增加到后几个头文件中
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程

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

3.2 引脚连接

引脚连接
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
实物图展示
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程

3.3 编译下载

工具设置
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程
下载程序:
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程

3.4 代码

这里不提供给jpeg1.h的代码啦,反正你们也能自己生成,对吧文章来源地址https://www.toymoban.com/news/detail-424586.html

#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,y
  delay(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 image
  uint16_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 blocks
  uint32_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 size
  uint32_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 image
  uint32_t drawTime = millis();

  // save the coordinate of the right and bottom edges to assist image cropping
  // to the screen size
  max_x += xpos;
  max_y += ypos;

  // read each MCU block until there are no more
  while (JpegDec.readSwappedBytes()) {
	  
    // save a pointer to the image block
    pImg = JpegDec.pImage ;

    // calculate where the image block should be drawn on the screen
    int mcu_x = JpegDec.MCUx * mcu_w + xpos;  // Calculate coordinates of top left corner of current MCU
    int mcu_y = JpegDec.MCUy * mcu_h + ypos;

    // check if the image block size needs to be changed for the right edge
    if (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 edge
    if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
    else win_h = min_h;

    // copy pixels into a contiguous block
    if (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 screen
    if (( 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 image
  drawTime = millis() - drawTime;

  // print the results to the serial port
  Serial.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驱动)显示图片教程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • stm32驱动st7789 TFT-LCD屏幕显示

    一切程序以最后百度网盘链接的程序为准,可能在写文章的时候有些地方有改动。 主控:STM32F103C8T6 1.69 TFT-LCD(st7789驱动) 1.1接线说明 1.2硬件初始化 TFT-LCD是采用SPI通信的,这里使用stm32f103c8t6的SPI1,初始化代码如下 1.3驱动初始化 在原有的驱动基础上增加了几个宏去控制显

    2024年02月16日
    浏览(43)
  • TFT屏幕在arduino (esp 32)下的驱动,汉字显示和字库比较

    绝大多数的tft屏幕在esp32 下都可以被 TFT_eSPI 驱动显示,以下清单中的驱动模块都可以用tft_espi来显示: 上面的驱动表基本囊括了主要的TFT显示模块,所以除非不在这个清单中,所以别找第三方驱动了。 二、TFT模块的汉字显示方式和字库调用 在TFT_eSPI 的官方系统中提供了pro

    2024年02月07日
    浏览(35)
  • 利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)

      项目:温湿度表 芯片:STM32F030C6T8 液晶:华迪1.54寸 TFT屏 温湿度传感器:SHT30      主要对液晶屏官方驱动代码进行了增加和修改。 一、STM32CubeMX建立工程          I2C1 给SHT30, SPI给液晶屏,TIM16用于内部基础定时,TIM17给LED,USART1打印调试信息。RTC预留。  SPI的DMA设置 

    2023年04月08日
    浏览(33)
  • gd32 exmc 连接 mcu 8080TFT 驱动(8pin/16pin)ST7789,40帧每秒240*320;

    #include \\\"gd32e50x.h\\\" #if    0  //RS~A23   16根数据线 #define BANK0_LCD_D         ((uint32_t)0x61000000)    //LCD data address,RS~A23 16线  2^23*2=0x1000000  #define BANK0_LCD_C         ((uint32_t)0x60000000)    //LCD register address Alternate2: EXMC_NE0=PD7~LCD_CS #define LCD_WR_DATA(value)    ((*(__IO uint16_t*)(BANK0_LCD_D)) = (

    2024年01月17日
    浏览(36)
  • 【开源&ESP32谷歌恐龙小游戏】【游戏演示和介绍】LVGL ST7789 适用于Arduino

      【源码及教程地址 - 持续更新】 ESP32 C3 LVGL 迷你小电视 Google谷歌恐龙小游戏 1.9寸LCD显示屏开发板 ST7789 适用于Arduino开发板,教程,资料,程序,代码,PDF手册 【开源 ESP32谷歌恐龙小游戏】【游戏演示和介绍】LVGL ST7789 适用于Arduin

    2024年02月10日
    浏览(35)
  • 【rust/esp32】初识slint ui框架并在st7789 lcd上显示

    esp32版本:s3 运行环境:no-std 开发环境:wsl2 LCD模块:ST7789V2 240*280 LCD Slint版本:master分支 github地址:这里 官网 为啥不用 lvgl ? 只能说rust的生态还是不太行,lvgl的rust binding似乎还在开发中,已经有仓库了,但是还在开发中。 slint 目前比较完善,但是相关资料也少。 反正已

    2024年02月05日
    浏览(40)
  • arduino-esp32:基于TFT-eSPI库实现触摸显示屏

    在arduino的IDE上已经搭建好了ESP32环境的话,写写小应用的话还是很简单的,毕竟有这么多优秀的库。 之前用自己买的TFT屏试了一下TFT-eSPI库的驱动效果,显示效果挺好的,但是触摸一直没用上。最近有空了弄了一下。 我的屏幕是2.2寸/2.4/2.8/3.2/3.5/4.0寸TFT触摸彩色SPI串口液晶屏

    2023年04月09日
    浏览(34)
  • ESP8266网络相框采用TFT_eSPI库TJpg_Decoder库mixly库UDP库实现图片传送

    用ESP8266和TFT_ESPI模块来显示图片数据。具体来说,我们将使用ILI9431显示器作为显示设备,并通过UDP协议将图片数据从发送端传输到ESP8266。最后,我们将解析这些数据并在TFT屏幕上显示出来。在这个过程中,我们将面临一些编程挑战,但我们将尽力克服它们。 首先,我们需要

    2024年01月25日
    浏览(32)
  • 使用micropython(ESP8266、ESP32)驱动SES 2.66寸墨水屏显示中文

    由于需要做一些低功耗的东西,所以最近在尝试玩墨水屏。出于成本考虑(没钱的另一种委婉说法)从咸鱼淘到2块便宜的二手SES 2.66寸三色墨水屏,并使用micropython将其驱动起来,并用字库的方法显示中文。 1.硬件连线 SES 2.66墨水屏 SES 2.66墨水屏带驱动小板 买到的屏幕是图上

    2024年01月22日
    浏览(27)
  • ESP8266+STM32获取网络时间、OLED显示时间&图片&视频。

    先说说我的设计内容的组成: 目录 学习过程不易,发文共享以下学习过程~ 1. STM32控制ESP8266获取网络时间 第一步:电脑控制ESP8266获取时间数据; 2. STM32基于获取到的时间使用定时器本地运行 3. 使用OLED显示时间数据,包括自定义的文字显示,图片显示,视频显示; 4. 完整的

    2024年02月08日
    浏览(30)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包