Compiling Errors trying to use the TFT-library

Hello together,

I am trying to use the TFT Library in order to print some lines, circles and text on the display.
I am using a Arduino Uno and set it in that way in the IDE.

I added the TFT library and both GFX libraries:

#include <TFT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>

I initialized the Display with

#define cs   10
#define dc   9
#define rst  8  


TFT screen = TFT(cs, dc, rst);

In the setup section I started the Display with

  screen.begin();
  screen.background(bgr,bgg,bgb); 
  screen.noFill();

In the loop section I drawed some lines and wrote some text using the commands from the TFT library (none of the GFX Library).

While compiling I get following error messages in the end. Has anyone of you any idea how you could fix that? I already googled after that problem but didn't found any solution for the Arduino One.

In file included from C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:19:
C:\Program Files (x86)\Arduino\libraries\TFT\utility\/Adafruit_ST7735.h: In member function 'uint16_t Adafruit_ST7735::Color565(uint8_t, uint8_t, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\/Adafruit_ST7735.h:116: error: 'newColor' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: In constructor 'Adafruit_ST7735::Adafruit_ST7735(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:33: error: no matching function for call to 'Adafruit_GFX::Adafruit_GFX()'
C:\Users\Felix\Documents\Arduino\libraries\Adafruit_GFX/Adafruit_GFX.h:17: note: candidates are: Adafruit_GFX::Adafruit_GFX(int16_t, int16_t)
C:\Users\Felix\Documents\Arduino\libraries\Adafruit_GFX/Adafruit_GFX.h:13: note:                 Adafruit_GFX::Adafruit_GFX(const Adafruit_GFX&)
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: In constructor 'Adafruit_ST7735::Adafruit_ST7735(uint8_t, uint8_t, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:45: error: no matching function for call to 'Adafruit_GFX::Adafruit_GFX()'
C:\Users\Felix\Documents\Arduino\libraries\Adafruit_GFX/Adafruit_GFX.h:17: note: candidates are: Adafruit_GFX::Adafruit_GFX(int16_t, int16_t)
C:\Users\Felix\Documents\Arduino\libraries\Adafruit_GFX/Adafruit_GFX.h:13: note:                 Adafruit_GFX::Adafruit_GFX(const Adafruit_GFX&)
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: At global scope:
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:101: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:160: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:197: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:205: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:214: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:261: error: 'constructor' was not declared in this scope

Thank you very much!

Where did you download that adafruit library, because I'm looking that the original library HERE, and see no such variable "newcolor" in this function, Adafruit_ST7735::Color565(uint8_t, uint8_t, uint8_t), in the library.

Could you post your full code.

I am using exactly this version, that's the reason why I'm wondered.

My full code is seperated in 3 files, here is the first:
Comments are mostly in German, if you don't understand something, just ask.

I want to do a digital read of three distance sensors, calculate a plane and draw a crosshair like a bubble level.
I also tried to disable the Sensor-API but I still get the same error message.

// === Includes: ===

// Displayfunktionen integrieren
#include <Display.ino>

// Sensorberechnungen integrieren
#include <sensorcalc.ino>

//Sensor-API:
#include <GP2D02.h>

//Importieren der Library für die Ansteuerung des Displays
#include <TFT.h>

//Möglichkeit Bilder von einer SD-Karte zu laden
//#include <SD.h>

//Include der Grafiklibrary
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>


// Display Anschlüsse (nur die fürs Display beachten: http://arduino.cc/en/uploads/Tutorial/GTFT_text_large.png
#include <SPI.h>
//Des Display wird mit SPI angesteuert


//=== Display: ===

// Display hat 160 (waagrecht) * 128 Pixel (senkrecht)

//Pindefinitionen für die Verbindung des Displays
#define cs   10
#define dc   9
#define rst  8  

//Ein Display als Objekt definieren
TFT screen = TFT(cs, dc, rst);
//Adafruit_ST7735 screen = Adafruit_ST7735(cs, dc, rst);

//Hintergrundfarbe

int bgr = 230;
int bgg = 230;
int bgb = 230;

//Abstandsberechnungsoffset
int doffset = 0;

//=== Sensoren: ===

//Ansteuerung des Sensors
/*
   _________
  o|       |---Black--------|Gnd
   | GP2D02|---White--->|---|Pin 2 (note the interfacing diode)
  O|       |---Red----------|+5V
   |_______|---Yellow ------|Pin 7

*/

//Sensor 1
const int INPUT_DATA_PIN1 = 0;
const int OUTPUT_CLOCK_PIN1 = 1;

// Instanzerzeugung Sensor
GP2D02 sensor1(INPUT_DATA_PIN1,OUTPUT_CLOCK_PIN1);

//Sensor 2
const int INPUT_DATA_PIN2 = 2;
const int OUTPUT_CLOCK_PIN2 = 3;

// Instanzerzeugung Sensor
GP2D02 sensor2(INPUT_DATA_PIN2,OUTPUT_CLOCK_PIN2);

//Sensor 3
const int INPUT_DATA_PIN3 = 4;
const int OUTPUT_CLOCK_PIN3 = 5;

// Instanzerzeugung Sensor
GP2D02 sensor3(INPUT_DATA_PIN3,OUTPUT_CLOCK_PIN3);

// === Buttonvariablen für das Zurücksetzen des Abstandes ===

// Nummer des Pins zuweisen
const int buttonPin = 6;

int buttonState; // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

int reading;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  screen.begin();
  screen.background(bgr,bgg,bgb); 
  screen.noFill();
}

void loop() {
  // put your main code here, to run repeatedly:
  
  
  abstanderhalten();
  
  ebeneber(getd1(),getd2(),getd3());
 
  // read the state of the switch into a local variable:
  reading = digitalRead(buttonPin);
  
  // === Entprellter Schalter ===
  
  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
  // long enough since the last press to ignore any noise:  

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }
 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // Abstand auf 0 setzen, falls ButtonState auf LOW gezogen wird (durch internen Pullup bewirkt Druecken des Buttons ein LOW)
      if (buttonState == LOW) {
        doffset = getdis();
      }
    }
  }
 
  // === Ende entprellter Schalter ===

  drawcrosshair();
  
  //Punkt auf dem Fadenkreuz erstellen
  drawpoint();
  
  //Als Text den Abstand hinschreiben
  abstandschreiben();
  
  
  
  //Wartezeit von 50 ms, damit man noch halbwegs was mitbekommt
  delay(50);
  
  //Bildschirm leeren und resetten
  screen.background(bgr,bgg,bgb); 
 
}

Second file is Display

// === Displayfunktionen: ===

//Definition Mittelpunkt Crosshair
int xposch = 100;
int yposch = 64;

//Skalierungsfaktor Crosshair
int scalech = 10;

//Text Abstand

char text1[50] = "Der Abstand ist";
char text2[50]  = " mm.";
char text[100];

//Anzuzeigender Abstand
int danz = getdis() - doffset;

void drawcrosshair(){
  //Schwarze Linienfarbe
  screen.stroke(0,0,0);
    
  //inner Circle
  screen.circle(xposch,yposch,scalech);
  //outer Circle
  screen.circle(xposch,yposch,3* scalech);
  
  
  //waagrechte Linie
  screen.line(xposch-4*scalech,yposch,xposch+4*scalech,yposch);
  //senkrechte Linie
  screen.line(xposch,yposch-4*scalech,xposch,yposch+4*scalech);
  
}


//Schreibfunktion für den Text
void abstandschreiben(){
  screen.setTextSize(2);
  
  screen.text(text1,10,20);
  
 // text = (char[ ]) danz //+ text2;
  screen.text((char*) danz,10,50);
  screen.text(text2,100,50);
  
}

//Punkt auf dem Fadenkreuz setzen
void drawpoint(){
  
  //rot gefüllter Punkt
  screen.fill(255,0,0);
  
  //Die Doubles sind auf int runtergecastet, da Pixelwerte (wahrscheinlich) nur als int gehen
  screen.circle((int) (xposch + getn20()*4*scalech) ,(int) (yposch + getn21() * 4 *scalech), (int) (1.5 * scalech));
  
}

The third File is sensorcalc but I don't think that you need it it doesn't do anything with the display.

I do need it because need the functions from it like:
abstanderhalten(); and ebeneber(getd1(),getd2(),getd3());

Okay sure, here it is:

/// === Sensor auslesen und Werte berechnen ===

//Werte vom Sensor
byte ins1;
byte ins2;
byte ins3;

//Berechnete Rückgabewerte
double diss1;
double diss2;
double diss3;


//Normaleneinheitsvektor dreidimensinal
double n03[3];

//Normaleneinheitsvektor zweidimensional (für Darstellung im Fadenkreuz)
double n02[2];

//berechneter Abstand Wand-Bohrmaschine
byte dber;

//Skalarprodukt der beiden aufspannenden Vektoren
double skaluv;

/*Definition Sensorpositionen
Annahme: Sensoren messen immer den Abstand in Blickrichtung der Sensoren, nicht den kürzesten Abstand zur Wand. 
Dies führt dazu, dass die x,y-Positionen der Sensoren konstant sind, da keine Winkelverdrehung und somit eine Änderung der Abstände zueinander stattfindet

Die Abstände werden relativ zur Bohrachse angegeben, wobei die Bohrachse die x3-Achse einnimmt, die x1-Achse nach rechts zeigt und die x2-Achse nach unten zeigt.
Dies gilt, wenn man hinter der Bohrmaschine steht und auf die Wand schaut */

//Punkte 1,2 und 3
//x3-Koordinate wird als 0 vordefiniert (später mit Messwert ersetzt)
int P1[] = {100,0,0};
int P2[] = {-20,80,0};
int P3[] = {-66,-66,0};

void abstanderhalten(){
 //Sensor anwerfen zum Messen
 sensor1.refresh();
 sensor2.refresh();
 sensor3.refresh();
 
 // Daten auslesen
 ins1 = sensor1.read();
 ins2 = sensor2.read();
 ins3 = sensor3.read();
 
 /*Distanzberechnung über Abstand = A / (Messwert - B)
 
 Es wurde die Kurve im Datenblatt als Beispiel (http://pdf.datasheetcatalog.com/datasheet/Sharp/mXvryzu.pdf) genommen, hierbei wurden die Punkte 
 DEC | 220 | 150
 L   | 8   | 18
 
 benutzt um die Näherungsgleichung zu lösen und die Parameter A und B zu
 
 A = 1008 und B = 94 zu bestimmen
 
 */
 
 //Abstände negativ, da Koordinatensystem auf der Wand liegt und x3-Vektor in die Wand hinein zeigt
 diss1 = -(1008 / (ins1 - 94) * 10) ; //in mm
 diss2 = -(1008 / (ins2 - 94) * 10);  //in mm
 diss3 = -(1008 / (ins3 - 94) * 10);  //in mm
}


//Rückgabefunktionen, da man nicht mehr als eine Variable zurückgeben kann

double getd1(){
  return diss1; 
}

double getd2(){
  return diss2; 
}

double getd3(){
  return diss3; 
}



// === Berechnungsfunktionen ===

void ebeneber(double d1,double d2,double d3){
  
  P1[2] = d1;
  P2[2] = d2;
  P3[2] = d3;
  
  //Berechnung Skalarprodukt u*v
  skaluv = (P2[0]-P1[0]) * (P3[0] - P1[0]) + (P2[1]-P1[1]) * (P3[1] - P1[1]) + (P2[2]-P1[2]) * (P3[2] - P1[2]);
  
  //Berechnung einzelne Komponenten des Normalenvektors
  n03[0] = ( (P2[1] - P1[1]) * (P3[2] - P1[2]) - (P2[2] - P1[2]) * (P3[1] - P1[1]) ) / skaluv;
  n03[1] = ( (P2[2] - P1[2]) * (P3[0] - P1[0]) - (P2[0] - P1[0]) * (P3[2] - P1[2]) ) / skaluv;
  n03[2] = ( (P2[0] - P1[0]) * (P3[1] - P1[1]) - (P2[1] - P1[1]) * (P3[0] - P1[0]) ) / skaluv;
  
  //Skalarprodukt Stützvektor mit 
  dber = abs(P1[0]*n03[0] + P1[1]*n03[1] + P1[2]*n03[2]);
  
  //zweidimensionaler Normalenvektor berechnen
  n02[0] = n03[0] / sqrt(n03[0]*n03[0] + n03[1]*n03[1]);
  n02[1] = n03[1] / sqrt(n03[0]*n03[0] + n03[1]*n03[1]);
}

//Getter-Befehle

double getn30(){
  return n03[0];
}

double getn31(){
  return n03[1];
}

double getn32(){
  return n03[2];
}

double getn20(){
  return n02[0];
}

double getn21(){
  return n02[1];
}

int getdis(){
  return (int) dber;
}

Take out these:

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>

Do you still get any errors?

No, Compilation works fine!

Just some warnings, but I can take a look at them later on.

Thank you very much for your instant help!!

:slight_smile:

It's a bit confusing with these GFX libraries:

You have to have them installed but they are getting loaded by the TFT library :wink:

Yea, its a mess. The Robot_Control library also has the Adafruit_GFX.h and Adafruit_ST7735.h libraries, but the TFT library is already made from both of them.

Just another issue the Arduino Team needs to fix.