• Increase font size
  • Default font size
  • Decrease font size
Home
Home BeagleBone Black Lesson 2: BeagleBone Black read Analog Tutorial

Lesson 2: BeagleBone Black read Analog Tutorial

It is time to make our Beagle sniff the external world.  Make sure you have gone through Lesson 1 and that you can blink an LED first.  On the pin mapping your Analog inputs our on the P9 connector (aka. expansion headers) as pins

AIN0
39
AIN140
AIN237
AIN3

38

AIN4
33
AIN536
AIN6
35
GND_ADC
34
VDD_ADC32


For a quick test just make use of how Linux reads/writes files to display the current analog readings.  Connect VDD_ADC pin P9_32 to P9_36 so that AIN5 will read 1.0 (1.8v).  Also connect a wire to P8_13.  Run the example analog.js (below code) and you should read 3.3 volts on P8_13.

var b = require('bonescript');

inputPin = "P9_36";
outputPin = "P8_13";

b.pinMode(outputPin, b.OUTPUT);
loop();

function loop() {
    var value = b.analogRead(inputPin);
    b.analogWrite(outputPin, value);
    setTimeout(loop, 1);
};

Once this is working you should be able to access it by reading the following linux files ( note tyou can read all the analog inputs with AIN*)

cat /sys/devices/ocp.2/helper.14/AIN5

Mine showed

1798

which is in mv so 1.798V which is the VDD_ADC that we connected to it.   Now connect gnd to AIN5 pin and repeat

cat /sys/devices/ocp.2/helper.14/AIN5

Mine showed 

0

 

Newsflash

Joomla! makes it easy to launch a website of any kind. Whether you want a brochure site or you're building a large online community, Joomla! allows you to deploy a site in minutes and add functionality as you need it. The hundreds of extensions will expand your site and allow you to deliver new services that expand your reach into the Internet.