Hello,
So, i think my problem is a simple one but my skills are limited.
Simply put the Rainbow HAT pressure is measured in Millibars so a typical reading will be something like
97951.6671688
Clearly this won’t display on the Rainbow HAT 4 DIGIT Alpha-numerical display so I simply convert the pressure reading as such:
p = rh.weather.pressure() / 10
Now this simply turns the number above to something like this
9795.1667168
Ideally, i want to display the number 9795 on the Alpha-numerical display with no decimal points as this would be the correct millibar reading.
Hope this makes sense? Thanks for any help offered.
Cheers
Scott
What I do on my sense hat is:
p = sense.get_pressure()
p = round(p)
That takes everything after the decimal point away and just displays a whole number. That’s in Python. I do the same for temperature and humidity that I display as a scrolling message on the Sense hat LED matrix.
Thanks alphanumeric
Almost, used the round command but it just turns the above number into 9795.0 and given that the display only has 4 characters, it fails to display. I think the problem is that the HAT cant display integers and only floating point numbers.
Perhaps there is another way?
Scott
You could do p = int(rh.weather.pressure() / 10)
. That will convert the floating point number into an integer (whole number).
1 Like
Thanks Sandy, I’m still learning so appreciate your help.
No probs. I think all programmers are still learning! Never stop. :-)
1 Like
Hi Sandy,
So we manage to convert it to an integer but cant display it on the Rainbow HAT
As far as I am aware there are only 2 display options for the alpha numeric display
rh.display.print_float
rh.risplay.print_str
Neither work and the latter comes up with an iteration error.
I’m really stumped here? Any ideas?
Cheers
Scott
Ps. Here is the full code
import signal
import time
import rainbowhat as rh
t = round(rh.weather.temperature())
p = int(rh.weather.pressure() / 100)
@rh.touch.A.press()
def touch_a(channel):
print("Temperature"),(t)
rh.lights.rgb(1,0,0)
rh.display.clear()
rh.display.print_float(t)
rh.display.show()
time.sleep(0.5)
@rh.touch.B.press()
def touch_b(channel):
print("Pressure"),(p)
rh.lights.rgb(0,1,0)
rh.display.clear()
rh.display.print_float(p)
rh.display.show()
time.sleep(0.5)
@rh.touch.release()
def release(channel):
rh.lights.rgb(0,0,0)
rh.display.clear()
rh.display.show()
signal.pause() # Pause the main thread so it doesn't exit```
Hello all,
If anybody is interested i solved my problem as follows:
rh.display.print_float(pressure, decimal_digits=0, justify_right=True)
The answer lay in the function decimal_digits. I found this by looking at the 4 letter Phat functions and assumed as it was very similar it might work, it did!
I would add that I think the Github needs a function reference section (like most other pieces of Pimoroni hardware have) for the Rainbow HAT, is it just me or is it missing?
Thanks
Scott
Here’s the documentation for Rainbow HAT: http://docs.pimoroni.com/rainbowhat/#
You can find docs for most of our boards at: http://docs.pimoroni.com
Thanks Sandy, the answer was there all the time. I think when you read the README.MD files on Github there is a link to the function reference section missing.
Cheers for the heads up
Scott