The buttons below wil run code in your that will impact the LEDs on your BeagleBone. The exact code used in the browser is below and will send messages to your board using Socket.IO.
Turn LEDs on:
b=require('bonescript');
b.pinMode('USR0', 'out');
b.pinMode('USR1', 'out');
b.pinMode('USR2', 'out');
b.pinMode('USR3', 'out');
b.digitalWrite('USR0', 1);
b.digitalWrite('USR1', 1);
b.digitalWrite('USR2', 1);
b.digitalWrite('USR3', 1);
Turn LEDs off:
b=require('bonescript');
b.pinMode('USR0', 'out');
b.pinMode('USR1', 'out');
b.pinMode('USR2', 'out');
b.pinMode('USR3', 'out');
b.digitalWrite('USR0', 0);
b.digitalWrite('USR1', 0);
b.digitalWrite('USR2', 0);
b.digitalWrite('USR3', 0);
All GPIOs accessible via digitalWrite and digtalRead.
This is your introduction to BeagleBone and Bonescript where you will learn:
BeagleBoard.org is an open hardware project leveling access to low-power mobile processing
| BeagleBoard-xM: Open software desktop experience with extra MHz and extra memory | BeagleBone: Hardware I/O focus with single cable development experience |
|
|
xzcat XXX.img.xz | sudo dd of=/dev/sdX
| P9 | P8 | |||||||
| 1 | 2 | 1 | 2 | |||||
| 45 | 46 | 45 | 46 | |||||
|
|
|
|
|
|
|
|
|
|
Some boilerplate required, but fairly minimal. Below is blinking LED app with the familiar blocking style:
require('bonescript');
ledPin = bone.USR3;
setup = function() {
pinMode(ledPin, OUTPUT);
};
loop = function() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
};
Installation and execution of above 'blinkled.js' with node 0.6.x on a supported platform would look something like:
# npm install bonescript # node blinkled.js
Blink USR3 LED for 30 seconds: run
value = 0;
pinMode(bone.USR3, 'out');
interval = setInterval(function() {
value = value ? 0 : 1;
digitalWrite(bone.USR3, value);
}, 100);
setTimeout(function() {
clearInterval(interval);
}, 30000);
What if we want to invoke the previous example on the target, rather than the browser?
Blink USR3 LED for 30 seconds: run
doEval(function(callback) {
var value = 0;
pinMode(bone.USR3, 'out');
var interval = setInterval(function() {
value = value ? 0 : 1;
digitalWrite(bone.USR3, value);
}, 100);
setTimeout(function() {
clearInterval(interval);
callback({'notice': "Removing doEval demo interval function"});
}, 30000);
return({'notice': "Launched doEval demo interval function"});
}, doAlert);
Blink USR3 LED: run
pinMode(bone.USR3, 'out');
addLoop(function() {
digitalWrite(bone.USR3, 1);
delay(100);
digitalWrite(bone.USR3, 0);
delay(100);
});
Halt all loops: run
getLoops(function(x) {
for(var loop in x.loops) {
removeLoop(loop);
}
});
You can download the BeagleBone Fritzing part
Please connect P8-3 to P8-5 with a 1khom resistor
Attach interrupt and toggle P8-3 for 30 seconds: run
Last value read was: unknown
pinMode(bone.P8_5, 'in');
pinMode(bone.P8_3, 'out');
value = 0;
digitalWrite(bone.P8_3, value);
function interruptHandler(x) { return({'value': x.value}); }
function interruptCallback(x) {
if(x.output) $('#attachInterruptValue').text(x.output.value);
else doAlert(x);
}
function toggleP8_3() {
value = value ? 0 : 1;
digitalWrite(bone.P8_3, value);
}
attachInterrupt(bone.P8_5, interruptHandler, 'both', interruptCallback);
var interval = setInterval(toggleP8_3, 200);
setTimeout(function() {
clearInterval(interval);
detachInterrupt(bone.P8_5, doAlert);
}, 30000);
Monitor analog in: run
pinMode(bone.P8_13, 'out', 4);
addLoop(function() {
var value = analogRead(bone.P9_36);
analogWrite(bone.P8_13, value);
}, 25, doAlert);
Fade in and out: run
pinMode(bone.P8_13, 'out', 4);
addLoop(function() {
if(!this.awDirection) { this.awValue = 0.01; this.awDirection = 1; }
analogWrite(bone.P8_13, this.awValue);
this.awValue = this.awValue + (this.awDirection*0.01);
if(this.awValue > 1.0) { this.awValue = 1.0; this.awDirection = -1; }
else if(this.awValue < 0.01) { this.awValue = 0.01; this.awDirection = 1; }
}, 10, doAlert);
Halt all loops: run
getLoops(function(loops){for(var loop in loops.loops){removeLoop(loop, doAlert);}});
Please connect P8-13 to LED through 1khom resistor
Attach to slider: run
pinMode(bone.P8_13, 'out', 4);
$("#slider1").bind("slidechange", function(event, ui) {
analogWrite(bone.P8_13, ui.value/100.0);
})
Please connect P9-36 to potentiometer and adust from 0V to 1.8V
Attach to slider for 30 seconds: run
arUpdateSlider = function(x) {
if(x.value) $("#slider2").slider("option", "value", x.value*100);
if(x.halt) alert("Halting analogRead slider update");
};
doEval(function(callback) {
var interval = setInterval(function() {
analogRead(bone.P9_36, callback);
}, 100);
setTimeout(function() {
clearInterval(interval);
callback({'halt':true});
}, 30000);
}, arUpdateSlider);
cd /var/lib/cloud9 git pull origin master
The interactivity presented on the previous slide is provided through a set of services running on your BeagleBone. You can experiment with some of these services below. The immediately following slides will provide you with some dynamic information about your BeagleBone.
Your BeagleBone is currently running the Angstrom Distribution. Below are links to upgrades for Angstrom and various other starting points you might choose for your project.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Share Alike 3.0 license