Modifications

Sauter à la navigation Sauter à la recherche
2 449 octets ajoutés ,  20 mai 2017 à 09:36
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
 +
<syntaxhighlight lang="python">
 +
#!/usr/bin/python
 +
# -*- coding: utf-8 -*-
 +
 +
# Copyright (c) 2014 Adafruit Industries
 +
# Author: Tony DiCola
 +
# Traduction des commentaires - comment translation :
 +
# Meurisse D. (shop.mchobby.be)
 +
 +
# Permission is hereby granted, free of charge, to any person obtaining a copy
 +
# of this software and associated documentation files (the "Software"), to deal
 +
# in the Software without restriction, including without limitation the rights
 +
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 +
# copies of the Software, and to permit persons to whom the Software is
 +
# furnished to do so, subject to the following conditions:
 +
 +
# The above copyright notice and this permission notice shall be included in all
 +
# copies or substantial portions of the Software.
 +
 +
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 +
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 +
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 +
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 +
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 +
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 +
# SOFTWARE.
 +
 +
# Import de la bibliotheque DHT
 +
import Adafruit_DHT
 +
 +
# La classe senseur doit être soit
 +
# * Adafruit_DHT.DHT11
 +
# * Adafruit_DHT.DHT22
 +
# * Adafruit_DHT.AM2302
 +
sensor = Adafruit_DHT.DHT22
 +
 +
# Si vous utilisez un Beaglebone Black, le senseur DHT doit être
 +
# connecté sur la broche P8_11.
 +
# pin = 'P8_11'
 +
 +
# Si vous utilisez un Raspberry Pi, le senseur DHT doit être
 +
# connecté sur GPIO23.
 +
pin = 23
 +
 +
# Essayer d'obtenir une lecture du senseur.  Utiliser la méthode read_retry qui permet
 +
# de faire jusqu'a 15 essais de lecture pour obtenir une lecture du senseur
 +
# (attendre 2 secondes entre chaque essais).
 +
# Lecture de l'humidité et température
 +
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
 +
 +
# Il peut parfois arriver que la lecture échoue et que vous n'obteniez
 +
# pas de lecture ou que le résultat est null.
 +
# Cela est causé par le fait que Linux ne garanti pas
 +
# le temps d'appel pour lire le senseur.
 +
# Si cela arrive, essayez encore!
 +
if humidity is not None and temperature is not None:
 +
    print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature, humidity))
 +
else:
 +
    print('Echec de lecture. Essayez encore!')
 +
</syntaxhighlight>
    
{{Rasp-Hack-DHT22-TRAILER}}
 
{{Rasp-Hack-DHT22-TRAILER}}
29 917

modifications

Menu de navigation