TFT 2.2'' SPI -> tft.setCursor() doesnt seem to have any effect! [SOLVED]

Hi all!

Ok.. this is silly and the answer might be just trivial but I ve spent hours and cant get it to work

I am usign one of those cheap TFT SPI connected screen just like this Cheap TFT 2.2 Inch Display on Arduino (ILI9340C or ILI9341) : 3 Steps - Instructables

with the adafuit Adafruit_ILI9341_AS TFT library

What I cant understand is why the following code prints the "Hello" always in the same place on screen (first line) no matter what the parameters inside of tft.setCursor () are;

void loop(){
      
      tft.setTextSize(2);
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_GREEN);
      tft.setCursor (4,5);
      tft.print("Hello");
      delay(10000);
}

with the adafuit Adafruit_ILI9341_AS TFT library

Please use the proper Adafruit library i.e. install Adafruit_ILI9341 via the IDE Library Manager

Run the library examples. Search the code for tft.setCursor() statements. Report any that "don't work"

David.

Please use the proper Adafruit library i.e. install Adafruit_ILI9341 via the IDE Library Manager

Thanks for your reply.

Trying the Adafruit library from the IDE Lib Manager was my first attempt.
However, I have faced a compiler complain when I tried to use non standard PIN assignments for the

Adafruit_ILI9341 tft = Adafruit_ILI9341(cs, dc, rst);

The compiler says :

no matching function for call to 'Adafruit_ILI9341::Adafruit_ILI9341(int, int, int)'

if the pin parameters are removed, it compiles just fine

The included examples have no parameters and obviously use the default. In my case however I need to define non stanrd pins for cs,dc and rst.

Please post your memory and library usage lines from a build. e.g. virgin example for a Uno target:

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\SPI 
Using library Adafruit_GFX_Library at version 1.10.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Adafruit_ILI9341 at version 1.5.6 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_ILI9341 
Using library Adafruit_BusIO at version 1.6.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\Wire 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_408375/graphicstest.ino.elf"
Sketch uses 18626 bytes (57%) of program storage space. Maximum is 32256 bytes.
Global variables use 722 bytes (35%) of dynamic memory, leaving 1326 bytes for local variables. Maximum is 2048 bytes.

and with the full-fat hardware constructor Adafruit_ILI9341 tft = Adafruit_ILI9341(10, 9, 8 );

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\SPI 
Using library Adafruit_GFX_Library at version 1.10.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Adafruit_ILI9341 at version 1.5.6 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_ILI9341 
Using library Adafruit_BusIO at version 1.6.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.13\hardware\arduino\avr\libraries\Wire 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_408375/graphicstest.ino.elf"
Sketch uses 18626 bytes (57%) of program storage space. Maximum is 32256 bytes.
Global variables use 722 bytes (35%) of dynamic memory, leaving 1326 bytes for local variables. Maximum is 2048 bytes.

i.e. exactly the same successful build.

You have many posts to your name. Please post links to your hardware and post your library version numbers.

Yes, occasionally there are problems with new boards or with new library Releases.
If we upgrade/downgrade to your library versions we can replicate your problem.

David.

OK… here we go.

I had to attach text files as the length of the files exceeds the maximum.

“Blink” file below is the verbose output from a minimal blink example
complile output.txt is the failed compile case in question .
The sketch taken from one of the library’s examples modified with full constructor.
That is the original example only had a minimal constructor and I modified it a below :

 Adafruit_ILI9341 tft = Adafruit_ILI9341( TFT_DC, TFT_CS, TFT_RST );

NOTE: I am using MightyCore for 1284p micro.

compile output.txt (24.6 KB)

Βlink output.txt (6.37 KB)

Your Arduino library installation looks a nightmare !!

Multiple libraries were found for "Adafruit_GFX.h"
 Used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_303465
 Not used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_879772
 Not used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_213611
 Not used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_185327
 Not used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_519980
 Not used: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_803838
...
Using library arduino_303465 at version 1.8.4 in folder: D:\Dropbox\MCU\Controller_Firmware\libraries\arduino_303465 
...

So it is very different to my

Using library Adafruit_GFX_Library at version 1.10.4 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library

I suggest that you straighten up your libraries first. e.g. leave IDE. Delete the multiple copies. start IDE. Install properly via the IDE library manager.

I see that you are using a non-standard board: ARDUINO_AVR_ATmega1284 via MightyCore
This should work 100% with the Adafruit examples.

David.

How do you propose its best to sort out the libraries?

I think the problem happened because i keep libraries on dropbox so that I can access them from another location as well.

Uninstall the IDE and re-install it?

Yes I am using a home-made PCB with 1284p tqfp44 chip

God gave you the IDE Library Manager.
Use it to install on each PC. In any country. In any world.

Personally, I would look at your dropbox and note each library name. e.g. Adafruit_GFX.h will be under those anonymous sounding folders.

Check which libraries are available via the Manager and which are not.
Leave IDE. Delete every directory that is Library Manager supported. Start IDE. Install properly.

David.

OK.. will do.

God gave you the IDE Library Manager.

Thank God for that! :slight_smile:

God invented Shields and the IDE Library Manager.

Compare that to the previous world of non-compatible dev boards, random code on the Internet, ...

With known hardware connections, routine provision of library examples the Arduino has had a massive impact on the world. Almost any new hardware chip, board, ... has Arduino examples from the Manufacturer.

David.

Yes I agree on the significance and impact of standardised approcah.
I was only joking before!

Not all libraries are available through he lib manager though.

eg, now having deleted everything, I had to manually add clickEncoder.h via a zip file

ok back to business with clean lib setup now.

The problem appears to persist with tft.setCursor() not working...

Will try to replicate with a basic sketch and post again...

Yes. Some libraries are only available via ZIP

It should mean that examples will work out of the box now.

setCursor() is a GFX method. Adafruit_ILI9341 inherits from Adafruit_GFX

Hi again…

Unfortunately nothing has changed. tft.setCursor() seems to have no effect on he text position.

No matter what parameters I enter on the tft.setCursor ( ) below, text appears at the beginning of the first line on the screen!

/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 13
#define TFT_CS 12
#define TFT_RST 19

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC,TFT_RST);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 
  digitalWrite(15,HIGH);
  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
 

  tft.fillScreen(ILI9341_BLACK);
  yield();
  tft.setTextSize(2);  
  tft.setTextColor(ILI9341_YELLOW);
  tft.setCursor(10, 20);               // <--------- Changing this has no effect on the text position on screen!
 
  tft.println("Hello World!");
  Serial.println(F("Done!"));
  
}

void loop(){}

compile output.txt (18.3 KB)

Edit: Problem solved!

Everything was fine from the beginning. I just hadn't realised that the setcursor() parameters are pixels coordinates and not actual character location like it on an LCD screen!

Thanks very much for your help and sorry for taking your time!
Karma points added!

This topic was automatically closed after 120 days. New replies are no longer allowed.