How do i use Adafruit ST7735 and Adafruit GFX libraries together?

Hi, i am all new to Particle Photon, and i am having issues using the Adafruit ST7735 and Adafruit GFX libraries together.

I have added the libraries from the Particle Web IDE libraries section, and they are after pressing include from the libraries section, included in the files like this:

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_GFX.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_ST7735.h>


void setup() {
}

void loop() {
}

However, these are the errors i am getting:

lib/Adafruit_GFX/Adafruit_GFX.cpp:420:0: multiple definition of "Adafruit_GFX::drawLine(short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:462:0: multiple definition of "Adafruit_GFX::drawRect(short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:470:0: multiple definition of "Adafruit_GFX::drawFastVLine(short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:476:0: multiple definition of "Adafruit_GFX::drawFastHLine(short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:482:0: multiple definition of "Adafruit_GFX::fillRect(short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:489:0: multiple definition of "Adafruit_GFX::fillScreen(unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:727:0: multiple definition of "Adafruit_GFX::invertDisplay(bool)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:298:0: multiple definition of "Adafruit_GFX::Adafruit_GFX(short, short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:298:0: multiple definition of "Adafruit_GFX::Adafruit_GFX(short, short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:311:0: multiple definition of "Adafruit_GFX::drawCircle(short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:345:0: multiple definition of "Adafruit_GFX::drawCircleHelper(short, short, short, unsigned char, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:388:0: multiple definition of "Adafruit_GFX::fillCircleHelper(short, short, short, unsigned char, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:381:0: multiple definition of "Adafruit_GFX::fillCircle(short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:495:0: multiple definition of "Adafruit_GFX::drawRoundRect(short, short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:510:0: multiple definition of "Adafruit_GFX::fillRoundRect(short, short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:522:0: multiple definition of "Adafruit_GFX::drawTriangle(short, short, short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:531:0: multiple definition of "Adafruit_GFX::fillTriangle(short, short, short, short, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:608:0: multiple definition of "Adafruit_GFX::drawBitmap(short, short, unsigned char const*, short, short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:641:0: multiple definition of "Adafruit_GFX::drawChar(short, short, unsigned char, unsigned short, unsigned short, unsigned char)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:621:0: multiple definition of "Adafruit_GFX::write(unsigned char)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:675:0: multiple definition of "Adafruit_GFX::setCursor(short, short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:680:0: multiple definition of "Adafruit_GFX::setTextSize(unsigned char)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:686:0: multiple definition of "Adafruit_GFX::setTextColor(unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:690:0: multiple definition of "Adafruit_GFX::setTextColor(unsigned short, unsigned short)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:695:0: multiple definition of "Adafruit_GFX::setTextWrap(bool)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:700:0: multiple definition of "Adafruit_GFX::getRotation()"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:703:0: multiple definition of "Adafruit_GFX::setRotation(unsigned char)"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:721:0: multiple definition of "Adafruit_GFX::width()"
error
lib/Adafruit_GFX/Adafruit_GFX.cpp:725:0: multiple definition of “Adafruit_GFX::height()”

I have tried downloading the libraries from GitHub and removing the duplicate definitions by myself, as that is what the errors say - but this only gave me more issues so i gave up on that.

Are there anything wrong with the libraries, or am i doing something wrong?

Thanks!

Try removing Adafruit_GFX library. I think the Adafruit_ST7735 lib brings its own copy (Adafruit_mfGFX) and isn’t guarded against multi inclusion.

1 Like

Im making a clock, and the screen flickers in a very ugly way because i redraw the entire background and text for every time my clock increments. But if i dont include the graphics library, then i for some reason cant call the getTextBounds() function, which i (according to this: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-gfx-graphics-library.pdf page 20), need to do in order update my ST7735’s text without flickering. I can also see on git that this function is available in the GFX lib.

Though when only including the Adafruit_ST7735 lib i get this:
‘class Adafruit_ST7735’ has no member named ‘getTextBounds’

I have also seen in other examples, though at Arduino, that they include both without problems. Like in this example in Arduino Studio:

Uten%20navn

Nevermind, i fixed it in a much more easy way:

//Hide last number
tft.setTextColor(ST7735_RED);
tft.setCursor(10, 10);
tft.print(oldNumber);

//Show new number
tft.setCursor(10, 10);
tft.setTextColor(ST7735_WHITE);
tft.print(str);
oldNumber = str;

There is also another way by providing the fore- and backcolor for your text, so you only need to print once.

tft.setTextColor(ST7735_WHITE, ST7735_RED);

Oh, neat! Thanks!