Max 7219 7-segments and a value with a decimal point
Jeff Haas
Posts: 421
in Propeller 1
Walter recently updated his DHT11/22 sensor object (http://obex.parallax.com/object/837) and I've been playing with it. Out of the box it shows temp and humidity on the PST.
Showing the temperature and humidity on an LCD is easy, I'm using this object for LCDs with a PCF8574 backpack:
http://obex.parallax.com/object/833
Replace the pst.str commands with lcd.str commands and It Just Works. (Thanks, JM!)
However, I also have one of those Max 7219 7-segment display sticks, and thought it would be interesting to show the temperature on it too. And here's where I'm stuck.
I can show numbers on the Max display that are generated by RCTime...
- Set registers to DECODE mode
- Extract individual digits of rctime value to a buffer
- Write the buffer to the display
But the DHT sensors return a temperature, which has a decimal in it - 68.5, etc. How do I handle extracting these digits and keeping track of the decimal? Is there an object I can check out?
Showing the temperature and humidity on an LCD is easy, I'm using this object for LCDs with a PCF8574 backpack:
http://obex.parallax.com/object/833
Replace the pst.str commands with lcd.str commands and It Just Works. (Thanks, JM!)
However, I also have one of those Max 7219 7-segment display sticks, and thought it would be interesting to show the temperature on it too. And here's where I'm stuck.
I can show numbers on the Max display that are generated by RCTime...
- Set registers to DECODE mode
- Extract individual digits of rctime value to a buffer
- Write the buffer to the display
But the DHT sensors return a temperature, which has a decimal in it - 68.5, etc. How do I handle extracting these digits and keeping track of the decimal? Is there an object I can check out?
Comments
If you assumed (as a zeroth approximation) that the string was always four characters TU.t (that is Tens, Units, Point, tenths) you could just subtract $30 from the first character to get the value for the tens digit, same thing for the second character for the units, same thing for the fourth character for the tenths. The decimal point goes with the units or tenths, depending on whether you have right hand or left hand decimal points.
Of course, that is an gross over-simplication because it doesn't treat the case of greater than 99.9 degrees or less than 10.0 degrees. Let alone that it could be negative.
Another approach would be to convert the floating point to integer tenths. Then you can use integer divide and modulo to extract the digits.
Finally, the Arduino guys have fiddled with the 7219 in more detail than I would have thought possible. There may be a specific driver for the 7219 over there (it would be in C of course).
And Chris, please post the code, I'm sure there's something I can get out of it.
might not help a lot, but here is it anyhow
Tachyon driver for MAX7219
Essentially I have a section that writes the various digits to my clock display. The decimal points for the minutes are wired to the colon LEDs between the hours and minutes. So they're always going to be on. So when I write out the minutes it looks like this:
ioByte contains the value I am displaying and when I want the decimal point on I just OR it with DecPnt, which is a constant:
You're essentially setting the high bit of the byte for that digit. Then it calls the routine that shifts the data to the MAX7219.
When you want to programmatically turn on the decimal point you can just do the OR when the right condition is met. For example, on mine if the ALM1 is set then the decimal point is turned on for that digit as shown below.
Here I am making sure there is no number, and that the decimal point only comes on if a1Status is equal to 1.
This thread reminded me about the 7219 driver so I got sidetracked and did it even though I didn't have hardware!
To interface the DHT21/22 sensor to the display in Tachyon could be as simple as:
#P4 DHT MAX7219 PRINT SPACE PRINT CON
Which would execute immediately reading the sensor (on pin 4) and display the temperature and humidity on the 7-segment display. Building fancier definitions takes less than a minute with instant results!
btw, decimal points are handled automatically when they are encountered in a character stream, so PRINT" 12.34" will produce a correct display.
I realize I may not have asked the right question. Here's the key method:
This displays the result of the DHT reading on both the PST and the Max7219 stick. For example, the PST will show 70.52, while the Max will show 04376. So there's some conversion of the FloatToString result that needs to happen to format things for the buffer sent to the Max stick.
I've also attached the entire project archive if the code above isn't enough info.
Of course, there's a little voice in the back of my head saying, "It works on an LCD, why are you doing this?!" Right now I'm ignoring it because this is interesting.
Like I always say, when is a good time? Considering that it is so easy to get it all running too.
However why are you using floating point??? All you need to do is to scale the reading and insert your decimal point as needed. If JM's driver is doing FP then change it. FP seems to me to be lazy programming style inherited from PC programming where FP is free but the Prop can't even multiply two integers without software. I've never ever in all my programming experience ever needed to use FP, just plain old scaled integers.
P.S. as to the voice in your head it's always good to know when to ignore it when it is trying to be sensible.
and directly moved to Tachyon and never regretted it.
Actually in reading the Tachyon kernel source code (since at that time there was almost no documentation - not like today with glossary, intoduction and encyclopedia of Tachyon all around and lot's of code as well) I learnt PASM as well.
So life is possible without SPIN and C ;-)
give Tachyon a try and have interactive fun
Markus
according to the DHT22 datasheet and checking your latest code (my Arduino visitor had a DHT11 which provides no decimals that I interfaced for him to Tachyon a few days ago ..)
I thought printing would be: to handle the integer / fraction part of the result and printing with decimal point.
Better might be a .DHT22
@Jeff - see? simple !
forums.parallax.com/discussion/comment/1371244/#Comment_1371244