Modifications

Sauter à la navigation Sauter à la recherche
4 654 octets ajoutés ,  10 septembre 2015 à 11:05
Ligne 44 : Ligne 44 :  
pressure = sense.get_pressure()
 
pressure = sense.get_pressure()
 
print(pressure)</nowiki>
 
print(pressure)</nowiki>
 +
 +
'''5.''' Select {{fname|File > Save}} (''Fichier > Sauver'') and choose a file name for your program.
 +
 +
'''6.''' Select {{fname|Run > Run module}} (''Exécuter > Exécuter module'').
 +
 +
'''7.''' If you see the error {{fname|Pressure Init Failed}} (''erreur d'initialisation de la pression''), please run as {{fname|root}} en utilisant {{fname|
 +
sudo}} on the last line in red, it means you haven't followed the instructions above. Close everything and go back to step 1.
 +
 +
'''8.''' You should see something like this:
 +
 +
<nowiki>Pressure sensor Init Succeeded
 +
1013.40380859</nowiki>
 +
 +
Le première ligne "Pressure sensor Init Succeeded" signifie ''Senseur de pression initialisé avec succès''.
 +
 +
If you get {{fname|0}} just run the code again. This sometimes happens when you use the pressure sensor for the first time.
 +
 +
'''9.''' Just before the {{fname|print(pressure)}} line, add this line below:
 +
 +
<nowiki>pressure = round(pressure, 1)</nowiki>
 +
 +
== Surveiller la pression ==
 +
'''1.''' It would be good to monitor the pressure as it changes, so let's put your code into a while loop and run it again:
 +
 +
<nowiki>while True:
 +
    pressure = sense.get_pressure()
 +
    pressure = round(pressure, 1)
 +
    print(pressure)</nowiki>
 +
 +
'''2.''' Unfortunately, it's not as easy to make it change as holding your thumb on the sensor or breathing on it, so use the plastic bottle experiment below to test your code.
 +
 +
== Expérience de la bouteille de plastique ==
 +
The experiment involves sealing a Raspberry Pi fitted with a Sense HAT inside a plastic bottle along with a mobile phone top up battery, and then blowing into the bottle to increase the air pressure. Someone with a good pair of lungs should easily be able to increase the pressure to about 1100 millibars inside the bottle. You'll first need to program the visual display.
 +
 +
'''1.''' Regardez la [https://www.youtube.com/watch?v=CHUukiKF3ew vidéo de "Dave Honess"] (''YouTube, anglais'') à propos de cette expérience.
 +
 +
'''2.''' Take an empty two litre plastic bottle, discard the lid, and cut it in half across the middle as shown:
 +
 +
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Pression-20.png]]
 +
 +
Dry the inside of the bottle using a tissue or a dishcloth. Do not be tempted to use a heat gun or a hair dryer as they will warp the plastic.
 +
 +
'''3.''' Do a fit test. Try to fit the upper half inside the bottom half to join it back together. If you blow into the bottle now you'll feel the air coming back at you through the gaps in the side; later you'll use tape to seal them.
 +
 +
'''4.''' Shut down the Raspberry Pi, leaving all the peripherals connected.
 +
 +
'''5.''' Disconnect the power supply and replace it with the mobile top up battery.
 +
 +
'''6.''' The Pi should boot up as usual, allowing you to load up and run the code.
 +
 +
'''7.''' Disconnect all the peripherals apart from the battery once the code is running, and put everything into the bottle. Make sure the top half goes inside the bottom half, so you'll feel the air coming back at you when you blow.
 +
 +
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Pression-21.png]]
 +
 +
'''8.''' Use the tape to seal the join between the two halves of the bottle:
 +
 +
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Pression-22.png]]
 +
 +
'''9.''' Blow into the bottle. You should feel air coming back at you if you've got any leaks so just use more tape to patch these.
 +
 +
[[Fichier:RASP-SENSE-HAT-ASTRO-PI-Pression-23.png]]
 +
 +
'''10.''' Be aware that the moisture in your breath will steam up the inside of the bottle, so stop before you make the Pi damp.
 +
 +
'''11.''' Remove the tape and separate the two halves of the bottle if you need to change the code. Just reconnecting the peripherals to do a quick edit should work fine.
 +
 +
== Afficher la pression sur la matrice LED ==
 +
Below is the code that was used in the video. It can cope with 1000 to 1100 millibars, so that's 100 millibars of range. We know that the LED matrix colours have a range of 0 to 255, so the first thing it does is create a ratio between the pressure range and the colour range. The plan is then to multiply the measured pressure by that ratio to get the colour. You have to subtract 1000 from the measured pressure to make this work, so you're multiplying a number between 0 and 100 by the ratio. It then clamps the colour to a maximum of 255, in case there is someone with very strong lungs who can drive the pressure higher than 1100 millibars.
 +
 +
<nowiki>from sense_hat import SenseHat
 +
 +
sense = SenseHat()
 +
sense.clear()
 +
 +
ratio = 255 / 100.0
 +
 +
while True:
 +
    pressure = sense.get_pressure()
 +
    pressure = round(pressure, 1) - 1000
 +
    blue = int(ratio * pressure)
 +
    if blue > 255:
 +
        blue = 255
 +
    sense.clear((0, 0, blue))</nowiki>
    
{{traduction}}
 
{{traduction}}
    
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
29 917

modifications

Menu de navigation