arduino newbie lcd variable

hello guys im new in arduino!

i wand to display in first line this -> volts = 2,5v

the "volts =" is text the 2,5 is varable and the "v" is also text

with codevision i set this as

float vol=2,5;

lcd_gotoxy(0, 1);
sprintf(lcd_buffer,"volts = %f v",vol );
lcd_puts(lcd_buffer);

i try this with arduino but dont work
float vol = 2.5;
lcd.setCursor(0, 1);
lcd.print("volts = %f",vol );

please someone send me the correct syntax because im new with arduino and im try to learn!!!

thanks

First of all, what kind of LCD do you have?

I've not heard of codevision but it seems to me that you are able to use sprintf in it.

You should use the same sprintf in arduino, which is C. There is no printf syntax in lcd.print. There is no printf anywhere. Arduino Dev board has no standard output device.

Also you won't see 2,5 you will see 2.5
C was invented in America, where people use a dot to separate digits before and after decimal "point".

It sounds like youre doing something very similar to what I was doing. I had to convert that float (double in my case) to a string that the LCD could understand first.

Did you already get it sorted out?

A couple of things:

The Arduino IDE uses the avr-gcc compiler.
Nomally, you should be able to simply write code very similar to your codevision code:

float vol=2,5;
lcd.setCursor(0, 1);
sprintf(lcd_buffer,"volts = %f v",vol );
lcd.print(lcd_buffer);

There is one small issue....
The avr-gcc tools has multiple versions of the xxprintf() library functions.
The default version, which is used by the IDE, does not support floating point.
Unfortunately, the IDE does not allow you to change the linker options to pull in the
other versions of the xxxprintf() functions.
Because of that, you will not be able to use sprintf() for floating point output.
(You can but then you have to abandon using the IDE and use your own makefiles)


The Arduino Print class, which is what is called when you do something like lcd.print()
does not support printf() style formatting.
The formatting provided by the Arduino Print class is very wimpy
and only supports simple strings and numbers.
(Most output formatting in C++ is no where near as simple and capable as the tried and true C xxprintf() routines)

So in order to do what you want using the standard Arduino Print class,
you have to something like:
(I'm assuming that you didn't want the space between the voltage and the "v" as in your codevision sample code)

float vol = 2.5;
lcd.setCursor(0, 1);
lcd.print("volts = ");
lcd.print(vol);
lcd.print('v');  // could also use the string "v" or " v" if you want the space

Unfortunately, it looks like the Print class doesn't have its own documentation,
so here is some additional information on the Print class that is available in the serial class.
Ignore the serial references, since the print function can be called from the lcd object.

And if you are curious how all this class stuff glues together:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240439279

--- bill

I was grappling with this same issue, what worked best for me was string concatenation.

I used:

float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 lcd.setCursor(0,0);
 String stringOne = " Temp F";
 String stringTwo = temperatureF + stringOne;
 lcd.print(stringTwo);

see: https://www.arduino.cc/en/Tutorial/StringAdditionOperator

Apparently it works best if you initialize the strings before concatenation