Skip to content

Commit 15c1188

Browse files
committed
fixed pressure unit and example
1 parent 161d961 commit 15c1188

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

adafruit_bmp280.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def pressure(self):
114114

115115
@property
116116
def altitude(self):
117-
"""calculate the altitude based on the sea level pressure (seaLevelPa) - which you must enter ahead of time)"""
118-
p = self.pressure / 100.0 # in Si units for Pascal
117+
"""calculate the altitude based on the sea level pressure (seaLevelhPa) - which you must enter ahead of time)"""
118+
p = self.pressure # in Si units for hPascal
119119
return 44330 * (1.0 - math.pow(p / self.seaLevelhPa, 0.1903));
120120

121121
def _read_coefficients(self):

examples/main.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import board
2+
import digitalio
23
import busio
34
import time
45
from adafruit_bmp280 import adafruit_bmp280
56

6-
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
7-
8-
while not i2c.try_lock(): pass
9-
print("I2C addresses found:", [hex(i) for i in i2c.scan()])
10-
i2c.unlock()
11-
12-
# Create library object on our I2C port
7+
# Create library object using our Bus I2C port
8+
i2c = busio.I2C(board.SCL, board.SDA)
139
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
1410

11+
# OR create library object using our Bus SPI port
12+
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
13+
#bmp_cs = digitalio.DigitalInOut(board.D10)
14+
#bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
15+
16+
# change this to match the location's pressure (hPa) at sea level
17+
bmp280.seaLevelhPa = 1013.25
18+
1519
while True:
1620
print("\nTemperature: %0.1f C" % bmp280.temperature)
1721
print("Pressure: %0.1f hPa" % bmp280.pressure)

0 commit comments

Comments
 (0)