Modifications

Sauter à la navigation Sauter à la recherche
2 156 octets ajoutés ,  5 avril 2014 à 10:37
Ligne 15 : Ligne 15 :     
{{ADFImage|Rasp-Hack-BMP085-Python-Lib-01.png|480px}}
 
{{ADFImage|Rasp-Hack-BMP085-Python-Lib-01.png|480px}}
 +
 +
== 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
 +
 +
<nowiki>def __init__(self, address, bus=smbus.SMBus(0), debug=False):<nowiki>
 +
 +
to
 +
 +
<nowiki>def __init__(self, address, bus=smbus.SMBus(1), debug=False)</nowiki>
 +
 +
 +
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):
 +
 +
<nowiki>sudo python Adafruit_BMP085_example.py</nowiki>
 +
 +
Which should give you something similar to the following:
 +
 +
 +
{{ADFImage|Rasp-Hack-BMP085-Python-Lib-02.png|480px}}
 +
 +
== 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:
 +
 +
<nowiki>#!/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</nowiki>
    
{{Rasp-Hack-BMP085-TRAILER}}
 
{{Rasp-Hack-BMP085-TRAILER}}
29 910

modifications

Menu de navigation