Beagleboard:BMP on the Beagle Bone Black

From eLinux.org
Jump to: navigation, search

BMP085 on the Beagle Board Black

Adafruit offers a BMP085 Pressure Sensor for $19.95 that measures barometric pressure and temperature via I2C. I have referenced both schematics below as a reference to the Hardware Section.
BMP085.jpg BYi-8-Port-1-Wire-PinDiagram.jpg

Setting up the Hardware

The BMP085 has 7 pins, 4 of which we will be using to connect to the BBB.

  1. Connect GND from the BMP085 to P9.1 of your BBB.
  2. Connect VIN from the BMP085 to P9.3 of your BBB.
  3. Connect SCL from the BMP085 to P9.19 of your BBB.
  4. Connect SDA from the BMP085 to P9.20 of your BBB.
  5. Once all the pins are connected, plug in your BBB to your computer via the Mini USB Data Cable. Wait for your BBB to connect to your host computer.

Reading the Barometric Pressure and Temperature

Using a terminal emulator such as PuTTy, we will setup and print the sensor ratings.

1. We will now inform the BBB that the BMP085 sensor is located at I2C location 0x77. The following command will initialize the driver.

echo bmp085 0x77 > /sys/class/i2c-adapter/i2c-1/new_device

2. To check that it was successfully initialized, type this in the terminal.

dmesg | grep bmp

You should see something like this:

[ 609.654845] i2c i2c-1: new_device: Instantiated device bmp085 at 0x77
[ 609.883799] bmp085 1-0077: Successfully initialized bmp085!

3. In order to read the temperature (in Celcius), type the following command in your terminal.

cat sys/bus/i2c/drivers/bmp085/1-0077/temp0_input

This will give you the temperature ratings. Divide that number by 10 and you will have the temperature in Celcius.

4. Now, we will read the pressure (in millibars). Type the following command in your terminal.

 cat sys/bus/i2c/drivers/bmp085/1-0077/pressure0_input

This is the given pressure, in millibars.

Bonescript

If you want to check the temperature/pressure ratings on Cloud9 using Bonescript, you can copy and paste this code onto your Cloud9 IDE and view the results on the console.

1. Plug in your BBB to your computer via the Mini USB Data Cable. Wait for your BBB to connect to your host computer.
2. Go to My Computer>BeagleBone Getting Started and open the START.htm file.
3. Once the "Step 1 and Step 2" buttons are highlighted green on the left, launch http://192.168.7.2 on your browser.
4. Scroll down to the Cloud9 IDE section on click on the "Cloud9 IDE" link to start the editor.
5. Click File>New File and copy and paste the code below.
6. Click File>Save As and save it as a .js file. (i.e. bmp085.js)
7. Run the code once. You should get an error but that is alright.
8. Next, comment out the 'b.writeTextFile(bmp085+ 'new_device', 'bmp085 0x77'); line and save. We don't need it anymore since we installed the driver already.
9. Run the code again and you should see an output of your temperature ratings on the console.


/***************************BMP085.js***************************************
* Created on: 6-12-2013
* Revised on: 6-13-2013
* Author: Juan Cortez
* Works on: 06-08-12 image or later on both BeagleBone and BeagleBone Black
* Reads temperature and pressure from the BMP085 Sensor
* Input: Sensors on the BMP085 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(bmp085....); line, save and run the code again.
*******************************************************************************/ 
var b = require('bonescript');
var bmp085= '/sys/class/i2c-adapter/i2c-1/'; 

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

/* We will initialize the driver for the BMP085 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(bmp085 + 'new_device', 'bmp085 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"); 
}