mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
bmp280, bme280: Initial implementation
This library adds support for both the BMP280 and BME280 sesnors from Bosch. The BME is virtually identical to the BMP280 aside from some slight register changes and adding support for a humidity sensor. The BMP280 is an absolute barometric pressure sensor especially designed for mobile applications. The sensor module is housed in an extremely compact 8-pin metal-lid LGA package with a footprint of only 2.0 × 2.5 mm2 and 0.95 mm package height. Its small dimensions and its low power consumption of 2.7 μA @1Hz allow the implementation in battery driven devices such as mobile phones, GPS modules or watches. The BME280 is as combined digital humidity, pressure and temperature sensor based on proven sensing principles. The sensor module is housed in an extremely compact metal-lid LGA package with a footprint of only 2.5 × 2.5 mm2 with a height of 0.93 mm. Its small dimensions and its low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches. The BME280 is register and performance compatible to the Bosch Sensortec BMP280 digital pressure sensor These drivers support both I2C and SPI operation. When using SPI on an Edison with the arduino breakout board, you must specify a CS of -1 to the constructor, and connect the chip's CS pin to arduino pin 10. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -266,6 +266,7 @@ endif()
|
||||
add_example (vcap)
|
||||
add_example (ds2413)
|
||||
add_example (ds18b20)
|
||||
add_example (bmp280)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
@ -291,3 +292,4 @@ add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||
add_custom_example (bme280-example bme280.cxx bmp280)
|
||||
|
78
examples/c++/bme280.cxx
Normal file
78
examples/c++/bme280.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bme280.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
upm::BME280 *sensor = new upm::BME280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BME280(0, -1, 10);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
|
||||
cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
|
||||
cout << "Humidity: " << sensor->getHumidity() << " %RH" << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
77
examples/c++/bmp280.cxx
Normal file
77
examples/c++/bmp280.cxx
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "bmp280.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BMP280 instance using default i2c bus and address
|
||||
upm::BMP280 *sensor = new upm::BMP280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMP280(0, -1, 10);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
cout << "Pressure: " << sensor->getPressure() << " Pa" << endl;
|
||||
cout << "Computed Altitude: " << sensor->getAltitude() << " m" << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
69
examples/java/BME280_Example.java
Normal file
69
examples/java/BME280_Example.java
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_bmp280.BME280;
|
||||
|
||||
public class BME280_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
BME280 sensor = new BME280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// BME280(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println("Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " Pa");
|
||||
|
||||
System.out.println("Computed Altitude: "
|
||||
+ sensor.getAltitude()
|
||||
+ " m");
|
||||
|
||||
System.out.println("Humidity: "
|
||||
+ sensor.getHumidity()
|
||||
+ " %RH");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
65
examples/java/BMP280_Example.java
Normal file
65
examples/java/BMP280_Example.java
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_bmp280.BMP280;
|
||||
|
||||
public class BMP280_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMP280 instance using default i2c bus and address
|
||||
BMP280 sensor = new BMP280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// BMP280(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println("Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " Pa");
|
||||
|
||||
System.out.println("Computed Altitude: "
|
||||
+ sensor.getAltitude()
|
||||
+ " m");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -126,6 +126,7 @@ if (BACNET_FOUND)
|
||||
add_example(E50HX_Example e50hx)
|
||||
endif()
|
||||
add_example(VCAP_Example vcap)
|
||||
add_example(BMP280_Example bmp280)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
@ -133,4 +134,5 @@ add_example_with_path(Lcm1602_i2cSample lcd i2clcd)
|
||||
add_example_with_path(Lcm1602_parallelSample lcd i2clcd)
|
||||
add_example_with_path(SSD1308_oledSample lcd i2clcd)
|
||||
add_example_with_path(SSD1327_oledSample lcd i2clcd)
|
||||
add_example_with_path(BME280_Example bmp280 bmp280)
|
||||
|
||||
|
71
examples/javascript/bme280.js
Normal file
71
examples/javascript/bme280.js
Normal file
@ -0,0 +1,71 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_bmp280');
|
||||
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BME280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BME280(0, -1, 10);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log("Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " Pa");
|
||||
|
||||
console.log("Computed Altitude: "
|
||||
+ sensor.getAltitude()
|
||||
+ " m");
|
||||
|
||||
console.log("Humidity: "
|
||||
+ sensor.getHumidity()
|
||||
+ " %RH");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
67
examples/javascript/bmp280.js
Normal file
67
examples/javascript/bmp280.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_bmp280');
|
||||
|
||||
// Instantiate a BMP280 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMP280();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMP280(0, -1, 10);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log("Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " Pa");
|
||||
|
||||
console.log("Computed Altitude: "
|
||||
+ sensor.getAltitude()
|
||||
+ " m");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
60
examples/python/bme280.py
Normal file
60
examples/python/bme280.py
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_bmp280 as sensorObj
|
||||
|
||||
# Instantiate a BME280 instance using default i2c bus and address
|
||||
sensor = sensorObj.BME280()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# BME280(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
print "Compensation Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Pressure: ", sensor.getPressure(), "Pa"
|
||||
|
||||
print "Computed Altitude:", sensor.getAltitude(), "m"
|
||||
|
||||
print "Humidity:", sensor.getHumidity(), "%RH"
|
||||
|
||||
print
|
||||
time.sleep(1)
|
58
examples/python/bmp280.py
Normal file
58
examples/python/bmp280.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_bmp280 as sensorObj
|
||||
|
||||
# Instantiate a BMP280 instance using default i2c bus and address
|
||||
sensor = sensorObj.BMP280()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# BMP280(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
print "Compensation Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Pressure: ", sensor.getPressure(), "Pa"
|
||||
|
||||
print "Computed Altitude:", sensor.getAltitude(), "m"
|
||||
|
||||
print
|
||||
time.sleep(1)
|
Reference in New Issue
Block a user