Modifications

Sauter à la navigation Sauter à la recherche
1 714 octets supprimés ,  2 janvier 2017 à 11:30
Ligne 75 : Ligne 75 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
== Modifier le code ==
  −
La bibliothèque BMP085 (BMP180) est organisé en deux classes séparée. Il y a une classe qui gère la communication de bas niveau sur le SMBus/I2C (Adafruit_I2C), et une autre classe pour gérer les fonctionnalités spécifiques au BMP085/BMP180.
  −
  −
La bibliothèque inclus l'exemple ci-dessous, mais vous pouvez également adapter un peu le code pour obtenir des informations de débug (utile au cas où vous auriez des problèmes), ou modifier l'adresse ou utiliser le BMP085/180 dans l'un des 4 différents modes (ULTRALOWPOWER, STANDARD, HIRES, and ULTRAHIRES). Voyez les différents commentaires dans le code ci-dessous:
  −
  −
<nowiki>#!/usr/bin/python
  −
  −
from Adafruit_BMP085 import BMP085
  −
  −
# ===========================================================================
  −
# Example Code
  −
# ===========================================================================
  −
  −
# Initialise le BMP085/BMP180 et utilise le mode STANDARD (valeur par défaut)
  −
# L'adresse du BMP sur le BUS est ici 0x77.
  −
# bmp = BMP085(0x77, debug=True)
  −
bmp = BMP085(0x77)
  −
  −
# Pour utiliser un mode différent avec le BMP, vous pouvez décommenter l'une
  −
#  des lignes suivantes:
  −
# bmp = BMP085(0x77, 0)  # Mode ULTRALOWPOWER (super basse consommation)
  −
# bmp = BMP085(0x77, 1)  # Mode STANDARD
  −
# bmp = BMP085(0x77, 2)  # Mode HIRES (haute résolution)
  −
# bmp = BMP085(0x77, 3)  # Mode ULTRAHIRES (Ultra haute résolution)
  −
  −
temp = bmp.readTemperature()  # Lecture de la température
  −
pressure = bmp.readPressure() # Lecture de la pression
  −
altitude = bmp.readAltitude() # Lecture de l'altitude
  −
  −
print "Température: %.2f C" % temp
  −
print "Pression:    %.2f hPa" % (pressure / 100.0)
  −
print "Altitude:    %.2f" % altitude</nowiki>
      
You can see from the comments there are a few ways to create the sensor instance. By default if you pass no parameters the library will try to find the right I2C bus for your device. For a Raspberry Pi the library will detect the revision number and use the appropriate bus (0 or 1). For a Beaglebone Black there are multiple I2C buses so the library defaults to bus 1, which is exposed with pin P9_19 as SCL clock and P9_20 as SDA data. You can explicitly set the bus number by passing it in the busnum parameter.
 
You can see from the comments there are a few ways to create the sensor instance. By default if you pass no parameters the library will try to find the right I2C bus for your device. For a Raspberry Pi the library will detect the revision number and use the appropriate bus (0 or 1). For a Beaglebone Black there are multiple I2C buses so the library defaults to bus 1, which is exposed with pin P9_19 as SCL clock and P9_20 as SDA data. You can explicitly set the bus number by passing it in the busnum parameter.
29 910

modifications

Menu de navigation