Ligne 107 : |
Ligne 107 : |
| print "Pression: %.2f hPa" % (pressure / 100.0) | | print "Pression: %.2f hPa" % (pressure / 100.0) |
| print "Altitude: %.2f" % altitude</nowiki> | | 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. |
| + | |
| + | '''Note if you're using a BeagleBone Black with the Ubuntu operating system you might need to change busnum to 2 to use the P9_19 & P9_20 pin I2C connectio'''n. Just change the line to look like: '''sensor = BMP.BMP085(busnum=2)''' |
| + | |
| + | The library will also choose by default to use the BMP sensor's standard operation mode. You can override this by passing a mode parameter with an explicit mode value--check the [http://www.adafruit.com/datasheets/BMP085_DataSheet_Rev.1.0_01July2008.pdf fiche technique du BMP] for more information on its modes. |
| + | |
| + | Once the BMP sensor instance is created, you can read its values by calling the {{fname|read_temperature}}, {{fname|read_pressure}}, {{fname|read_altitude}}, and {{fname|read_sealevel_pressure}} functions like below: |
| + | |
| + | <syntaxhighlight lang="python"> |
| + | print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature()) |
| + | print 'Pressure = {0:0.2f} Pa'.format(sensor.read_pressure()) |
| + | print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude()) |
| + | print 'Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure()) |
| + | </syntaxhighlight> |
| + | |
| + | That's all you need to do to read BMP sensor values using the Adafruit Python BMP library! |
| + | |
| + | For another example of using the BMP library, check out the google_spreadsheet.py example. This code is similar to the [https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/overview DHT sensor Google Docs spreadsheet logging code] (''Adafruit, Anglais''), but is modified to use the BMP sensor and write the temperature, pressure, and altitude to a Google Docs spreadsheet. Check out the [https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/connecting-to-googles-docs-updated page on configuring Google Docs] to see more details on how to create the spreadsheet and configure the username, password, and spreadsheet name. |
| | | |
| {{Rasp-Hack-BMP085-TRAILER}} | | {{Rasp-Hack-BMP085-TRAILER}} |