O'Reilly logo

Programming the BeagleBone by Yogesh Chavan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program to print temperature

Write the following code in Cloud9 and save it as tmp36.js. Run the program and check the printed temperature. Then touch the plastic body of the sensor for a few seconds (avoid touching metal pins). You should see an increase in temperature. The code for tmp36.js is as follows:

var b = require('bonescript');
var loopTimer = setInterval(readVoltageLoop, loopTime);
var loopTime = 2000;
var TMP36 = 'P9_40';

function readVoltageLoop()
{
  b.analogRead(TMP36, printTemperature);
}

function printTemperature(pinObj)
{
  var volt = pinObj.value * 1.8;
  var temperature = (100 * volt) - 50;
  console.log("Voltage at input pin = " + volt.toPrecision(3) + " Temperature in Celsius =" + temperature.toPrecision(3) );
}

Explanation

We want ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required