RASP-SENSE-HAT-ASTRO-PI-Humidite

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Senseur de température

The Sense HAT features a number of sensors, one of which is a humidity sensor that measures the amount of water in the air.

Le source anglaise de cette traduction se trouve ici https://www.raspberrypi.org/learning/astro-pi-guide/sensors/humidity.md

Qu'est ce que l'humidité

- Humidity is the amount of water vapour in the air.
- Water vapour is the gaseous state of water.

The amount of water vapour suspended in the air is dependent on temperature.

- The higher the temperature, the more water vapour can be suspended in the air.
- The lower the temperature, the less water vapour can be suspended.

![](images/condensation.jpg)

When you take a cold can or bottle out of the fridge you see water appearing on it. This happens because the cold bottle is cooling the air around it, causing the air to be less capable of suspending water vapour. This then causes the water vapour that can't be suspended to turn back into liquid water. This is called condensation. So, given this information, we next need to understand that there are two ways that we can measure humidity:

- *Absolute* humidity is the total mass of water vapour suspended in a given volume of air. Temperature is not taken into consideration. It's usually expressed as grams of water per cubic metre of air.
- *Relative* humidity, however, is expressed as a percentage. For any given air temperature there is a maximum amount of water vapour that it can suspend. Relative humidity is the percentage of actual water vapour present, compared to the maximum possible amount.

A known amount of water vapour will result in different relative humidity readings, depending on the temperature of the air and the ability of the air to suspend it. So a low air temperature might give a high relative humidity reading because the air can't suspend much more water vapour. Increasing the temperature of the air and keeping the same amount of water vapour will cause the relative humidity reading to drop, because the maximum amount of water vapour that could be suspended has increased.

The Sense HAT gives you the humidity measurement as relative humidity. This is why the humidity sensor also has a temperature sensor built in.

Quel est le taux d'humidité

1. Open Python 3 from a terminal window as sudo by typing:

sudo idle3 &

2. Select File > New Window (Fichier > Nouvelle fenêtre) and enter the following code:

from sense_hat import SenseHat

sense = SenseHat()
sense.clear()

humidity = sense.get_humidity()
print(humidity)

3. Select File > Save (Fichier > Sauver) and choose a file name for your program.

4. Select Run > Run module (Exécuter > Exécuter module).

5. If you see the error Humidity Init Failed, please run as root / use sudoon the last line in red, it means you haven't followed the instructions above. Close everything and go back to step 1.
Le message signifie Initialisation d'humidité échouée, exécutez comme root / utiliser sudo.

6. You should see something like this:

Humidity sensor Init Succeeded
34.6234588623

La première ligne du message signifiant Senseur d'humiditié initialisé avec succès.

7. Just before the print(humidity) line add this line below:

humidity = round(humidity, 1)

8. You should now see something like this, without all the numbers after the decimal point:

Humidity sensor Init Succeeded
34.6

Surveiller l'évolution de l'humidité

1. It would be good to monitor the humidity as it changes, so let's put your code into a while loop and run it again:

while True:
        humidity = sense.get_humidity()
        humidity = round(humidity, 1)
        print(humidity)

2. Exhale slowly onto the sensors. The water vapour in your breath should cause the readings to jump up.

3. Keep watching and it should slowly fall back to the background humidity of the room.

4. Pressez Ctrl + C pour arrêter le programme.

Afficher l'humidité sur la matrice LED

Think about how you might use the matrix to display the humidity. One way is to divide 64 (the number of LEDs in the matrix) by 100, then multiply that by the percentage of relative humidity, which gives you the number of LEDs you should turn on. 100%, for example, would be all 64 LEDs turned on. To do this, you need to build up a pixel list of the right number of light vs. dark pixels, and then call the set_pixels function.

from sense_hat import SenseHat

sense = SenseHat()
sense.clear()

on_pixel = [255, 0, 0]
off_pixel = [0, 0, 0]

while True:
    humidity = sense.get_humidity()
    humidity = round(humidity, 1)

    if humidity > 100:
        humidity = 100.0

    pixels = []
    on_count = int((64 / 100.0) * humidity)
    off_count = 64 - on_count

    pixels.extend([on_pixel] * on_count)
    pixels.extend([off_pixel] * off_count)

    sense.set_pixels(pixels)

Source: Getting Started with Astro PI et Astro-Pi Guide proposé par Raspberry Pi Learning Resource (www.raspberrypi.org)

Licence Creative Commons - CC-BY-SA
The learning resource is provided for free by the Raspberry Pi Foundation under a Creative Commons licence.
Find more at raspberrypi.org/resources and github.com/raspberrypilearning.

Traduction réalisée par Meurisse. D pour shop.MCHobby.be - Licence CC-BY-SA.
Crédit de traduction: Toute référence, mention ou extrait de cette traduction doit également être explicitement accompagné du crédit de traduction suivant : «  Traduction par MCHobby (shop.MCHobby.be) » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.