Go Down

### Topic: Display floating point temperature on 7-segment display (Read 3391 times)previous topic - next topic

##### Sep 20, 2013, 11:00 pm
I have temperature values from around 60 to 212 as floating point variables because I want one or two decimal point accuracy. These are to be displayed on Adafruit 7-segment displays. The documentation for these display devices is not very good, but I think I can figure out how to display one digit at a time and print a decimal point in front of the proper digit.
So, is there an easy way to pick off the four most significant digits of a floating point value, one at a time and detect which has the decimal point in front of it?  I have checked the Arduino Language page and do not see any obvious solutions there.

Since this seems to be something many others have probably done, I am hoping there is  best way to do it.

Thanks,

Barry

#### int2str

#1
##### Sep 20, 2013, 11:14 pm
Multiply the float by 100 and convert it to an integer.

Code: [Select]
`int intTemp = floatTemp * 100;`

This will turn 12.3456 into 1234.
Now you can display the digits onto the 7 segment display and simply enable the dot before the last two digits.

#### KeithRB

#2
##### Sep 20, 2013, 11:16 pm
Try dtostrf()
http://forum.arduino.cc/index.php?topic=85523.0

I used this for this exact thing, and simply did a search for the '.' and printed the digits on either side as needed.

#### Delta_G

#3
##### Sep 20, 2013, 11:19 pm
Take your float and convert it to an ascii string in a char array.  Declare another array for what you will display.

Loop through the first four(if no decimal at all) or five (four digits and a decimal) elements in the array.  Read through them one at a time and if they're digits add them to the display and if you hit a decimal point then deal with that separately.  For all the seven segments I have the decimal is after the number, so it would mean when you hit a decimal you have to go back to the last digit you displayed and turn on the decimal point.
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

#### JimEli

#4
##### Sep 20, 2013, 11:32 pm

Multiply the float by 100 and convert it to an integer.

Code: [Select]
`int intTemp = floatTemp * 100;`

This will turn 12.3456 into 1234.
Now you can display the digits onto the 7 segment display and simply enable the dot before the last two digits.

How about if the temperature is 100.1?

#### int2str

#5
##### Sep 20, 2013, 11:54 pm
How about if the temperature is 100.1?

Then the display will read "100.10".
The decimal point always being in the same spot makes it easier to read and it usually looks better as well.

Consistency....

Worst case you can always check the last digit and if it's 0, divide by 10 and move the decimal point. still think 2 decimal digits consistently  is preferred.

#6
##### Sep 21, 2013, 12:13 am
I can multiply by 10 when the temp is over 100 or multiply 100 when the temp is under 100 and end up with a four digit integer number and the location of the decimal point.  That's great!

Now, how do I pick off one digit at a time from this four digit integer number so I can write it to the proper location on the four digit display. I can imagine a brute force method(count the number of times I can subtract 1000 without going below zero for the first digit etc.), but is there an easy way?

Converting to a character array also sounds easy, but I have to figure out how the result can be written to this display. As I said in my post, the documentation is not good.

#### int2str

#7
##### Sep 21, 2013, 12:27 am
Now, how do I pick off one digit at a time from this four digit integer number so I can write it to the proper location on the four digit display.

Right-to-left:

Code: [Select]
`while (intTemp > 0){    byte digit = intTemp % 10;    // Write digit to display    intTemp /= 10;}`

#### Jimmy60

#8
##### Sep 21, 2013, 12:28 am
It's probably just me but I see no reason to display Fahrenheit temperatures to 1/100 of a degree accuracy.

Is the sensor even that accurate?

#### int2str

#9
##### Sep 21, 2013, 12:30 am
I'm sure there is a datasheet to go with it....

Is it any of these:

#10
##### Sep 21, 2013, 01:13 am
Actually I only need .1 degree accuracy as the temperature sensor is .5 accurate. But, I have four digits to display, so why not. This is ona production still and temperatures below 100f aren't very imortant anyway.

int2str, could you explain the code you are suggesting?  It looks elegant, but alas I'm not good enough to understand it. I do have the display at the link in your post, and believe me I have been trying to get meaningful documentation from them. It does not exist. Their web pages are a big easter egg hunt for information and there is no documentation that lists the commands (or whatever you call them) or their syntax for printing to the display. Instead, you go on to their forum and start asking questions.

barry

#11
##### Sep 21, 2013, 03:06 am
int2str, no need to reply, I figured out how your code works. Very clever!

Thanks,

Barry

Go Up

Please enter a valid email to subscribe