Go Down

Topic: Text printing on a TFT with the GFX library (Read 611 times) previous topic - next topic


Just trying a simple example of text using a 1.8 inch TFT and using information from the adafruit-gfx-graphics-library.pdf.
However, it won't compile due to errors in the print statement. When I use tft.print I get the error message 'tft' was not declared in this scope.
What is missing here? I am right out of my depth in understanding of this issue.

Code: [Select]

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <SPI.h>

void setup() {
void setCursor(uint16_t x0, uint16_t y0);
void setTextColor(uint16_t color);
void setTextColor(uint16_t color, uint16_t backgroundcolor);
void setTextSize(uint8_t size);
void setTextWrap(boolean w);

print("Hello world");
print(0xDEADBEEF, HEX);

void loop() {



Jun 14, 2019, 03:32 pm Last Edit: Jun 14, 2019, 03:35 pm by floresta
I have not used that particular library but in general you will need a line something like this:
Adafruit_ST7735 tft = Adafruit_ST7735(. . .);

Also, to display your message you will then use something like this:
tft.print(. . .);


EDIT:  Your other statements will also have to start with 'tft.' to look like this:
tft.setTextColor(. . .);



Almost every library comes with examples. If you start with an example, or have at least a look at it, it should be easy to get started.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.


You can port GFX programs very easily.   They all use the same graphics and text methods.
Drawing a circle or writing text is straightforward.

You just change the constructor to suit your hardware.
Sometimes the hardware-specific methods vary.   e.g. tft.begin() or tft.init() or tft.begin(ID)

Always start with the examples that come with your library.    Run each example.   Ask if you have a problem ( quoting which example )

If you find a sketch written for another GFX library,   just ask.
The geography may be for 240x320.   You have to change a few x,y coordinates and possibly shorter text sentences.



Just did a quick check using tft.begin() and tft.init() but still got the message:
gfxCompileTry:12: error: 'tft' was not declared in this scope.
I also used tft.print etc rather than just print. Maybe adafruit could try to help novices like me a bit more in their information.

I was hoping for a quick fix but will have to spend much more time going through examples to get a much greater understanding of the process.

Thanks to all who provided help on this subject.


open the IDE.

click on the File (top left)



Thanks fnb...

I'm well aware of that.
However, the best examples appear to be in the Adafruit_ST7735 library and I have got to a stage where I can compile with no errors and successfully upload my trial sketch. No image as yet on the screen but hopefully I will get there eventually.

Go Up