Différences entre versions de « Rasp-Hack-BMP085-Python-Lib »
Ligne 3 : | Ligne 3 : | ||
== Introduction == | == Introduction == | ||
− | + | Le code Python du BMP085 pour Raspberry Pi est disponible sur le le dépôt GitHub [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code Adafruit-Raspberry-Pi-Python-Code] | |
− | + | Même si une partie des pilotes et classes sont toujours en cours d'évolution -- AdaFruit investit beaucoup de temps pour accéder à la couche matériel de façon aussi simple que possible -- le code actuel est un excellent point de départ pour comprendre comment accéder aux périphériques SMBus/I2C de votre Pi, et obtenir des données depuis votre BMP085/BMP180. | |
== Télécharger le code depuis GitHub == | == Télécharger le code depuis GitHub == |
Version du 9 avril 2014 à 19:05
Introduction
Le code Python du BMP085 pour Raspberry Pi est disponible sur le le dépôt GitHub Adafruit-Raspberry-Pi-Python-Code
Même si une partie des pilotes et classes sont toujours en cours d'évolution -- AdaFruit investit beaucoup de temps pour accéder à la couche matériel de façon aussi simple que possible -- le code actuel est un excellent point de départ pour comprendre comment accéder aux périphériques SMBus/I2C de votre Pi, et obtenir des données depuis votre BMP085/BMP180.
Télécharger le code depuis GitHub
The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros. Simply run the following commands from an appropriate location (ex. "/home/pi"):
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git $ cd Adafruit-Raspberry-Pi-Python-Code $ cd Adafruit_BMP085
Crédit: AdaFruit Industries www.adafruit.com
Tester la bibliothèque
If you're using a version 2 Pi (512 M) then you'll have to change the I2C bus as it flipped from #0 to #1 in the version 2. Edit Adafruit_I2C.py with nano Adafruit_I2C.py and change this line
def __init__(self, address, bus=smbus.SMBus(0), debug=False):
to
def __init__(self, address, bus=smbus.SMBus(1), debug=False)
Once the code has be downloaded to an appropriate folder, and you have your BMP085 properly connected, you can start reading some data via the following command (the driver includes a simple demo program):
sudo python Adafruit_BMP085_example.py
Which should give you something similar to the following:
Crédit: AdaFruit Industries www.adafruit.com
Modifier le code
The BMP085 library is organized as two seperate classes. There is one class to handle the low-level SMBus/I2C calls (Adafruit_I2C), and another class that handles the BMP085-specific functionality.
The library includes the basic example shown above, but you can also customize the code a bit to provide full debug output if you're having any problems, change the address, or use the BMP085 in one of it's four different modes (ULTRALOWPOWER, STANDARD, HIRES, and ULTRAHIRES), as seen in the commented out initializors in the sample code below:
#!/usr/bin/python from Adafruit_BMP085 import BMP085 # =========================================================================== # Example Code # =========================================================================== # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) bmp = BMP085(0x77) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode # bmp = BMP085(0x77, 3) # ULTRAHIRES Mode temp = bmp.readTemperature() pressure = bmp.readPressure() altitude = bmp.readAltitude() print "Temperature: %.2f C" % temp print "Pressure: %.2f hPa" % (pressure / 100.0) print "Altitude: %.2f" % altitude
Source: Using BMP085 with Raspberry Pi. Créé par Kevin Townsend pour AdaFruit Industries.
Traduction et corrections réalisée par Meurisse D pour MCHobby.be.
Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : « Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.
L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.
Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com