adc working last angstrom build

add this to bonescript index.js

https://www.youtube.com/watch?v=JJS42HShD7M

analogRead = exports.analogRead = function(pin){
    var value = fs.readFileSync("/sys/devices/platform/tsc/ain" +
pin);
    return value;
}

have ez1 sonar working on beaglebone. max output voltage at max 255
in. is less than 1.8 volts.
using node.js and processing.js
also blinks led at less than alarm voltage. two views fishview and
default.
client code
Dashboard
Project Files
Open a file or create a new one to get started
    p.draw = function(){
         p.background(224);
        p.textSize(30);
        p.fill(0, 102, 153);
        myWidth = p.textWidth('sonar ' + inches + ' in');
        p.text('sonar ' + inches + ' in', canvasWidth/2 - myWidth/2,
canvasHeight - 40);
        var height = (inches/255) * canvasHeight ;
        p.arc(xorigin, yorigin, height, height, -120 * Math.PI/180,
-60 *Math.PI/180);
        };
    p.drawFish = function(){
        p.background(224);
        p.textSize(15);
        p.fill(0, 102, 153);
        for (i = 25; i < 255; i+=25){
            var height = (i/255) * canvasHeight ;
            p.line(0,height, canvasWidth, height);
            p.text(i + ' in', 10, height-20);
        }
        for (j = 0; j < 3; j++){
            if (!isNaN(fishArray[j])){
                var depth = fishArray[j]/255 * canvasHeight;
                var x = canvasWidth/2 + (j*120) - 90;
                var y = depth;
                p.ellipse(x,y , 70,20);
                p.triangle(x-20,y,x-40,y-20, x-40, y+20);
                p.text(Math.round(fishArray[j]),x , y + 25);
            }
        }
    };
    p.noLoop();
}
var currentProc;
var sonar = new Processing(sonarCanvas, sonarSketchProc);
var socket = io.connect('http://192.168.7.2:8080');
socket.on('reading', function (data) {
     var r = document.getElementById('range').value;
      var x = parseFloat(data);
   // console.log(x);
    inches = Math.floor(x);
    var dispMode = document.getElementById('display').value
    fishArray[count] = x;

server code

var bb = require('./bonescript');
var io = require('socket.io').listen(8080);
var ledPin = bone.P8_3;
var onLed = false;
io.disable('heartbeats');
io.set('log level', 1);
function getReading(){
var raw = parseFloat(analogRead('1'));
  // console.log("raw " + raw);
    var v = (raw/4096.000)* 1.8;
  // console.log("actual voltage " + v);
    var inches = v/(3.4/512);

    return inches;
}
io.sockets.on('connection', function (socket) {
   pinMode(ledPin, OUTPUT);
  socket.emit('reading', getReading() );

  socket.on('nextReading', function (data) {

    socket.emit('reading', getReading());
  });

  socket.on('toggle',function(data){
    if (onLed === false){
          digitalWrite(ledPin, HIGH);
          onLed = true;
      } else {
          digitalWrite(ledPin, LOW);
          onLed=false;
      }
  });
  socket.on('ledoff',function(data){
      digitalWrite(ledPin, LOW);
  });

});

Hah! Your analog read function is nearly identical to the one that I
wrote. I did add "1" to the argument to make it more "arduino-ish".
In other words "analogRead(0)" reads from "/sys/devices/platform/tsc/
ain1"

I vacillated between using a numeric index (like you did) and using
the actual header location as the ADC argument (like the bonescript
"digitalOut()" does). The simpler "numeric index" approach won --
lazy me ...

Dithering over which way to access the data seems like a very small
thing, but it also seems like one of those fragmentation issues that
can evolve into a royal pain over time. I personally would be
interested in the views of the BB community -- is it better to
-- use the header location (e.g. "analogRead('P9_39')
-- or use a numeric index (e.g. "analogRead(0)
-- or better still to devise a function that can accept either sort of
argument
   -- maybe define the ADC definitions in bonescript/index.js to
encapsulate all possibilities, e.g.
      P9_39: { name: "AIN0", index: 0, fileindex: 1, filename:
"ain1"},

And is it better to start at an index of "1" (like the "/sys/devices/
platform/tsc/ain" files) or start at "0" (like the documentation).

At any rate, I will probably tweak my functions to match whatever
format seems popular, with the hopes that it will be syntactically
correct when bonescript is updated.

BTW, I calculated an average conversion speed of about 800 samples per
second when polling all 8 channels using a function encapsulated in a
"loop()" function called using "bb.run()" -- i.e. the function
executed about 100 times per second and it polls all 8 channels.
putting "for" loop in the polling routine that iterates three times
seemed to result in "loop()" being called about 1/3 as fast, so I
presume that the file reads are the dominant cost here. I guess the
speed is ok -- but it's a few orders of magnitude below the
theoretical performance of the ADCs.

If either of you can send a pull request against https://github.com/jadonk/bonescript to merge your stuff, that would be great.

No problem -- probably this weekend (unless someone beats me to it).

I am still interested in any views on implementation style
- arduino-ish e.g. analogRead(0) .. analogRead(7)
- arduinino++-ish e.g. analogRead(1) .. analogRead(8)
- bone-ish -- e.g. analogRead('P9_39')
- some-mix-of-the-above-ish

I have found that doing things more-or-less the same as Arduino
(Wiring) is a decent way to leverage source code from various Arduino
libraries. I used this approach with TIWrap in order to port the
LiquidCrystal library and some MAX7221 library.

I would vote for the mix of Arduino-ish (0-7) and bone-ish. That will make it easier to port Arduino libraries.