Serial LCD and floats

Hello,
I use a serial LCD from sparkfun with original library, but i can't print float numbers on that SERIAL LCD.
Anyone know other library or a solution for my problem?

Regards,
Leo

What lcd, what library are you currently using?

I try SparkFunSerLCD.h and SparkFunSerLCD.h with the same results.
Any ideas?

Again, What LCD are you using? (sparkfun makes several serial lcds) , and what library are you using?

Can you post the code you are using that is not working?

--- bill

Sorry i-m ambigous.
So, the LCD is this: Serial Enabled 16x2 LCD - Black on Green 5V - LCD-09393 - SparkFun Electronics
The library is in attach.
The code i used is:
float x=2.34566;
lcd.print(1, 1, x, 5);//x is float number and 5 is byte precision.
I followed this: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271823354
but this library still not support float numbers.

Any sugestion?

SparkFunSerLCD.cpp (3.46 KB)

You could try this (It should work, though I haven't tested it):

float x=2.34566;
int exponent = (int)x;
x -= exponent;
if (x < 0){
  x *= -1.0; //Ensure it is positive (the sign is kept in the exponent already)
}
for (int precision = 0; precision < 5; precision++){
  x *= 10.0;
}
char string[13] = {0}; //Enough room for an integer exponent (including sign), a decimal point, 5 characters of decimal and a null.
sprintf(string,"%d.%05ld",exponent,(unsigned long)x);
lcd.print(1, 1, string);

thx for reply, but your code not working.

Any ideas?

Can you post your complete sketch? Little snippets don't really help anyone.

I can't see anything in the library code you posted that has a version of lcd.print() that takes both cursor position and output parameters. There is an at() shortcut that does that though, so something like

float x=2.34566;
lcd.at(1, 1, x, 5);

might work.

THis is the code:
#include <SoftwareSerial.h>
#include <SparkFunSerLCD.h>
SparkFunSerLCD led(7,2,16); // desired pin, rows, cols);

int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// declaratii pentru partea de masurare tensiune
float vout = 0.0;
float vin = 0.0;
float vout2 = 0.0;
float vin2 = 0.0;
float vout3 = 0.0;
float vin3 = 0.0;
float curent = 0.0;
float putere = 0.0;
int analogInput = 1;
int analogInputa = 2;
int analogInputb = 3;
float R1 = 48500.0; // !! rezistenta R1 !!
float R2 = 4600.0; // !! rezistenta R2 !!
int value = 0;
int valoare = 0;
int valoareb = 0;

void rpm_fun()
{
//Each rotation, this interrupt function is run twice, so take that into consideration for
//calculating RPM
//Update count
rpmcount++;
}

void setup()
{
pinMode(analogInput, INPUT); //aici preiau prima tensiune
Serial.begin(9600);
led.setup();
delay(1000);
led.at(1,1,"RPM: ");
led.at(2,1,"U1: ");

//Interrupt 0 is digital pin 2, so that is where the IR detector is connected
//Triggers on FALLING (change from HIGH to LOW)
attachInterrupt(0, rpm_fun, FALLING);

//Turn on IR LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);

rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
turatie();
delay(1000);
tensiuni();
}
void turatie()
{
//Update RPM every second
//delay(1000);
//Don't process interrupts during calculations
detachInterrupt(2);
//Note that this would be 60*1000/(millis() - timeold)rpmcount if the interrupt
//happened once per revolution instead of twice. Other multiples could be used
//for multi-bladed propellers or fans
rpm = 8.57
1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;

//Print out result to lcd and serial
Serial.print ("RPM:");
Serial.print(rpm);
Serial.print (" | ");
led.at(1,6," ");
led.at(1,6,rpm);

//Restart the interrupt processing
attachInterrupt(2, rpm_fun, FALLING);
}
void tensiuni(){
// read the value on analog input
value = analogRead(analogInput);
valoare = analogRead(analogInputa);
valoareb = analogRead(analogInputb);
//Serial.print("value=");
//Serial.println(value);

if (value >= 1023) {
Serial.println("TENSIUNE MAXIMA!!");
return;
}
else if (value <= 0) {
Serial.println("TENSIUNE MINIMA!!");
return;
}
// print result over the serial port
vout = (value * 5.0) / 1024.0;
vout2 = (valoare * 5.0) / 1024.0;
vout3 = (valoareb * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
vin2 = vout2 / (R2/(R1+R2));
vin3 = vout3 / (R2/(R1+R2));
curent = (vin - vin2)/1.2;
putere = vin3*curent;
//Serial.print("vout=");
//Serial.println(vout);
Serial.print("Ugen=");
Serial.print(vin3);
Serial.print("V | ");
Serial.print("U1=");
Serial.print(vin);
Serial.print("V | ");
Serial.print("U2=");
Serial.print(vin2);
Serial.print("V | ");
Serial.print("I=");
Serial.print(curent);
Serial.print("A | ");
Serial.print("P=");
Serial.print(putere);
Serial.println("W ");
led.at(2,5," ");
led.at(2,5,vin, 4); //THIS CAN't BE DISPLAYED
}
in attach is the library.

If sommeone can help!

SparkSoftLCD.cpp (5.68 KB)

SparkSoftLCD.h (1.93 KB)

Have you tried any of the other serial lcd libraries here - Arduino Playground - LCD ?

Any library from Arduino Playground - LCD can't support floats.... and maybe this is a big problem for sparkfun LCDs.

Any sugestions?

Based on the code you posted, try this:

float x=2.34566;
int exponent = (int)x;
x -= exponent;
if (x < 0){
  x *= -1.0; //Ensure it is positive (the sign is kept in the exponent already)
}
for (int precision = 0; precision < 5; precision++){
  x *= 10.0;
}
char string[13] = {0}; //Enough room for an integer exponent (including sign), a decimal point, 5 characters of decimal and a null.
sprintf(string,"%d.%05ld",exponent,(unsigned long)x);
lcd.at(1, 1, string);

Error compiling.
Not working

TCWORLD:
Based on the code you posted, try this:

float x=2.34566;

int exponent = (int)x;
x -= exponent;
if (x < 0){
  x *= -1.0; //Ensure it is positive (the sign is kept in the exponent already)
}
for (int precision = 0; precision < 5; precision++){
  x *= 10.0;
}
char string[13] = {0}; //Enough room for an integer exponent (including sign), a decimal point, 5 characters of decimal and a null.
sprintf(string,"%d.%05ld",exponent,(unsigned long)x);
lcd.at(1, 1, string);

Error compiling. not working

What exactly is the error? It works fine for me (all be it with Serial.print() not the LCD).

EDIT:
Ahh, you called it 'led' not 'lcd'. Change the last line to be led.at(1,1,string); and it should work.

You can't use xxprintf() functions with floating point on Arduino because in order to get floating support,
requires linking with a floating point version of the xxxprintf() libraries. In order to do that, you have change the
linker options. And.... the Arduino Team did not build in any way to set the linker options into the IDE.
So you are out of luck with that.

I'm still not clear on exactly what library code you are using. (I need to see all of it)
Your post (reply #4) references an old forum thread which in turn links to a library "SparkSoftLCD" but that is different from
the library .cpp file you attached which I assume is from SparkFunSerLCD library ?

Also that .cpp file attached is not all the files in that library. Where is the .h file?

I need to see exactly what library you are using - ALL of the files in order to help you fix any issues
as all these libraries are different and don't correspond to the LCD 1.0 API that the stock LiquidCrystal library uses.

--- bill

I really don't know with error, becuase my arduino IDE says ERROR COMPILING.
I try to split this float in two INT values and print on LCD like this: "val1"+,+"val2".

leonte:
I really don't know with error, becuase my arduino IDE says ERROR COMPILING.
I try to split this float in two INT values and print on LCD like this: "val1"+,+"val2".

Don't waste time guessing/trying things.
Post the library you are using and lets use it correctly or fix it.

--- bill

I bet it doesn't say 'ERROR COMPILING'. I bet it actually tells you what the error is if you are prepared to read it. If you don't understand it, post what it says so we can help.

TCWORLD:
I bet it doesn't say 'ERROR COMPILING'. I bet it actually tells you what the error is if you are prepared to read it. If you don't understand it, post what it says so we can help.

Hi,
trust me. I-m not crazy to say bad words about my project.
The message from compiller is: ERROR COMPILING.
thx!