Bug in Arduino 0021

Just upgraded from version 0018 to 0021 and found some very unexpected results!

Release notes for 0018 states that a “precision parameter for printing floats / doubles” was added. This is a really useful feature as it allows you to specify the number of decimal places of precision a float will be printed to.

It appears that version 0021 now interpretes the “precision” parameter as a “base” parameter - hence you get some very surprising values printed out.

Help does anyone know how to fix this?
Is it a bug or is this an intentional change?
Is the only way tofix this to go back to 0018 or is there some other work around that will allow me to specify the precision of printed floats?

Specifics, please.

What board? What OS? What code?

Paul,

The h/w is a Teensy 2.0 and my PC is running Windows XP, but I don't think that this is too relivant based on the following which is a cut and paste from the 0021 library reference that clearly states that the second parameter in a the print() function will be interpreted as the base:

print() Description Prints text to the LCD. Syntax lcd.print(data) lcd.print(data, BASE) Parameters lcd: a variable of type LiquidCrystal data: the data to print (char, byte, int, long, or string) BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).

So based on this library reference my code is behaving as this reference note would suggest. The issue that I have is that if I run the same code in version 0018 then this second parameter is interpreted as the number of decimal places that will be printed after the decimal point.

The "precision" parameter that was available under the 0018 print library was really useful and it has now been taken away from me.

The Teensy needs modifications to the standard Arduino IDE. I wonder if their following statement below from the Teensy site might require you to ask the manufacture if the Print statement is effected. Perhaps the Teensy IDE add-ons aren't compatible with Arduino Ver 21?

"While many types of sketches can run, Teensy is NOT an "Arduino clone" due to the substantial technical differences. The Teensy hardware and Teensyduino software add-on are NOT endorsed or supported by the Arduino developer team."

http://www.pjrc.com/teensy/teensyduino.html

The only thing that changed between 0018 and 021 was support for String was added. Whatever problem you're having was already in 0018 or has nothing to do with precision.

Please post a Sketch that illustrates the bug.

Here is an example that illustrates the problem:

float x=12.3456; lcd.begin(16, 1); lcd.print("x = "); lcd.setCursor(4, 0); lcd.print(x, 2);

If I run this code on Arduino V 0018 I get the following:

x = 12.34

This is no great surprise as this is what the ARDUINO V 0018 library reference suggest that I should get.

If I run the same code on Arduino V 0021 I get the following:

x = 1100

This although it is a different result is understandable if you read the ARDUINO library reference as the second parameter in the print command is now (according to the 0021 ARDUINO library reference) interpreted as a "base", and 1100 base 2 is equal to 12 base 10.

The issue here is the the meaning attributed to this second parameter in the print command has changed from "precision" to "base".

I don't see how this has anything to do with the Teensy hardware as it is the ARDUINO library reference that actually states that this new meaning is to be expected.

I can fully understand the difference in the two outputs based on the ARDUINO library reference fro V 0018 and V 0022 - the problem as I see it is that the meaning attributed to this second paramerter has been changed.

Additional note of clarifacation:

If I try serial.print(12.3456, 2);

I get consistant results for both V 0018 and V 0021

BUT when I try lcd.print(12.3456, 2);

I get different results for V 0018 and V 0021

This is not too surprising and the ARDUINO library reference for serial.print is consistant between V 0018 and V 0021.

BUT the ARDUINO library reference (and actual respose) is different for lcd.print if you check out the ARDUINO V 0018 reference and compare this to the ARDUINO V 0021 library reference.

P.S. I spotted a "typo" in my last comment - the first response should of read:

x = 12.35

(I.E. 12.3456 printed to 2 d.p.)

If I try serial.print(12.3456, 2);

I get consistant results for both V 0018 and V 0021

BUT when I try lcd.print(12.3456, 2);

I get different results for V 0018 and V 0021

Presumably, you meant Serial, not serial…

Both Serial and lcd (if it is an instance of LiquidCrystal) derive from Print. It is possible that the derived classes have overloaded print methods that conflict with the Print::print() overload that deals with float arguments.

Not knowing which classes you are really using makes it very difficult to help you. It is why we continually harp on people to post all of their code, not just snippets.