@abandonware/bmp085-sensor 中文文档教程

发布于 5年前 浏览 24 项目主页 更新于 3年前

BMP085.js

访问 BMP085 温度和传感器 使用 Node.js 的 Raspberry Pi 气压传感器。

NPM

Install

$ npm install bmp085-sensor

Usage

没有指定单位,返回 inHg 和华氏度。

var bmp085 = require('bmp085-sensor');

var sensor = bmp085({address: 0x77,
                     mode: 3});

sensor.calibrate(function (err, data) {                                                                                                                                                                                                                                        
  if(err || !data) {                                                                                                                                                                                                                                                           
     throw err;                                                                                                                                                                                                                                                                
  }                                                                                                                                                                                                                                                                            
  console.log(data);                                                                                                                                                                                                                                                           
  sensor.read(function (err, data) {                                                                                                                                                                                                                                           
    if(err || !data) {                                                                                                                                                                                                                                                         
      throw err;                                                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                                          
    // data is { pressure: 29.957463223223005, temp: 68.9 }
  });                                                                                                                                                                                                                                                                          
});

您还可以指定公制单位,返回 Pa 和摄氏度:

var bmp085 = require('bmp085-sensor');

var sensor = bmp085({address: 0x77,
                     mode: 3,
                     units: 'metric'});

sensor.calibrate(function (err, data) {                                                                                                                                                                                                                                        
  if(err || !data) {                                                                                                                                                                                                                                                           
     throw err;                                                                                                                                                                                                                                                                
  }                                                                                                                                                                                                                                                                            
  console.log(data);                                                                                                                                                                                                                                                           
  sensor.read(function (err, data) {                                                                                                                                                                                                                                           
    if(err || !data) {                                                                                                                                                                                                                                                         
      throw err;                                                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                                          
    // data is { pressure: 101435.97, temp: 20.5 }
  });                                                                                                                                                                                                                                                                          
});

Using alt runtime IoT.js

make runtime=iotjs
# iotjs test.js 
# ...
#   "temperature": 32.3
#   "pressure": 100855.38749926083,
# ...

Resources

  • https://www.npmjs.com/package/bmp085-sensor
  • https://github.com/dbridges/bmp085-sensor
  • https://www.openhub.net/p/bmp085-sensor

BMP085.js

Access a BMP085 temperature & barometric pressure sensor from your Raspberry Pi using Node.js.

NPM

Install

$ npm install bmp085-sensor

Usage

With no units specified, returns inHg and degree F.

var bmp085 = require('bmp085-sensor');

var sensor = bmp085({address: 0x77,
                     mode: 3});

sensor.calibrate(function (err, data) {                                                                                                                                                                                                                                        
  if(err || !data) {                                                                                                                                                                                                                                                           
     throw err;                                                                                                                                                                                                                                                                
  }                                                                                                                                                                                                                                                                            
  console.log(data);                                                                                                                                                                                                                                                           
  sensor.read(function (err, data) {                                                                                                                                                                                                                                           
    if(err || !data) {                                                                                                                                                                                                                                                         
      throw err;                                                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                                          
    // data is { pressure: 29.957463223223005, temp: 68.9 }
  });                                                                                                                                                                                                                                                                          
});

You can also specify metric units, returning Pa and degree C:

var bmp085 = require('bmp085-sensor');

var sensor = bmp085({address: 0x77,
                     mode: 3,
                     units: 'metric'});

sensor.calibrate(function (err, data) {                                                                                                                                                                                                                                        
  if(err || !data) {                                                                                                                                                                                                                                                           
     throw err;                                                                                                                                                                                                                                                                
  }                                                                                                                                                                                                                                                                            
  console.log(data);                                                                                                                                                                                                                                                           
  sensor.read(function (err, data) {                                                                                                                                                                                                                                           
    if(err || !data) {                                                                                                                                                                                                                                                         
      throw err;                                                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                                          
    // data is { pressure: 101435.97, temp: 20.5 }
  });                                                                                                                                                                                                                                                                          
});

Using alt runtime IoT.js

make runtime=iotjs
# iotjs test.js 
# ...
#   "temperature": 32.3
#   "pressure": 100855.38749926083,
# ...

Resources

  • https://www.npmjs.com/package/bmp085-sensor
  • https://github.com/dbridges/bmp085-sensor
  • https://www.openhub.net/p/bmp085-sensor
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文