36浏览
查看: 36|回复: 4

[项目] 【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32

[复制链接]
今天我收到了几周前订购的两块ILI9341 TFT 屏幕。这些屏幕实际上是为 Arduino Uno 设计的扩展板,但它们在连接到其他开发板时工作得很好,而且价格非常便宜:只需 4 美元。

在这种情况下,我们将屏幕连接到 ESP32 开发板。
引脚的配置方式与您在网络上可以找到的其他示例略有不同:我试图尽量减少错误,因为我们将使用 13 个引脚,所以我认为最好的方法是使用尽可能多的连续引脚。

您也可以仅使用 4 个 IO 引脚(不是此型号)连接ILI9341,但刷新/绘画速度无法比拟。
我们将使用的库是 Bodmer TFT_eSPI库,目前我们唯一的目的是成功执行示例演示脚本。
在测试过程中,您可以将 TFT 3V3 引脚直接连接到 ESP32 3V3 引脚,但只能在短时间内进行,因为屏幕 LED 消耗的电流为 134mA,您会注意到 LED 和开发板电压限制器将如何变热。
两个 22V22 引脚之间有一个 3Ω 电阻(不是 3),足以将电流降低到 23mA,虽然屏幕不是世界上最亮的屏幕,但我认为它足以用于测试目的。
按照上图所述完成引脚连接后,如果您尚未安装TFT_eSPI库,则可以安装它。
打开 Arduino IDE,转到库管理器,然后在搜索框中键入 TFT_eSPI。在结果列表中,查找下一个并安装它。
TFT_eSPI Bodmer Arduino 库
现在您已经安装了库,您必须配置我们连接屏幕的 IO 引脚。其他库使用每个草图顶部的常量定义来执行此作,但TFT_eSPI使用通用文件来定义配置。
在您的 Arduino 安装中找到名为 User_Setup.h 的文件
它应该位于与以下路径相当的路径中:
.  [Arduino 文件夹]/libraries/TFT_eSPI/User_Setup。h

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图1

驴友花雕  中级技神
 楼主|

发表于 昨天 08:00

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32

保存文件并返回 Arduino IDE。
打开示例草图UTFT_demo(位于文件/示例/TFT_eSPI/320 x 240/UTFT_demo下)
此时,您可以编译草图并将其上传到您的 ESP32。如果一切正常,您应该会看到一些图形、背景和文本出现在您的 TFT 屏幕上。否则请仔细查看 IO 引脚配置(硬和软)。
如果它有效,您可能会像在镜子中一样看到结果。要解决此问题,请转到草图并编辑设置屏幕方向的线。这是在设置功能中完成的。

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图1

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图2

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图3


【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图4

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图5

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图6

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图7

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图8

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图9

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图10

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图11


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 昨天 08:01

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32

项目代码

  1. // Demo based on:
  2. // UTFT_Demo_320x240 by Henning Karlsen
  3. // web: http://www.henningkarlsen.com/electronics
  4. //
  5. /*
  6. This sketch uses the GLCD and font 2 only.
  7. Make sure all the display driver and pin connections are correct by
  8. editing the User_Setup.h file in the TFT_eSPI library folder.
  9. #########################################################################
  10. ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
  11. #########################################################################
  12. */
  13. #include "SPI.h"
  14. #include "TFT_eSPI.h"
  15. #define TFT_GREY 0x7BEF
  16. TFT_eSPI myGLCD = TFT_eSPI();       // Invoke custom library
  17. unsigned long runTime = 0;
  18. void setup()
  19. {
  20.   randomSeed(analogRead(A0));
  21. // Setup the LCD
  22.   myGLCD.init();
  23.   myGLCD.setRotation(1);
  24. }
  25. void loop()
  26. {
  27.   randomSeed(millis());
  28.   //randomSeed(1234); // This ensure test is repeatable with exact same draws each loop
  29.   int buf[318];
  30.   int x, x2;
  31.   int y, y2;
  32.   int r;
  33.   runTime = millis();
  34. // Clear the screen and draw the frame
  35.   myGLCD.fillScreen(TFT_BLACK);
  36.   myGLCD.fillRect(0, 0, 319, 14,TFT_RED);
  37.   myGLCD.fillRect(0, 226, 319, 14,TFT_GREY);
  38.   myGLCD.setTextColor(TFT_BLACK,TFT_RED);
  39.   myGLCD.drawCentreString("* TFT_eSPI *", 160, 4, 1);
  40.   myGLCD.setTextColor(TFT_YELLOW,TFT_GREY);
  41.   myGLCD.drawCentreString("Adapted by Bodmer", 160, 228,1);
  42.   myGLCD.drawRect(0, 14, 319, 211, TFT_BLUE);
  43. // Draw crosshairs
  44.   myGLCD.drawLine(159, 15, 159, 224,TFT_BLUE);
  45.   myGLCD.drawLine(1, 119, 318, 119,TFT_BLUE);
  46.   for (int i=9; i<310; i+=10)
  47.     myGLCD.drawLine(i, 117, i, 121,TFT_BLUE);
  48.   for (int i=19; i<220; i+=10)
  49.     myGLCD.drawLine(157, i, 161, i,TFT_BLUE);
  50. // Draw sin-, cos- and tan-lines  
  51.   myGLCD.setTextColor(TFT_CYAN);
  52.   myGLCD.drawString("Sin", 5, 15,2);
  53.   for (int i=1; i<318; i++)
  54.   {
  55.     myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95),TFT_CYAN);
  56.   }
  57.   myGLCD.setTextColor(TFT_RED);
  58.   myGLCD.drawString("Cos", 5, 30,2);
  59.   for (int i=1; i<318; i++)
  60.   {
  61.     myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95),TFT_RED);
  62.   }
  63.   myGLCD.setTextColor(TFT_YELLOW);
  64.   myGLCD.drawString("Tan", 5, 45,2);
  65.   for (int i=1; i<318; i++)
  66.   {
  67.     myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)),TFT_YELLOW);
  68.   }
  69.   delay(0);
  70.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  71.   myGLCD.drawLine(159, 15, 159, 224,TFT_BLUE);
  72.   myGLCD.drawLine(1, 119, 318, 119,TFT_BLUE);
  73. int col = 0;
  74. // Draw a moving sinewave
  75.   x=1;
  76.   for (int i=1; i<(317*20); i++)
  77.   {
  78.     x++;
  79.     if (x==318)
  80.       x=1;
  81.     if (i>318)
  82.     {
  83.       if ((x==159)||(buf[x-1]==119))
  84.         col = TFT_BLUE;
  85.       else
  86.       myGLCD.drawPixel(x,buf[x-1],TFT_BLACK);
  87.     }
  88.     y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
  89.     myGLCD.drawPixel(x,y,TFT_BLUE);
  90.     buf[x-1]=y;
  91.   }
  92.   delay(0);
  93.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  94. // Draw some filled rectangles
  95.   for (int i=1; i<6; i++)
  96.   {
  97.     switch (i)
  98.     {
  99.       case 1:
  100.         col = TFT_MAGENTA;
  101.         break;
  102.       case 2:
  103.         col = TFT_RED;
  104.         break;
  105.       case 3:
  106.         col = TFT_GREEN;
  107.         break;
  108.       case 4:
  109.         col = TFT_BLUE;
  110.         break;
  111.       case 5:
  112.         col = TFT_YELLOW;
  113.         break;
  114.     }
  115.     myGLCD.fillRect(70+(i*20), 30+(i*20), 60, 60,col);
  116.   }
  117.   delay(0);
  118.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  119. // Draw some filled, rounded rectangles
  120.   for (int i=1; i<6; i++)
  121.   {
  122.     switch (i)
  123.     {
  124.       case 1:
  125.         col = TFT_MAGENTA;
  126.         break;
  127.       case 2:
  128.         col = TFT_RED;
  129.         break;
  130.       case 3:
  131.         col = TFT_GREEN;
  132.         break;
  133.       case 4:
  134.         col = TFT_BLUE;
  135.         break;
  136.       case 5:
  137.         col = TFT_YELLOW;
  138.         break;
  139.     }
  140.     myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 60,60, 3,col);
  141.   }
  142.   
  143.   delay(0);
  144.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  145. // Draw some filled circles
  146.   for (int i=1; i<6; i++)
  147.   {
  148.     switch (i)
  149.     {
  150.       case 1:
  151.         col = TFT_MAGENTA;
  152.         break;
  153.       case 2:
  154.         col = TFT_RED;
  155.         break;
  156.       case 3:
  157.         col = TFT_GREEN;
  158.         break;
  159.       case 4:
  160.         col = TFT_BLUE;
  161.         break;
  162.       case 5:
  163.         col = TFT_YELLOW;
  164.         break;
  165.     }
  166.     myGLCD.fillCircle(100+(i*20),60+(i*20), 30,col);
  167.   }
  168.   
  169.   delay(0);
  170.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  171. // Draw some lines in a pattern
  172.   for (int i=15; i<224; i+=5)
  173.   {
  174.     myGLCD.drawLine(1, i, (i*1.44)-10, 223,TFT_RED);
  175.   }
  176.   for (int i=223; i>15; i-=5)
  177.   {
  178.     myGLCD.drawLine(317, i, (i*1.44)-11, 15,TFT_RED);
  179.   }
  180.   for (int i=223; i>15; i-=5)
  181.   {
  182.     myGLCD.drawLine(1, i, 331-(i*1.44), 15,TFT_CYAN);
  183.   }
  184.   for (int i=15; i<224; i+=5)
  185.   {
  186.     myGLCD.drawLine(317, i, 330-(i*1.44), 223,TFT_CYAN);
  187.   }
  188.   
  189.   delay(0);
  190.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  191. // Draw some random circles
  192.   for (int i=0; i<100; i++)
  193.   {
  194.     x=32+random(256);
  195.     y=45+random(146);
  196.     r=random(30);
  197.     myGLCD.drawCircle(x, y, r,random(0xFFFF));
  198.   }
  199.   delay(0);
  200.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  201. // Draw some random rectangles
  202.   for (int i=0; i<100; i++)
  203.   {
  204.     x=2+random(316);
  205.     y=16+random(207);
  206.     x2=2+random(316);
  207.     y2=16+random(207);
  208.     if (x2<x) {
  209.       r=x;x=x2;x2=r;
  210.     }
  211.     if (y2<y) {
  212.       r=y;y=y2;y2=r;
  213.     }
  214.     myGLCD.drawRect(x, y, x2-x, y2-y,random(0xFFFF));
  215.   }
  216.   delay(0);
  217.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  218. // Draw some random rounded rectangles
  219.   for (int i=0; i<100; i++)
  220.   {
  221.     x=2+random(316);
  222.     y=16+random(207);
  223.     x2=2+random(316);
  224.     y2=16+random(207);
  225.     // We need to get the width and height and do some window checking
  226.     if (x2<x) {
  227.       r=x;x=x2;x2=r;
  228.     }
  229.     if (y2<y) {
  230.       r=y;y=y2;y2=r;
  231.     }
  232.     // We need a minimum size of 6
  233.     if((x2-x)<6) x2=x+6;
  234.     if((y2-y)<6) y2=y+6;
  235.     myGLCD.drawRoundRect(x, y, x2-x,y2-y, 3,random(0xFFFF));
  236.   }
  237.   delay(0);
  238.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  239. //randomSeed(1234);
  240. int colour = 0;
  241. for (int i=0; i<100; i++)
  242.   {
  243.     x=2+random(316);
  244.     y=16+random(209);
  245.     x2=2+random(316);
  246.     y2=16+random(209);
  247.     colour=random(0xFFFF);
  248.     myGLCD.drawLine(x, y, x2, y2,colour);
  249.   }
  250.   delay(0);
  251.   myGLCD.fillRect(1,15,317,209,TFT_BLACK);
  252.   // This test has been modified as it takes more time to calculate the random numbers
  253.   // than to draw the pixels (3 seconds to produce 30,000 randoms)!
  254.   for (int i=0; i<10000; i++)
  255.   {
  256.     myGLCD.drawPixel(2+random(316), 16+random(209),random(0xFFFF));
  257.   }
  258.   // Draw 10,000 pixels to fill a 100x100 pixel box
  259.   // use the coords as the colour to produce the banding
  260.   //byte i = 100;
  261.   //while (i--) {
  262.   //  byte j = 100;
  263.   //  while (j--) myGLCD.drawPixel(i+110,j+70,i+j);
  264.   //  //while (j--) myGLCD.drawPixel(i+110,j+70,0xFFFF);
  265.   //}
  266.   delay(0);
  267.   myGLCD.fillScreen(TFT_BLUE);
  268.   myGLCD.fillRoundRect(80, 70, 239-80,169-70, 3,TFT_RED);
  269.   
  270.   myGLCD.setTextColor(TFT_WHITE,TFT_RED);
  271.   myGLCD.drawCentreString("That's it!", 160, 93,2);
  272.   myGLCD.drawCentreString("Restarting in a", 160, 119,2);
  273.   myGLCD.drawCentreString("few seconds...", 160, 132,2);
  274.   runTime = millis()-runTime;
  275.   myGLCD.setTextColor(TFT_GREEN,TFT_BLUE);
  276.   myGLCD.drawCentreString("Runtime: (msecs)", 160, 210,2);
  277.   myGLCD.setTextDatum(TC_DATUM);
  278.   myGLCD.drawNumber(runTime, 160, 225,2);
  279.   delay (5000);
  280. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 昨天 08:06

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32

【Arduino 动手做】ILI9341屏使用TFT_eSPI库以并行模式(8 个数据引脚)连接到 ESP32
项目链接:https://www.pangodream.es/ili9341-esp32-parallel
项目作者:阿尔贝托·伊里贝里·安德烈斯

项目视频 :https://www.youtube.com/watch?v=dhQjDKtNi58
项目代码:https://github.com/Bodmer/TFT_eS ... _demo/UTFT_demo.ino
Bodmer TFT_eSPI库:https://github.com/Bodmer/TFT_eSPI

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 昨天 08:10

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图2

【Arduino 动手做】ILI9341屏使用TFT_eSPI库并行连接 ESP32图1
回复

使用道具 举报

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail