***************************BMP280.js***************************************
* Created on: 6-12-2013
* Revised on: 6-13-2013
* BMP085 Author: Juan Cortez, Modified by me for the BMP280.
* Works on: 06-08-12 image or later on both BeagleBone and BeagleBone Black
* Reads temperature and pressure from the BMP280 Sensor
* Input: Sensors on the BMP280 Sensor
* Output: Outputs the readings on the console.
* Special Instructions: Run code once as it is. You will get an error but it is OK.
* Comment out the b.writeTextFile(bmp280....); line, save and run the code again.
*******************************************************************************/
var b = require('bonescript');
var bmp280= '/sys/class/i2c-adapter/i2c-1/';
//Sensor Locations on the BeagleBone Black
var temperature= '/sys/bus/i2c/drivers/bmp280/1-0077/temp0_input';
var pressure= '/sys/bus/i2c/drivers/bmp280/1-0077/pressure0_input';
/* We will initialize the driver for the BMP280 sensor located at I2C location 0x77.*/
/* !NOTE!: You only have to initialize the driver once. Once you run the code once, comment out the next line. (i.e. b.writeTextFile....) */
//b.writeTextFile(bmp280 + 'new_device', 'bmp280 0x77');
/************************************Comment out the line above after you run the code once***********************************************/
/* Opens,reads, and prints pressure and temperature. */
b.readTextFile(pressure, printPressure);
b.readTextFile(temperature,printTemperature);
/* Prints Pressure */
function printPressure(x) {
console.log("Pressure: ", x.data/100 + " millibar");
}
/* Prints Temperature */
function printTemperature(x){
console.log("Temperature: ", x.data/10 + '\xB0' + " Celcius"); // '\xB0' is decimal in hexademical
x.data /= 10;
x.data *= 1.8;
x.data += 32;
console.log("or: ", x.data + '\xB0' + " Fahrenheit");
}