Go Down

Topic: Odd occurance with TFT library. (Read 125 times) previous topic - next topic

Arnak

Hi,

This is a very strange issue that I came across.

The program below will compile and work but only with a 2013 version of the TFT library by Enrico Gueli.

I do get some SD warnings but they are not for functions that I will be using.

My Arduino is connected to a Makehawk 1.44" display and it works!

After compiling with the latest TFT library I get the following errors, can anyone please explain why?

Thanks,

Martin

Code: [Select]
// include TFT and SPI libraries
#include <TFT.h> 
#include <SPI.h>

// pin definition for Arduino UNO
 #define cs    A5
 #define dc    A3
 #define mosi  A2
 #define sclk  A1
 #define rst   A4
// create an instance of the library
// TFT TFTscreen = TFT(cs, dc, rst);

         //TFT(cs, dc, mosi, sclk, rst);
TFT TFTscreen = TFT(A5, A3, A2, A1, A4);

void setup() {

  //initialize the library
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  //set the text size
  TFTscreen.setTextSize(2);
}

void loop() {

  //generate a random color
  int redRandom = random(0, 255);
  int greenRandom = random (0, 255);
  int blueRandom = random (0, 255);
 
  // set a random font color
  TFTscreen.stroke(redRandom, greenRandom, blueRandom);

  pinMode(A0, OUTPUT);
    digitalWrite(A0, HIGH);  //switch backlight on
 
  // print Hello, World! in the middle of the screen
  TFTscreen.text("Hello, World!", 6, 57);
 
  // wait 200 miliseconds until change to next color
  delay(200);
}



In file included from C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:36:0,

                 from C:\Users\oem\Documents\Arduino\Working_Version\Working_Version.ino:7:

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/utility/Adafruit_GFX.h:60:3: warning: #warning "The SD library was not found. loadImage() and image() won't be supported." [-Wcpp]

  #warning "The SD library was not found. loadImage() and image() won't be supported."

   ^

Working_Version:20:39: error: no matching function for call to 'TFT::TFT(const uint8_t&, const uint8_t&, const uint8_t&, const uint8_t&, const uint8_t&)'

 TFT TFTscreen = TFT(A5, A3, A2, A1, A4);

                                       ^

In file included from C:\Users\oem\Documents\Arduino\Working_Version\Working_Version.ino:7:0:

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:47:3: note: candidate: TFT::TFT(uint8_t, uint8_t, uint8_t)

   TFT(uint8_t CS, uint8_t RS, uint8_t RST);

   ^

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:47:3: note:   candidate expects 3 arguments, 5 provided

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:45:7: note: candidate: constexpr TFT::TFT(const TFT&)

 class TFT : public Adafruit_ST7735 {

       ^

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:45:7: note:   candidate expects 1 argument, 5 provided

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:45:7: note: candidate: constexpr TFT::TFT(TFT&&)

C:\Program Files (x86)\arduino-1.8.9\libraries\TFT\src/TFT.h:45:7: note:   candidate expects 1 argument, 5 provided

Multiple libraries were found for "TFT.h"
 Used: C:\Program Files (x86)\arduino-1.8.9\libraries\TFT
 Not used: C:\Program Files (x86)\arduino-1.8.9\libraries\new display
Using library TFT at version 1.0.6 in folder: C:\Program Files (x86)\arduino-1.8.9\libraries\TFT
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\arduino-1.8.9\hardware\arduino\avr\libraries\SPI
exit status 1
no matching function for call to 'TFT::TFT(const uint8_t&, const uint8_t&, const uint8_t&, const uint8_t&, const uint8_t&)'



pert

Unfortunately, you'll often find that there are multiple Arduino libraries with a generic name like "TFT" with different APIs. Code written for one "TFT" library may not work for the other.

You'll be happy to know that I did recently add the software SPI constructor to Arduino's official TFT library. There hasn't been a release of the library since that time so you can't get the update from the Arduino IDE's Library Manager. You'll need to install it manually:
  • Download https://github.com/arduino-libraries/TFT/archive/master.zip
  • Unzip the downloaded file
  • Rename the unzipped folder from TFT-master to TFT.
  • Move the TFT folder to {sketchbook folder}/libraries. You can find the location of {sketchbook folder} in the Arduino IDE at File > Preferences > Sketchbook location.


Not used: C:\Program Files (x86)\arduino-1.8.9\libraries\new display
It's a very bad idea to install libraries to the Arduino IDE installation folder. The reason is that everything in that folder will be not recognized or lost when you update to a new version of the Arduino IDE. This is why you should always install libraries to the libraries subfolder of the sketchbook folder. That will happen automatically when you install libraries via the Arduino IDE's Library Manager or Sketch > Include Library > Add .ZIP Library so I recommend using those installation methods whenever possible.

Arnak

Hi Pert,

Thanks very much for the reply. :)

I have now used the new TFT library and my latest version of my new code compiles correctly thanks to you.

Martin

pert

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

Go Up