User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Testing the pressure sensor

Sat May 16, 2015 7:11 am

Hi folks
Unfortunately it's not as easy to make the air pressure sensor values change as holding your thumb on the sensor or breathing on it. But I've come up with a neat and cheap way that you can use in the classroom with your kids.

You will need:
  • A two litre plastic bottle (circular in cross section)
  • A mobile phone top up battery
  • A USB-A to Micro USB-b lead
  • A pair of scissors
  • Sticky tape, any kind
Check out this video:
https://www.youtube.com/watch?v=CHUukiKF3ew

Here is the code:

Code: Select all

from astro_pi import AstroPi

ap = AstroPi()
ap.clear()

ratio = 255 / 100.0

while True:
    pressure = ap.get_pressure()
    pressure = round(pressure, 1) - 1000
    blue = int(ratio * pressure)
    if blue > 255:
        blue = 255
    ap.clear((0, 0, blue))

Johnny5C
Posts: 82
Joined: Thu Apr 18, 2013 3:32 pm

Re: Testing the pressure sensor

Sat May 16, 2015 7:18 am

Thanks Dave! Going to try this with the kids later!

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Testing the pressure sensor

Sat May 16, 2015 7:20 am

Nice one. The range is 1000 to 1100 millibars. It assumes the resting air pressure is 1000 millibars or above, if it's below this it'll probably calculate the blue colour component as a negative number and then fall over. You can see it subtracts 1000 from whatever pressure is measured and then uses the ratio to calculate what the blue colour component should be.

Johnny5C
Posts: 82
Joined: Thu Apr 18, 2013 3:32 pm

Re: Testing the pressure sensor

Sat May 16, 2015 9:22 am

1027.34 Millibars this morning in sunny Gosport. Could use this to make a neat little graphical barometer..

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Testing the pressure sensor

Sat May 16, 2015 10:46 am

If, instead of huffing and puffing into the bottle, you attach (air tight) a long piece of preferably clear hose pipe half filled with water, you can get positive and negative pressure by raising and lowering the free end of the pipe.
But do be careful not to get your astropi wet.
>)))'><'(((<

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Testing the pressure sensor

Sat May 16, 2015 11:01 am

How about changing the Hue of the display based on the pressure, rather than the intensity. Something like this:-

Code: Select all

from astro_pi import AstroPi
import colorsys

ap = AstroPi()
ap.clear()

pressureRange = 200.0
basePressure = ap.get_pressure()

while True:
    pressureDelta = ap.get_pressure() - basePressure + (pressureRange / 2.0)
    hue = 1.0 - (pressureDelta / pressureRange)
    rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)

    red = int(rgb[0] * 255)
    green = int(rgb[1] * 255)
    blue = int(rgb[2] * 255)

    ap.clear(red, green, blue)
Note: I don't have an Astro Pi, so I can't test the code. I don't write very much Python.

JarJarGeek
Posts: 48
Joined: Tue Mar 18, 2014 11:32 am

Re: Testing the pressure sensor

Fri May 22, 2015 11:18 am

Yes , tested that Hue script , very cool ; http://fb.me/4uD4GHz9Z
Great work !!
@jarjargeek

syntax-err0r.com

Return to “Astro Pi”