Skip to content

Instantly share code, notes, and snippets.

@jadonk
Created February 18, 2014 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/9065159 to your computer and use it in GitHub Desktop.
Save jadonk/9065159 to your computer and use it in GitHub Desktop.
Quickly read the AIN values on BeagleBone Black for debugging the Quickbot (http://o-botics.org/robots/quickbot/). To install, open Cloud9 IDE on your board (http://<bot's IP address>:3000), create a new file and paste this content, then click the PREVIEW button.
<!-- Quickbot testing -->
<html>
<head>
<title>Quickbot testing</title>
<script src="http://beagleboard.org/static/jquery.js"></script>
<script src="http://beagleboard.org/static/bonescript.js"></script>
</head>
<body>
<h1>jQuery Demo</h1>
<p>AIN0 = <span id="ain0"></span></p>
<p>AIN1 = <span id="ain1"></span></p>
<p>AIN2 = <span id="ain2"></span></p>
<p>AIN3 = <span id="ain3"></span></p>
<p>AIN4 = <span id="ain4"></span></p>
<p>AIN5 = <span id="ain5"></span></p>
<p>AIN6 = <span id="ain6"></span></p>
<script>
// Connect with board connected at fixed USB address
// and execute run() upon initialization
setTargetAddress(window.location.hostname, { initialized: run });
// The demo BoneScript application within the 'run()' function
function run() {
/*
* Setup
*/
var b = require('bonescript');
var ain = [];
for(var j = 0; j <= 6; j++) {
for(var i = 0; i < b.bone.pinIndex.length; i++) {
if(b.bone.pinIndex[i].name == 'AIN' + j) {
ain[j] = b.bone.pinIndex[i].key;
}
}
}
var index = 0;
doRead();
function doRead() {
b.analogRead(ain[index], onRead);
}
function onRead(x) {
try {
$('#ain' + index).html(x.value.toFixed(3));
} catch(ex) {
$('#ain' + index).html('XXXXX');
}
index++;
if(index > 6) {
index = 0;
setTimeout(doRead, 100);
} else {
doRead();
}
}
}
</script>
</body>
</html>
@jeremyro
Copy link

jeremyro commented Mar 1, 2014

When I follow your instructions above, my browser opens a new tab with the below information. Do you know what I am doing wrong? I'm not supposed to save after copying, correct?

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<d:error xmlns:d="DAV:" xmlns:a="http://ajax.org/2005/aml">
<a:exception>jsDAV_Exception_FileNotFound/a:exception
<a:message>
File at location /var/lib/cloud9/Untitled1 not found
/a:message
<a:jsdav-version>0.1.2/a:jsdav-version
/d:error

@jadonk
Copy link
Author

jadonk commented Mar 11, 2014

You need to save the file with a name that has .html at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment