Int to ascii to lcd

I feel like such a moron. I know I’m missing something easy here. How do you print an ascii character to the lcd when the character is represented by an integer? Example: instead of printing 97 to the lcd, how do I get it to print “a”? Thanks for tolerating a really stupid question.

lcd.print((char)97);

or

lcd.write(97);

an LCD only prints ASCII characters

i usually generate a string with alphanumeric text and pass the string to the LCD routine to display a string

     char s [40];
     int   someVal = 123;

     sprintf (s, "someVal = %d", someVal);
     lcd.puts (s);

sprintf() is a very powerful (and large) function and often has features that go unused in a given sketch, which means it's often an h-bomb-to-kill-an-ant. Bob's solution will likely use significantly less memory resources.

econjack:
sprintf() is a very powerful (and large) function and often has features that go unused in a given sketch, which means it's often an h-bomb-to-kill-an-ant. Bob's solution will likely use significantly less memory resources.

if the program is small, what's the point of making it harder for the coder to save RAM. it's an opportunity to learn something

You can't use sprintf() to print to an lcd directly... sort of comparing apples to oranges here

You could also use the itoa function:

https://playground.arduino.cc/Code/PrintingNumbers/

aarg:
You can't use sprintf() to print to an lcd directly... sort of comparing apples to oranges here

you don't use sprintf to print to any device

use it to format a string and use a device specific function to print a string to that device, such as an lcd, oled, bluetooth, serial, ...

UKHeliBob gave the correct and simplest answer for the OPs question.

gcjr, the example code you posted in response #2 prints the integer value of the variable, which is not what the OP was asking for.


In term of using an xxprintf() type formatting function for sending formatted output the LCD, most of the 3rd party platforms include a printf() method in the Print class.
So on most 3rd party platforms you can "printf" directly to any Print class object. i.e.

lcd.printf(formatstring, ....);

This will work on Teensy, pic32, and esp platforms.

Even though there have been many requests to add a printf() method to the Arduino.cc platforms (AVR, DUE, etc)
The original/core Arduino.cc developers have violently opposed it so it has never been added to those platforms.
Believe it or not, memory is not the main issue sited.
They claim xxprintf() is too scary and complicated for Arduino users.

If you are using an Arduino board that requires using an Arduino.cc platform you can add printf() to the Print class yourself
Years ago, I did a write up on the Playground Printf page about how to add printf method to the Print class.
https://playground.arduino.cc/Main/Printf/

Alternatively you can create a Print class printf function, Pprintf() that can work without having to modify any Arduino IDE platform files.
It is just a few lines.
The idea is that it is like frpintf() but instead of passing in a FILE pointer you pass in a Print class object which indicates where the formatted output is to go.

Here is an example sketch that shows it and how to use it.

#define PPRINTF_BUFSIZE 128

void setup(void)
{
 Serial.begin(115200);
 Pprintf(Serial, "Pprintf...\n");
}
void loop(void)
{
 Pprintf(Serial, "Seconds up: %04ld\n", millis()/1000);
 delay(1000);
}

#ifndef PPRINTF_BUFSIZE
#define PPRINTF_BUFSIZE 64
#endif
size_t Pprintf(Print &outdev, const char *format, ...)
{
char buf[PPRINTF_BUFSIZE];
 va_list ap;
 va_start(ap, format);
 vsnprintf(buf, sizeof(buf), format, ap);
 va_end(ap);
 return(outdev.write(buf));
}

In terms of code size the xxprintf() code is about 1.8k on the AVR platforms.
In some projects that may be an issue.
But for projects that use more modern processors like the ESP parts which have megabytes of flash and 64k+ of RAM, those types of tight resource limitations are no longer an issue.

--- bill