# Convert Barometric Pressure to Display on Rainbow HAT?

**URL:** <https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742>\
**Category:** Support\
**Created:** [December 29, 2017, 11:06am UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742 "2017-12-29T11:06:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 29, 2017, 11:06am UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/1 "2017-12-29T11:06:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [December 29, 2017, 12:41pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/2 "2017-12-29T12:41:48Z")

</div>

What I do on my sense hat is:

```auto
    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.

---

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 29, 2017, 12:57pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/3 "2017-12-29T12:57:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sandyjmacdonald](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/sandyjmacdonald/32/393_2.png) [@sandyjmacdonald](https://forums.pimoroni.com/u/sandyjmacdonald)\
**Post date:** [December 29, 2017, 8:25pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/4 "2017-12-29T20:25:31Z")

</div>

You could do `p = int(rh.weather.pressure() / 10)`. That will convert the floating point number into an integer (whole number).

---

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 29, 2017, 8:42pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/5 "2017-12-29T20:42:08Z")

</div>

Thanks Sandy, I’m still learning so appreciate your help.

---

<div class="post-metadata">

**Author:** ![sandyjmacdonald](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/sandyjmacdonald/32/393_2.png) [@sandyjmacdonald](https://forums.pimoroni.com/u/sandyjmacdonald)\
**Post date:** [December 29, 2017, 8:52pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/6 "2017-12-29T20:52:46Z")

</div>

No probs. I think all programmers are still learning! Never stop. :-)

---

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 30, 2017, 11:58am UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/8 "2017-12-30T11:58:32Z")

</div>

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

````auto

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```
````

---

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 31, 2017, 3:59pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/9 "2017-12-31T15:59:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sandyjmacdonald](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/sandyjmacdonald/32/393_2.png) [@sandyjmacdonald](https://forums.pimoroni.com/u/sandyjmacdonald)\
**Post date:** [December 31, 2017, 5:16pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/10 "2017-12-31T17:16:34Z")

</div>

Here’s the documentation for Rainbow HAT: [http://docs.pimoroni.com/rainbowhat/#](http://docs.pimoroni.com/rainbowhat/#)

You can find docs for most of our boards at: [http://docs.pimoroni.com](http://docs.pimoroni.com)

---

<div class="post-metadata">

**Author:** ![badboybubby](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@badboybubby](https://forums.pimoroni.com/u/badboybubby)\
**Post date:** [December 31, 2017, 5:36pm UTC](https://forums.pimoroni.com/t/convert-barometric-pressure-to-display-on-rainbow-hat/6742/11 "2017-12-31T17:36:50Z")

</div>

Thanks Sandy, the answer was there all the time. I think when you read the [README.MD](http://README.MD) files on Github there is a link to the function reference section missing.

Cheers for the heads up

Scott
