Floats to int on lcd 4x20

Hello.
I have a problem with my project. Its a bike computer with kp. Watt. Cadence, kcal. so far.. I want the values without decimals on the lcd. I try to convert to int, works well but the value "flipping" from 100 rpm to 780rpm for a sec than back to real. It never happend with presentation in float on lcd

Next problem is I want a second "tachometer" connected digital input 2 and rpm to pin 3 . The rpm works well with attachinterupt. But nothing happend with the other one. Can i use two at the same time? I use sensor module fc03 and arduino uno.

Best regards björn

100 rpm sounds like 12 KPH with 26 inch wheels.
780 rpm is 97 KPH.

I have a Cateye Mity. It seems to do everything that I want.

If I were to make a home made one, I probably would not care about battery life.
You receive an interrupt for each revolution of your front wheel.
Calculate speed, distance, ...
You probably display running averages rather than instant values.

I have never achieved 97KPH on a mountain bike. I would need fresh trousers.

David.

Oh I forget to write its a testbike like wattbikes in the basement. One sensor for cadence and one on the flywheel i want to read trip and kmh. Cadence value is correct but sometimes it flipping. Only when i covert to int from float. I use ant+ sensors with the phone at the same time. This project is for watt calculating .Regards björn

I try to convert to int, works well but the value "flipping" from 100 rpm to 780rpm for a sec than back to real

Are you certain it is not 78 rpm with the trailing 0 left from the previous print? How are you doing cursor management and clearing of spaces to handle both 2 and 3 digit numbers?

Yeah i think you have right. It working now :slight_smile: thanks. Regards björn

I am having a similar issue running analog back to the LCD.
I am using a line to print blank spaces after each cycle of code but it still keeps showing white boxes at the end of my number.
How did you get it to show just the digits?

I just write out "spaces" on the lcd before every time the calculated value shuld be present on lcd.
only lcd.setCursor( 0 , 0);
lcd.print(" ");

the problem disappear. maybe there is some better ways. but I'm a newbie :slight_smile:

Regards Björn

If you are printing floats, the dtostrf() function can do all the formatting for you.
If you are printing integers, I suggest that you use sprintf() to do the formatting.

Then you simply set the cursor to X, Y and print the formatted result whenever required.

e.g. char * dtostrf( double __val, signed char __width, unsigned char __prec, char * __s);

    char buf[20];      //somewhere to put the result
    dtostrf(123.456, 7, 1, buf);
    lcd.print(buf);     //prints "  123.5"
    sprintf(buf, "%04X", 0x456);
    lcd.print(buf);     //prints "0456"

Formatting anything in C++ is painful. I am not sure how well Arduino implements the stream formatting features.

David.

Excel88bjrn:
I just write out "spaces" on the lcd before every time the calculated value shuld be present on lcd.
only lcd.setCursor( 0 , 0);
lcd.print(" ");

the problem disappear. maybe there is some better ways. but I'm a newbie :slight_smile:

Regards Björn

sprintf is your friend.

    char buf[20];

    int n = 123;
    lcd.setCursor(0, 0);
    sprintf(buf, "%04d", n);
    lcd.print(buf); // should print "0123"

    delay(1000);

    n = 45; // trying a different number this time
    lcd.setCursor(0, 0);
    sprintf(buf, "%04d", n);
    lcd.print(buf); // should print "0045"

    delay(1000);

    n = 6789; // trying one more number
    lcd.setCursor(0, 0);
    sprintf(buf, "%04d", n);
    lcd.print(buf); // should print "6789"

    delay(1000);

I would look at using the PrintEx library vs using sprintf().
It will add a printf() method to the lcd library class so you don't have to mess around using sprintf() and a separate buffer.
It also supports floats which by default sprintf() on the AVR does not.

i.e. once you create the proper lcd wrapping object, you will be able to do this:

lcd.printf("%04d", value);

--- bill