数码之家

 找回密码
 立即注册

QQ登录

只需一步,快速开始

微信登录

微信扫一扫,快速登录

搜索
查看: 12610|回复: 16

[Arduino] ESP8266直驱TFT屏幕显示JPEG图片

[复制链接]
发表于 2020-4-11 21:37:54 | 显示全部楼层 |阅读模式
ESP8266直驱TFT屏幕显示JPEG图片,
8266开SPIFFS,直接把XX.jpg图片放在SPIFFS里,读取并显示在屏幕上,下一步,WEB网页直接上传图片,保存在SPIFFS,并更新显示在屏幕上







=========代码如下,=========

  1. //====================================================================================
  2. //                                  Libraries
  3. //====================================================================================
  4. // Call up the SPIFFS FLASH filing system this is part of the ESP Core
  5. #define FS_NO_GLOBALS
  6. #include <FS.h>

  7. // JPEG decoder library
  8. #include <JPEGDecoder.h>

  9. // SPI library, built into IDE
  10. #include <SPI.h>

  11. // Call up the TFT library
  12. #include <TFT_eSPI.h> // Hardware-specific library for ESP8266
  13. // The TFT control pins are set in the User_Setup.h file <<<<<<<<<<<<<<<<< NOTE!
  14. // that can be found in the "src" folder of the library

  15. // Invoke TFT library
  16. TFT_eSPI tft = TFT_eSPI();

  17. //====================================================================================
  18. //                                    Setup
  19. //====================================================================================
  20. void setup()
  21. {

  22.     delay(10);
  23.    
  24.   Serial.begin(115200); // Used for messages and the C array generator

  25.   delay(10);
  26.   Serial.println("");
  27.   
  28.   Serial.println("NodeMCU decoder test!");

  29.    SPIFFS.begin();

  30.    
  31.   Serial.println("  SPIFFS.begin(); !");
  32.      Serial.println("");

  33.      
  34.   tft.begin();
  35.   tft.setRotation(0);  // 0 & 2 Portrait. 1 & 3 landscape
  36.   tft.fillScreen(TFT_BLACK);



  37.   if (!SPIFFS.begin())
  38.   {
  39.     Serial.println("SPIFFS initialisation failed!");
  40.     while (1) yield(); // Stay here twiddling thumbs waiting
  41.   }
  42.   Serial.println("\r\nInitialisation done.");
  43.   listFiles(); // Lists the files so you can see what is in the SPIFFS

  44.   
  45. if (!SPIFFS.begin())
  46. {
  47. Serial.println("SPIFFS initialisation failed!,SPIFFS初始化失败 ");
  48. if (!SPIFFS.begin())
  49. {
  50. Serial.println("SPIFFS初始化失败22 ");
  51. while (1) yield(); // Stay here twiddling thumbs waiting //呆在这里,手忙脚乱地等着

  52. }

  53. }
  54. Serial.println("\r\nInitialisation done初始化完成.");
  55. listFiles(); // Lists the files so you can see what is in the SPIFFS //列出文件,以便查看SPIFFS中的内容

  56.   

  57. }

  58. //====================================================================================
  59. //                                    Loop
  60. //====================================================================================
  61. void loop()
  62. {
  63.   // Note the / before the SPIFFS file name must be present, this means the file is in
  64.   // the root directory of the SPIFFS, e.g. "/Tiger.jpg" for a file called "Tiger.jpg"


  65.   tft.setRotation(0);  // portrait
  66.   tft.fillScreen(random(0xFFFF));

  67.   drawJpeg("/BaboonL", 0, 16); //1
  68.   delay(2000);

  69.   tft.fillScreen(random(0xFFFF));
  70.   drawJpeg("/BaboonP.jpg", 4, 0);//2
  71.   delay(2000);

  72.   tft.setRotation(1);  // landscape
  73.   //tft.fillScreen(random(0xFFFF));
  74.   drawJpeg("/EagleEye.jpg", 0, 0);//3
  75.   delay(2000);

  76.   tft.fillScreen(TFT_BLACK);
  77.   drawJpeg("/Mouse.jpg", 0, 4);//4
  78.   delay(2000);





  79. /*****************
  80.   tft.setRotation(0);  // portrait
  81.   tft.fillScreen(random(0xFFFF));

  82.   drawJpeg("/EagleEye160.jpg", 0, 16);
  83.   delay(2000);

  84.   tft.fillScreen(random(0xFFFF));
  85.   drawJpeg("/tiger160.jpg", 4, 0);
  86.   delay(2000);

  87.   tft.setRotation(1);  // landscape
  88.   //tft.fillScreen(random(0xFFFF));
  89.   drawJpeg("/arduino160.jpg", 0, 0);
  90.   delay(2000);

  91.   tft.fillScreen(TFT_BLACK);
  92.   drawJpeg("/Baboon160.jpg", 0, 4);
  93.   delay(2000);

  94.   tft.fillScreen(random(0xFFFF));
  95.   drawJpeg("/Mouse160.jpg", 0, 11);
  96.   delay(2000);

  97.   ****************/


  98. //=============================
  99.   // Create arrays from the jpeg images and send them to the serial port for copy and
  100.   // pasting into a sketch (used to make arrays fot the TFT_FLASH_Jpeg sketch)

  101.   //createArray("/EagleEye160.jpg");
  102.   //createArray("/tiger160.jpg");
  103.   //createArray("/Baboon160.jpg");
  104.   //createArray("/Mouse160.jpg");
  105.   //while(1) yield(); // Stay here
  106. }
  107. //====================================================================================
复制代码






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册 微信登录

x

打赏

参与人数 3家元 +60 收起 理由
家睦 + 20
温力口 + 10 谢谢分享。。。。。厉害!把玩8266得心应手.
qingkong + 30 赞就一个字!

查看全部打赏

 楼主| 发表于 2020-4-11 23:44:07 来自手机浏览器 | 显示全部楼层
人艰不拆了 发表于 2020-4-11 23:40
显示速度如何?

刷图很慢,主要是spi
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-13 13:01:48 来自手机浏览器 | 显示全部楼层
zxy882266 发表于 2020-4-13 11:30
楼主我为了驱动9341找到TFT_eSPI学习了一下,8266下是没问题的,但我现在要 用ESP32驱动我搞不定了,你有方 ...

那个库,里面有个文件可以修改32的脚,强大网络都有你下得到的东西
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 微信登录

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2025-7-19 20:03 , Processed in 0.171600 second(s), 11 queries , Redis On.

Powered by Discuz!

© 2006-2025 MyDigit.Net

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