Newbie question about LCD code

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

playing around with a cheap 16x2 LCD, and most of it is working well, except the following bit of code:

CMPulse = 10.00;
sprintf(tmpString, "%f KM", (double) CMPulse);
lcd_puts(tmpString);

Results in "? KM" being displayed on the LCD. I have replaced CMPulse with a float directly in the sprintf and have the same result.

In the project options, I have added libm.a, and sprintf_flt.a.

Any ideas?

Richard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But the library that supports printf is not sprintf_flt.a but printf_flt.

In fact just find and edit this section in your Makefile:

#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

# If this is left blank, then it will use the Standard printf version.
#PRINTF_LIB = 
#PRINTF_LIB = $(PRINTF_LIB_MIN)
PRINTF_LIB = $(PRINTF_LIB_FLOAT)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is the above true when using sprintf as well?

I will give it a try as soon as I get home, thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes both printf and sprintf rely on the core vsprintf that is the main component of that lib

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK tried the above, with no luck. Although there is a makefile, it doesn't have any sections which resemble your changes.

I am using AVR Studio 4 at the moment

I have changed the options in the project menu, currently selected for linking is libm.a and libprintf_flt.a, and compiler options changed -Wall to -Wl,-u,vfprintf

I have searched for this on the forums, and none of the suggestions I have found seems to have helped so far.

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I ran into this issue today, and was able to resolve the problem after a bit of trial and error. I was able to get floating point numbers to work correctly after adding the flags to the correct section in AVR Studio.

"Custom Options"
[Linker Options]
-Wl
-u
vfprintf

"Libraries"
libm.a
libprintf_flt.a

Hope this helps.
Chris