Concatenate Float w/ a String

Arrch:
I've always seen Arduino as a entry point to get people into the world of microcontrollers.

The Arduino also fits very well into the student / university niche. It's easy enough for a beginner to learn on, and it's powerful enough to build many different kinds of "teaching aids" (lab experiments).

I may do an Arduino project as a prototype, then have to build 16, 24 or more of the same thing to be used as teaching lab hardware. The project is (probably) too small to justify making a custom PC board and, besides, why re-invent the wheel? The Arduino board works out of the box.

As I've said before, I completely understand why the floating point code was left out. What is "wrong" is that this (very important) fact is not officially documented anywhere and there is no user friendly (i.e. in the IDE) way to enable or disable it.

Countless hours have been collectively wasted by people trying to do something that should certainly work, but strangely does not. It should at least be documented.

The user should have the choice to use floating point code at the expense of code size, or to not use it. IMHO.

PaulS:
Sure. But take a look at the Arduino-specific functions, like digitalRead() and analogRead(). What types do those functions return? What about millis()? micros()? Can you find a single Arduino-specific function that returns a float?

Well then why not get rid of the "float" and "double" datatypes? It could save another 500 bytes I'm certain!

After all, nobody uses floats, right?

Krupski:
As I've said before, I completely understand why the floating point code was left out. What is "wrong" is that this (very important) fact is not officially documented anywhere and there is no user friendly (i.e. in the IDE) way to enable or disable it.

Countless hours have been collectively wasted by people trying to do something that should certainly work, but strangely does not. It should at least be documented.

Well my experience was completely different: I tried using sprintf() for a float, got some undesirable results, googled it, which lead me to a thread on these forums informing me that sprintf() didn't work with floats. I then spent 2 minutes developing my single line "kludge".

... And more expensive. Not every project needs a $10 micro-controller, especially if I can spend ~$1 on an ATTiny and accomplish what I need to with a simple "kludge"

I understand the cost point here but that isnt the problem. Thats why I love arduino's compatibility features with several different micro-controllers. The point here is I spent the money on a mega why am I not allowed to use floats naturally without an ugly kludge or including some third party modifications?

It should be a documented step to enable, or like the very nice edit a checkbox. I would uncheck that box when working with tinys or unos.

it wouldn't make much sense to spend 10x the amount on the chip for additional software support that can be handled with a "kludge" like this

10x? Really? The mega cost me just under double the price of the uno. I'm not sure about the actual controller but if i was a large company and buying in bulk this wouldn't come close to 10x the cost. Again I don't see why I'm not allowed to make the decision to have floats.

Kludges are a problem. I expect a C++ programmer to be able to pickup an Arduino sketch and have a go. Suddenly they see some weird code which needs to be included either once(A function) or every time a float is used. This leads to backwards learning.

Sure. But take a look at the Arduino-specific functions, like digitalRead() and analogRead(). What types do those functions return? What about millis()? micros()? Can you find a single Arduino-specific function that returns a float?

Allow me to quote the arduino home page:

Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators.

How many sensors are you aware of that output floats? GPS,Accelerometers,Gyros, I even saw a geiger counter shield.

I get what you are saying, I guess the point here is. I want the option to enable them and disable them at will. Most of the time its disabled.

Something else from the main website:

Simple, clear programming environment - The Arduino programming environment is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well.

Well I want to as what i would consider myself to be( an advanced user) want take advantage of floats in sprintf and thanks to a third party I can. :slight_smile:

ahref:
without an ugly kludge or including some third party modifications?

You keep using the word "kludge", but I don't think that's really what is; you're just writing the code that the function would normally do for you; it's not that complicated. My workaround requires only a single extra line of code and 2-4 bytes of memory.

10x? Really? The mega cost me just under double the price of the uno. I'm not sure about the actual controller but if i was a large company and buying in bulk this wouldn't come close to 10x the cost.

Cost of an ATTiny84/85 - ~$1
Cost of an ATMega1280 - ~$10

You were talking about production, so I priced base on the microcontroller.

Kludges are a problem. I expect a C++ programmer to be able to pickup an Arduino sketch and have a go. Suddenly they see some weird code which needs to be included either once(A function) or every time a float is used. This leads to backwards learning.

How is it backwards learning? You aren't given the crutch, so you have to build it yourself. Learning math isn't just about learning how to use a calculator.

If were talking about a project that could do with a 1280 I don't know why we are comparing it to the price of a tiny with a lot less processing power that will probably fall short anyway. Regardless. Its still my choice to throw money around and have enough power to throw floats around. I think that solves the money problem.

Your Kludge is a kludge.

A kludge (or kluge) is a workaround, a quick-and-dirty solution, a clumsy, inelegant, difficult to extend, hard to maintain yet effective and quick solution to a problem, and a rough synonym to the terms "jury rig", "Jugaad" or "jerry rig".

which leads me to backwards learning, I mean if someone sees your kludge and they aren't aware of the lack of float support they will most likely come to your desk and ask you what is going on. Instead you could enable floating support because your platform obviously needs it if you are writing that code.

Without wanting to flog a dead horse here i'll make it brief, The option to enable floats should be a part of the arduino core. Do you have any arguments to just that sentence that make it not being an option logical?

ahref:
If were talking about a project that could do with a 1280 I don't know why we are comparing it to the price of a tiny with a lot less processing power that will probably fall short anyway.

Like it has in all my projects :roll_eyes:

Regardless. Its still my choice to throw money around and have enough power to throw floats around. I think that solves the money problem.

Well then, sticking to prototyping is ideal for you.

A kludge (or kluge) is a workaround, a quick-and-dirty solution, a clumsy, inelegant, difficult to extend, hard to maintain yet effective and quick solution to a problem, and a rough synonym to the terms "jury rig", "Jugaad" or "jerry rig".

Without saying "you should be able to already do this with sprintf()" (which makes it a workaround, not a kludge), explain how my workaround is inelegant, klumsy and difficult to extend?

which leads me to backwards learning, I mean if someone sees your kludge and they aren't aware of the lack of float support they will most likely come to your desk and ask you what is going on. Instead you could enable floating support because your platform obviously needs it if you are writing that code.

Then why not use a device that has an FPU? Hell, you could consider the entire floating point software suite for the Arduinos as a kludge.

Without wanting to flog a dead horse here i'll make it brief, The option to enable floats should be a part of the arduino core. Do you have any arguments to just that sentence that make it not being an option logical?

I tend to avoid doing floating point calculations in my projects, so I have no need to enable it. If enough people care about this lack of option and complain to the developers that it should be included, I'm not going to argue against it.

I tend to avoid doing floating point calculations in my projects, so I have no need to enable it. If enough people care about this lack of option and complain to the developers that it should be included, I'm not going to argue against it.

That is fair :). So let's get it as a valid option :D!

ahref:
It should be a documented step to enable, or like the very nice edit a checkbox. I would uncheck that box when working with tinys or unos.

Grab this file: https://github.com/krupski/arduino-1.0.3/blob/master/app/pde.jar

Backup your pde.jar file and replace it with this one. It adds a checkbox in Preferences to enable or disable floating point support (i.e. using %f).

It works with Arduino 1.0.0 to 1.0.3.

I did this the moment I saw it krup. Many thanks for the github link though. I find it more reliable than your site :slight_smile:

ahref:
I did this the moment I saw it krup. Many thanks for the github link though. I find it more reliable than your site :slight_smile:

Someone suggested that I place my mods on GitHub rather than a private server. I was reluctant because I didn't know how to use Git. But then I figured "everyone else uses it - so I may as well learn how too" and did it!

If you're interested, the code for the mod is in "Preferences.java" (the checkbox part) and "Compiler.java" (the conditional compiler options string part).

All in all it's only about 5 or 6 extra lines of code!

The checkbox selection is saved in "preferences.txt" as

build.floating_point=true/false

Hope you find the mod useful.

-- Roger