2.4“ TFT LCD Shield在Arduino Mega上不起作用


9

即使在ebay的网站上,也提到我不能在Arduino Mega上使用2.4“ TFT LCD Shield显示器。问题是我错误地购买了此屏蔽。我想将此屏蔽放在Arduino Mega 2560上。 Mega和2.4“ Display Shield相结合的方法?

注意:我尝试了我朋友的Arduino Uno。Shield运行非常好。

注意:下面的照片确定了我的问题。显示器未运行我的Arduino代码。它仅运行其LED。

在此处输入图片说明

    // UTFT_Demo_320x240 (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>
#define ILI9320_16 18
// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(UNO_24,A2,A1,A3,A4);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT myGLCD(ILI9320_16,38,39,40,41);   // Remember to change the model parameter to suit your display module!

void setup()
{
  randomSeed(analogRead(0));

// Setup the LCD
  pinMode(A0,OUTPUT);       // for the UNO_SHIELD_1IN1
  digitalWrite(A0,HIGH);    // the RD pin must be set high
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;

// Clear the screen and draw the frame
  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 226, 319, 239);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.setColor(255,255,0);
  myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227);

  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 319, 225);

// Draw crosshairs
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);
  for (int i=9; i<310; i+=10)
    myGLCD.drawLine(i, 117, i, 121);
  for (int i=19; i<220; i+=10)
    myGLCD.drawLine(157, i, 161, i);

// Draw sin-, cos- and tan-lines  
  myGLCD.setColor(0,255,255);
  myGLCD.print("Sin", 5, 15);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,0,0);
  myGLCD.print("Cos", 5, 27);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,255,0);
  myGLCD.print("Tan", 5, 39);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);

// Draw a moving sinewave
  x=1;
  for (int i=1; i<(318*20); i++) 
  {
    x++;
    if (x==319)
      x=1;
    if (i>319)
    {
      if ((x==159)||(buf[x-1]==119))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled, rounded rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled circles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some lines in a pattern
  myGLCD.setColor (255,0,0);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(1, i, (i*1.44)-10, 224);
  }
  myGLCD.setColor (255,0,0);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(318, i, (i*1.44)-11, 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(1, i, 331-(i*1.44), 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(318, i, 330-(i*1.44), 224);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random circles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(256);
    y=45+random(146);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rounded rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRoundRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(209);
    x2=2+random(316);
    y2=16+random(209);
    myGLCD.drawLine(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<10000; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(316), 16+random(209));
  }

  delay(2000);

  myGLCD.fillScr(0, 0, 255);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRoundRect(80, 70, 239, 169);

  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("That's it!", CENTER, 93);
  myGLCD.print("Restarting in a", CENTER, 119);
  myGLCD.print("few seconds...", CENTER, 132);

  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.print("Runtime: (msecs)", CENTER, 210);
  myGLCD.printNumI(millis(), CENTER, 225);

  delay (10000);
}

1
eBay广告中有一个荒谬的声明:“此屏蔽板不适用于Mega Arduino,但由于Mega重新排列所有引脚的方式,它的速度仅为Uno型板的一半(无法绕开所有引脚这!)”同时运行一半速度又怎么会不起作用?
gwideman 2014年

您使用的是8位还是16位版本?
LoneWolf 2014年

您的代码说在看图片时使用引脚38-41,屏蔽层甚至都没有连接到引脚38-41。您还为Mega定义了与UNO不同的LCD模型。尝试使用与uno相同的代码;所以UTFT myGLCD(UNO_24,A2,A1,A3,A4);
Gerben

看一下措辞,听起来好像是行不通的,但是最终他们将拥有一个较慢的库来使其工作。

Answers:


7

几天前,我刚好买了相同的LCD Shields,寻找一个可以在我发现的MEGA 2560开发板上使用的库https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code其中支持UNOMEGA板。

用法很简单,如果我们想用它来MEGA我们应该改变头#include "uno_24_shield.h"SWTFT.cpp#include "mega_24_shield.h"

说明(用于在其他库中为屏蔽添加支持):

不兼容来自Mega和UNO之间用于Arduino引脚分配的不同端口映射。

UNO液晶屏中的屏蔽层将通过以下方式连接:

+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Uno port/pin  | PD7 | PD6 | PD5 | PD4 | PD3 | PD2 | PB1 | PB0 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

MEGA中,它将通过以下方式连接:

+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| MEGA port/pin | PH4 | PH3 | PE3 | PG5 | PE5 | PE4 | PH6 | PH5 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

1
哦,我的上帝!!它正在工作:D首先,我从此处下载Arduino增强版本1.0.5:forum.arduino.cc/index.php/topic,118440.0.html然后打开您的GitHub代码,然后下载。我通过之前下载的DevC / C ++程序打开swtft.cpp。我用以下命令更改了uno行:#include“ mega_24_shield.h”,然后将代码上传到Mega中,它起作用了。我只将2.4英寸TFT LCD放到了MEGA上,我没有做更多的连接。只是我将屏蔽放到了Mega上:D上帝为您节省了:D非常感谢您。错误仍然存​​在6个月。谢谢。

4

一种进行方法是创建一个电子表格,以显示该板所使用的引脚位置,以及将它们插入的Arduino屏蔽信号。在这些旁边,您需要显示与屏蔽引脚相连的ATMega2560(对于Mega2560)和ATMega328(对于Uno)上实际信号的列。您可以从Uno和Mega2560原理图获得此信息。

快速查看一下,似乎Uno和Mega的Arduino屏蔽引脚名称是相同的:例如,屏蔽引脚'0'(数字零)在两个板上的相同位置,其他引脚也是如此。

但是,在Uno上,数字0连接到ATMega328端口D的位0,而在Mega2560上,它连接到ATMega2560端口E的位0。数字2..7变得更加晦涩。

现在,当使用digitalWrite(pin,value)分别对位进行缠绕时,Arduino库无疑会转换为需要为正在使用的ATMega芯片和Arduino板设置的适当端口/位。但是,使用较低级功能的库(尤其是如果它们需要将完整的字节写入端口,例如快速的LCD库时)将需要采取自己的步骤来进行此转换。

所以...第一步是确定Mega2560是否有单独的LCD驱动程序库。

接下来,调查您的库是否具有初始化代码,该代码应确定正在运行的板上(以及板上是否包含?),或者要求您设置一些标志以告知正在使用的板上。

否则,您可能会创建一些跳线或其他一些布线方案,以使Mega的ATMega2560信号跳线,从而像Uno一样进行布线。目前尚不清楚这是否可能,因为ATMega2560的某些端口D甚至都没有连接到插头。

或者,您可以查看该库的源代码,查看其实际作用,以及需要做些什么来操作屏蔽连接的ATMega 2560引脚。



0

您需要比较Mega和朋友的Uno之间的引脚功能。然后,您需要进行这些电气连接。我在此处的答案的“固定位置”部分对此进行了一些讨论。

这需要“黑客”。需要做一些事情来重新路由那些物理连接。我通常使用中间屏蔽层根据需要平移引脚。有专门为此目的制作的盾牌,但我找不到。也许这个可行吗?


SPI没问题,因为屏蔽层使用的是D0-D7 图片。还有什么其他因素可能会影响这一点?
匿名企鹅2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.