Go Down

Topic: append a float 2 a string? (Read 4302 times) previous topic - next topic

DigitalJohnson

I'm using a one-wire temp sensor with the one-wire library(v2.0) and everything works fine. I'm trying to show the temp on a serial 4-dig LED display (sparkfun). The problem is I need to seperate the decimal point from the float variable the 1-wire library gives me. I tried to use the string library's .append to make a string out of the float, but I get:

error: call of overloaded 'append(float)' is ambiguous.

I have to send 4 bytes (1 for each digit) to the display, as the actual values for each digit or ASCII char values for the numbers. My display will print a blank for the dec.pt. or a negative sign.

Any suggestions on how to convert a float to a char string?

Thanks,
DJ
DigitalJohnson

drhex

#1
Jun 26, 2010, 01:50 pm Last Edit: Jun 26, 2010, 01:55 pm by drhex Reason: 1
Can you show the code that caused the compile error?
Do you want to display the decimal point?

This thread migt be worth reading: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1200716061

DigitalJohnson

I didn't save the code. I didn't put much time into it. I used the Dallas Temperature library and copied the single device example sketch and I used method 1 in the printTemperature() functionin of the example to scan for devices. Then I set up the led display's RX to the TX of serial1 on the arduino Mega. I used the standard serial port for debugging. The only changes I made to the example code were adding the string library, setup 'stringX' of length Y, and at the bottom of the printTemperature() function I added the following code:

stringX.append(sensors.getTempF(deviceAddress));

Thats where the error occured. I also wrote a small function to do some string manipulation and got no errors there. I believe the problem is that I'm trying to append a float to a char string with the string lib. I was hoping someone here had an easy solution for what I'm trying to do.

Thanks for any help,
DJ  
DigitalJohnson

AWOL

Quote
I didn't put much time into it

But you hope others will?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DigitalJohnson

Quote
But you hope others will?


No Sir, I apologize if it sounds that way. :-[ I love to learn. My question is a simple one (I think, I may be wrong. :-?). How can I get the string library to accept the float variable that the dallas library outputs? I'll keep reading until I find the answer. I thought the forum was a place for everyone to learn from each other. ;)

Always thankful for replies,
DJ
DigitalJohnson

DigitalJohnson

>> drhex <<

Thanks for the thread tip!  :) That is exactly what I was trying to do. If anyone else out there is looking for a easier way to convert a floating point to a string, goto the thread posted by drhex above.

Much Thanks!  :) :) :)
DJ
DigitalJohnson

Go Up