converting integers to char for GFX

Please help! I'm beating my head against a wall on something that should be so simple.
I'm trying to display some numbers on a TFT screen using drawChar();

It works perfectly fine if I plug in a static char in single quotes.

But when I try to pass an int to it doesn't work. See the 'below doesn't work' part.

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

#define TFT_CS 10
#define TFT_DC 9
#define TFT_RES 8

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

void setup() {
  Serial.begin( 115200 );
  tft.begin();
  tft.setRotation( 1 );
  tft.fillScreen( ILI9341_RED );
  
  // below works
  tft.drawChar( 190, 100, '7' , ILI9341_WHITE, ILI9341_BLACK, 5);

/* below doesn't work
  int number = 9;
  char c_number = number;
  tft.drawChar( 190, 100, c_number, ILI9341_WHITE, ILI9341_BLACK, 5);
  */
}

void loop() {

}

I've tried all kinds of complicated ways to convert an int to a char, including this:

but it doesn't work.

Can someone tell me an to pass a variable to drawChar() ?

If the integer really must be converted to a string (note lowercase s, not a String) then you can do it with the itoa() function.

Post what you tried that did not work.

Thanks for such a fast reply! I tried this and didn't work:

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

#define TFT_CS 10
#define TFT_DC 9
#define TFT_RES 8

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

void setup() {
  Serial.begin( 115200 );
  tft.begin();
  tft.setRotation( 1 );
  tft.fillScreen( ILI9341_RED );
  
  // below works
  tft.drawChar( 190, 100, '7' , ILI9341_WHITE, ILI9341_BLACK, 5);

/* below doesn't work
int a=1;
char b[1];
String str;
str=String(a);
str.toCharArray(b,1);
tft.drawChar( 190, 100, b, ILI9341_WHITE, ILI9341_BLACK, 5);
 */
}

void loop() {

}
  int theInt = 123;  //integer to be converted
  char buffer[10];  //char buffer to hold converted integer up to 9 digits plus terminator
  itoa(theInt, buffer, 10);  //convert using base 10 and put result in string named buffer
  tft.drawChar( 190, 100, buffer, ILI9341_WHITE, ILI9341_BLACK, 5);

Note that Strings were not used in this conversion

I tried your code, but changed the buffer size, since I only need to display 1 character 0-9. Did I do it right? I get an error:
invalid conversion from 'char*' to 'unsigned char' [-fpermissive]

int theInt = 6;  //integer to be converted
  char buffer[2];  //char buffer to hold converted integer up to 9 digits plus terminator
  itoa(theInt, buffer, 2);  //convert using base 10 and put result in string named buffer
  tft.drawChar( 190, 100, buffer, ILI9341_WHITE, ILI9341_BLACK, 5);

Which line are you getting the error on ?

If you only want to print single digits then try

 tft.drawChar( 190, 100, theInt + 48, ILI9341_WHITE, ILI9341_BLACK, 5);

I do not have the library or a TFT to try it on. Are there any examples with the library ?

I'll try that in just a bit, thanks! The library only has examples with static chars being displayed in quotes. But I did find this, from another thread. Seems to work at first test. I'll test some more

char c;
int q = 5;
c = q + '0'; // convert the number to a character corresponding to it
tft.drawChar( 190, 100, c, ILI9341_WHITE, ILI9341_BLACK, 5);

The + '0' is the same as + 48 (48 is the ASCII code for '0') so either should work

I have just found the manual for the library https://cdn-learn.adafruit.com/downloads/pdf/adafruit-gfx-graphics-library.pdf

If you want to print text to the screen then you can simply use the print function having set the position, size etc. This could be faster than using drawChar()

I will look into that.
Thank you for your quick replies, I really appreciate it.

Hopefully someone can benefit from the + '0' / 48 trick.