数码之家

 找回密码
 立即注册
搜索
查看: 12439|回复: 16

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

[复制链接]
发表于 2020-4-11 21:37:54 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

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

x
ESP8266直驱TFT屏幕显示JPEG图片,
8266开SPIFFS,直接把XX.jpg图片放在SPIFFS里,读取并显示在屏幕上,下一步,WEB网页直接上传图片,保存在SPIFFS,并更新显示在屏幕上

8166.jpg
11.jpg
22.jpg
33.jpg


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

  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. //====================================================================================
复制代码






打赏

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

查看全部打赏

发表于 2020-4-11 23:40:27 | 显示全部楼层
显示速度如何?
回复 支持 反对

使用道具 举报

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

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

使用道具 举报

发表于 2020-4-11 23:46:59 | 显示全部楼层
mckk520 发表于 2020-4-11 23:44
刷图很慢,主要是spi

哈哈,我的也很慢:mad:
回复 支持 反对

使用道具 举报

发表于 2020-4-12 00:37:55 来自手机浏览器 | 显示全部楼层
这个没搞过spi屏幕 但是看micropython是有个硬件spi接口的 80mhz啊

而arduino croe和micropython是同源的啊 ardunio应该也有类似的接口吧

micropyhton下的引用是hspi...

Hardware SPI bus
The hardware SPI is faster (up to 80Mhz), but only works on following pins: MISO is GPIO12, MOSI is GPIO13, and SCK is GPIO14. It has the same methods as the bitbanging SPI class above, except for the pin parameters for the constructor and init (as those are fixed):
回复 支持 反对

使用道具 举报

发表于 2020-4-12 00:46:59 来自手机浏览器 | 显示全部楼层
arduino也是有这个东西的


SPI
SPI library supports the entire Arduino SPI API including transactions, including setting phase (CPHA). Setting the Clock polarity (CPOL) is not supported, yet (SPI_MODE2 and SPI_MODE3 not working).

The usual SPI pins are:

MOSI = GPIO13
MISO = GPIO12
SCLK = GPIO14
There’s an extended mode where you can swap the normal pins to the SPI0 hardware pins. This is enabled by calling SPI.pins(6, 7, 8, 0) before the call to SPI.begin(). The pins would change to:

MOSI = SD1
MISO = SD0
SCLK = CLK
HWCS = GPIO0
This mode shares the SPI pins with the controller that reads the program code from flash and is controlled by a hardware arbiter (the flash has always higher priority). For this mode the CS will be controlled by hardware as you can’t handle the CS line with a GPIO, you never actually know when the arbiter is going to grant you access to the bus so you must let it handle CS automatically.
回复 支持 反对

使用道具 举报

发表于 2020-4-13 11:30:38 | 显示全部楼层
楼主我为了驱动9341找到TFT_eSPI学习了一下,8266下是没问题的,但我现在要 用ESP32驱动我搞不定了,你有方案吗?还有就是你说的图片显示问题能讲的详细点吗,俺软件真的不行,求教了
回复 支持 反对

使用道具 举报

发表于 2020-4-13 12:02:30 | 显示全部楼层
#include <FS.h>
#include <JPEGDecoder.h>
这俩库也贡献下吧楼主,如何添加他们
回复 支持 反对

使用道具 举报

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

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

使用道具 举报

发表于 2020-5-4 08:45:18 | 显示全部楼层
谢谢分享。。。。。厉害!把玩8266得心应手。。。。
回复 支持 反对

使用道具 举报

发表于 2020-5-4 10:39:58 | 显示全部楼层

我的8266SPI刷到飞,不知道你们咋回事
回复 支持 反对

使用道具 举报

发表于 2020-7-5 00:28:06 | 显示全部楼层
我用Adafruit库  spi刷屏也是飞起啊,可以跑动画呢
回复 支持 反对

使用道具 举报

发表于 2020-7-22 00:42:53 来自手机浏览器 | 显示全部楼层
www.jztmkj.com 发表于 2020-7-5 00:28
我用Adafruit库  spi刷屏也是飞起啊,可以跑动画呢

我用micropython ,esp32硬件spi驱动oled也慢
回复 支持 反对

使用道具 举报

发表于 2021-4-6 23:17:08 | 显示全部楼层
有两个问题想求教一下楼主:listFiles 和 drawJpeg这两个函数内容是啥呀,不太懂:doubt:doubt:
回复 支持 1 反对 0

使用道具 举报

发表于 2021-4-25 10:26:49 | 显示全部楼层
本帖最后由 inthsunshine 于 2021-4-25 10:29 编辑
stategrid 发表于 2020-7-22 00:42
我用micropython ,esp32硬件spi驱动oled也慢

是库的问题,层层封装影响了刷新速度, 硬件SPI不背锅,,一闪而过几乎感觉不到延迟,我曾发过帖子
回复 支持 反对

使用道具 举报

发表于 2022-7-9 20:31:42 | 显示全部楼层
: In function 'void loop()':
3_4_8_SPIFFS_File_Upload_Server:88:3: error: 'drawJpeg' was not declared in this scope
   88 |   drawJpeg("/01.jpg", 4, 0);//2
      |   ^~~~~~~~

请问是什么错误,怎么修改? 这个 drawJpeg  有问题
回复 支持 反对

使用道具 举报

发表于 2022-7-10 13:53:56 | 显示全部楼层
listFiles()  drawJpeg  可以发这两个涵数代码吗???
回复 支持 反对

使用道具 举报

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

本版积分规则

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

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2025-6-8 15:22 , Processed in 0.202800 second(s), 16 queries , Redis On.

Powered by Discuz!

© 2006-2025 MyDigit.Net

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