Page 1 of 1

Testing the pressure sensor

Posted: Sat May 16, 2015 7:11 am
by Davespice
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))

Re: Testing the pressure sensor

Posted: Sat May 16, 2015 7:18 am
by Johnny5C
Thanks Dave! Going to try this with the kids later!

Re: Testing the pressure sensor

Posted: Sat May 16, 2015 7:20 am
by Davespice
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.

Re: Testing the pressure sensor

Posted: Sat May 16, 2015 9:22 am
by Johnny5C
1027.34 Millibars this morning in sunny Gosport. Could use this to make a neat little graphical barometer..

Re: Testing the pressure sensor

Posted: Sat May 16, 2015 10:46 am
by aTao
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.

Re: Testing the pressure sensor

Posted: Sat May 16, 2015 11:01 am
by AndyD
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.

Re: Testing the pressure sensor

Posted: Fri May 22, 2015 11:18 am
by JarJarGeek
Yes , tested that Hue script , very cool ; http://fb.me/4uD4GHz9Z
Great work !!