ILI9225 library issue

Hi,

I'm using a tft ILI9225 wired with a Arduino pro mini.
I need to print a count number when a pushbutton is pressed.
The TFT_22_ILI9225 library has no tft.print capability or anything that
can print a counting number on the screen.

Is there any other way to do tft.print on the screen?
or
Is there any other library that works with ILI9225 beside TFT_22_ILI9225?

can someone help how to implement this?

Thanks for your help!

Hi,

You can try with GxTFT.

Download the library as zip-file, then add it using Library Manager "Add .ZIP Library...".

Start with the example "GxTFT_myTFTs_graphicstest.ino"

Select the pre-configured display header file by uncomment, comment the previous selection:

#include "myTFTs/my_2.0_TFT_INHAOS_LCD_2000_9225.h"

Save the example as starting point to add your code then.

GxTFT is not "Newbie friendly", but it can give you a starting point.

The ILI9225 specific code is taken from TFT_22_ILI9225. print() is available.

Jean-Marc

Oops, I forgot that the INHAOS_LCD_2000_9225 is special, as it uses a latched 8bit interface to the 16bit panel.

So you may need to use a different GxIO class, dependent on your display.

Please provide a link to your display if you need help. Be patient, as I am absent some time today.

As you use TFT_22_ILI9225, you most likely use SPI:

original myTFTs/my_2.0_TFT_INHAOS_LCD_2000_9225.h

// e.g. https://www.aliexpress.com/item/LCD-Development-Kit-9225-with-Mega-2560-2-0-TFT-LCD-Display-TFT-LCD-PCB-Adapter/32587170491.html

// this display uses 8 bit data bus but has a latch for 16 bit panel

#include "../GxIO/GxIO_MEGA_P8_MEGASHIELD_LS/GxIO_MEGA_P8_MEGASHIELD_LS.h"
#include "../GxCTRL/GxCTRL_ILI9225/GxCTRL_ILI9225.h" // 176x220
GxIO_Class io; // #define GxIO_Class is in the selected header file
GxCTRL_Class controller(io); // #define GxCTRL_Class is in the selected header file
TFT_Class tft(io, controller, 176, 220); // portrait 176x220
//TFT_Class tft(io, controller, 220, 1760); // landscape 176x220

version for SPI: (need to define RS/CD and RST)

#include "../GxIO/GxIO_SPI/GxIO_SPI.h"
#include "../GxCTRL/GxCTRL_ILI9225/GxCTRL_ILI9225.h" // 176x220
GxIO_Class io(SPI, SS, RS, RST);
GxCTRL_Class controller(io); // #define GxCTRL_Class is in the selected header file
TFT_Class tft(io, controller, 176, 220); // portrait 176x220
//TFT_Class tft(io, controller, 220, 1760); // landscape 176x220

TFT_22_ILI9225 has a drawPixel() method. So it would be easy to make it inherit from Adafruit_GFX.
Then you get all the Adafruit_GFX methods, including print().

I have created a clone and added Adafruit_GFX. Compiles ok, but untested.

Thank Zingg,

First I am going to try TFT_22_ILI9225. print() and see if I'm able to print the counter on the screen.

then if I'm unsuccessful I will give your library a try.

I used TFT_22_ILI9225.print(count) I got a response,

expected unqualified-id before '.' token

TFT_22_ILI9225.print() seems to be good idea.
because that was the only line of code I needed.

that's the link

https://www.aliexpress.com/item/2-2-inch-SPI-serial-port-176-220-ILI9225-drive-IC-support-Ardunio-UNO-Mega2560-C51/32806133802.html

Thanks for the link. Do I understand correctly that you have a compile error?

In this case you should post the error message "copy error message", then post it in code tags, symbol </>.

You can't use the class name directly, you have something like
TFT_22_ILI9225 myTFT(...);
then you use myTFT.print(count);

Check first with one of the examples and try to understand the example code.

The examples have an old-fashioned use of the constructor:

TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);

that constructs an instance and then copies that instance to the instance that will be used.

the normal use would be:

TFT_22_ILI9225 tft(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);

this is what trying to do

#include <TFT_22_ILI9225.h>
#include <SPI.h>

        #define TFT_RST 8
        #define TFT_RS  9
        #define TFT_CS  10            // SS
        #define TFT_SDI 11            // MOSI
        #define TFT_CLK 13            // SCK
        #define TFT_LED 3             // 0 if wired to +5V directly
        #define TFT_BRIGHTNESS        // Initial brightness of TFT backlight (optional)
        #define Buzzer           A0
        #define Val              293

const int PhotoPin_P   =  4;
int Q_count;
int Q_value = 0;
void setup {
     this is set up
}
void loop {
counter();
}
void counter() {

          Q_value = digitalRead(PhotoPin_Q);
      if (Q_value >=  Val) {
        digitalWrite(TFT_LED, HIGH);
        
          Q_count++;
          tft.setCursor(100,46);
    TFT_22_ILI9225 myTFT(Q_count);
     myTFT.print(Q_count);
      analogWrite(Buzzer, HIGH);
      tone(Buzzer, 300, 100);    

      Serial.print("counter: ");
      Serial.println(Q_count);
       }

can you show what correction I have to make to have the counter print on the screen.

No, I can't. I do not like to post code that I can't test. But you can try this (untested):

#include <TFT_22_ILI9225.h>
#include <SPI.h>

        #define TFT_RST 8
        #define TFT_RS  9
        #define TFT_CS  10            // SS
        #define TFT_SDI 11            // MOSI
        #define TFT_CLK 13            // SCK
        #define TFT_LED 3             // 0 if wired to +5V directly
        #define TFT_BRIGHTNESS 200       // Initial brightness of TFT backlight (optional) <<=====
        #define Buzzer           A0
        #define Val              293

const int PhotoPin_P   =  4;
int Q_count;
int Q_value = 0;

TFT_22_ILI9225 myTFT(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);


void setup {
     //this is set up
  myTFT.begin(); //   <<=====
}
void loop {
counter();
}
void counter() {

          Q_value = digitalRead(PhotoPin_Q);
      if (Q_value >=  Val) {
        digitalWrite(TFT_LED, HIGH);
        
          Q_count++;
          tft.setCursor(100,46);
     myTFT.print(Q_count);
      analogWrite(Buzzer, HIGH);
      tone(Buzzer, 300, 100);    

      Serial.print("counter: ");
      Serial.println(Q_count);
       }

the error was

exit status 1
'myTFT' was not declared in this scope

post the code and the complete error message.

If you want to use the TFT_22_ILI9225 library you just have to create the appropriate String.

        void drawText(uint16_t x, uint16_t y, String s, uint16_t color = COLOR_WHITE);

        /// Calculate 16-bit color from 8-bit Red-Green-Blue components
        /// @param    red red component, 0x00..0xff
        /// @param    green green component, 0x00..0xff
        /// @param    blue blue component, 0x00..0xff
        /// @return   16-bit color

If you want to print an expression, simply use String(expression)

Personally, I am happier with Adafruit_GFX style libraries.
Then you tft.setCursor(x, y); tft.print(expression);

Arduino and the String class "works" but seems more clunky than using C or C++ expressions.

Producing nicely formatted text is so much easier with C printf() or sprintf(buffer, format, args...) and printing the resultant buffer

David.

thanks for replies,

I'm trying to print a counting number when a button is pressed on the screen.
create a string won't work for a counting number after a button is pressed.

on the ILI9225 tft.setCursor(x,y) and tft.print(counting) doesn't work.

class TFT_22_ILI9225' has no member named 'setCursor' or print

Of course it does. With your library:

tft.drawText(x, y, String(counter), COLOR_RED);

You would only use setCursor() and print() with a GFX style library.

one other thing,
with ILI9225 is there any other library that works with that screen
beside TFT_22_ILI9225.h?
I haven't come across one yet.
maybe you guys will since you're library writing master.