Is it possible to use the printf command to print text to a graphical LCD? I will be using the ks0108 library.
Yes you can!
If you use the latest library (glcd v3 beta).
Use the latest glcd v3 library instead of the older ks0108 library
as it has many improvements including printf support.
I totally detest the print class functions so
I included real printf() support in the glcd library.
It is documented - see the included HTML documentation
(click on glcd/doc/GLCDref.htm in the library)
It is part of the gText class.
So you can do things like:
It is just that simple.
The glcd library also supports user definable scrollable text areas so text
will automatically wrap and scoll. The direction of scrolling is
configurable as well.
If you create custom text areas, you can then have portions of
the display scroll independently while other areas of the display remain
So you could say create a text area that is the bottom half of the display
and then output text to it while the top half remains in place.
You will see this behavior in the demo sketch.
What isn't in the demo sketch is the use of the Printf() function.
But to use it all you have to do is use Printf instead of print.
So when you see things like
GLCD.print("blah") or textArea.print("blah") you can also use
GLCD.Printf("blah") or textArea.Printf("blah")
It calls the standard library printf functions so all formatting types
That said, by default floating point is not supported.
(This is documented in the glcd documentation)
You have to link against another library to get floating point support
and the IDE does not allow you to set linker options so you are kind
of SOA on floating support in the library.
But you can do format widths so things like printing a 4 digit number
that is filled with zeros, i.e like a counter, is as easy as:
I will say that if you are concerned about code space,
the printf support is 1.8k and if you use the printf support
try to avoid using the print class formatting routines so you
can save the space of those routines.
i.e. pick one method of formatting and stick with it.
I'm about to release an update to the glcd library and will be including an
example sketch that uses the printf functionality as well as some other
But yes printf support is built into the glcd v3 beta that has been
available for about 6 months now.