Fork me on GitHub
beagleboard.org

BoneScript

BMP085 I2C pressure/temperature sensor demo

The BMP085 is a readily available pressure/temperature sensor using I2C. It is directly supported by the Linux kernel, so all you have to do is ask the kernel to load the driver and then start reading values.

Demo

var b = require('bonescript');
var bus = 1;
// uncomment if using SeeedStudio Grove sensor
// bus = 2;
var iic = '/sys/class/i2c-adapter/i2c-' + bus + '/';

//Sensor Locations on the BeagleBone Black
var temperature = '/sys/bus/i2c/drivers/bmp085/' + bus + '-0077/temp0_input';
var pressure = '/sys/bus/i2c/drivers/bmp085/' + bus + '-0077/pressure0_input';

// We will initialize the driver for the BMP085 sensor located at I2C location 0x77
b.writeTextFile(iic + 'new_device', 'bmp085 0x77');

// 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) {
   // '\xB0' is the degree symbol in hexademical
   console.log("Temperature: ", x.data/10 + '\xB0' + " Celcius");
   x.data /= 10;
   x.data *= 1.8;
   x.data += 32;
   console.log("or: ", x.data + '\xB0' + " Fahrenheit"); 
}

Build and execute instructions

  • Disconnect your board from power (including USB)
  • Connect BMP085 GND to P9_1
  • Connect BMP085 VCC to P9_3
  • Connect BMP085 SCL to P9_19
  • Connect BMP085 SDA to P9_20
  • Reapply power and refresh this page before running the demo code

See also

Topics

Related functions

Examples