analogWrite not working ERROR: Exception: Please perform setTargetAddress on a valid target

I am trying to run the code below on my beaglebone black but it is not working

var b = require(‘bonescript’);
b.analogWrite(‘P9_14’, 0.7, 2000, printJSON);
function printJSON(x) { console.log(JSON.stringify(x)); }

but I am getting this error

Exception: Please perform setTargetAddress on a valid target

Does anyone know what I did wrong?

I am trying to run the code below on my beaglebone black but it is not working

var b = require(‘bonescript’);
b.analogWrite(‘P9_14’, 0.7, 2000, printJSON);
function printJSON(x) { console.log(JSON.stringify(x)); }

but I am getting this error

Exception: Please perform setTargetAddress on a valid target

Does anyone know what I did wrong?

Are you doing this in the Cloud9 IDE, command-line or on a web page in your browser?

The error indicates you are doing this in a browser window, which isn’t running with access to the hardware. You need to connect to the BoneScript RPC server.

Your web page must already be including bonescript.js. You still need to point to your board to make the network connection from your browser window.

Maybe this’ll make more sense…

http://jsfiddle.net/jkridner/z547taL9/

I ran it on the browser and I got that error. i tried on Cloud9 IDE but it kept stopping and it wasn’t telling me if it actually did something.

Do you have anything hooked up to the pin to see if it is toggling?

I suspect that the pinmux mode isn’t right, but I’m not sure if I don’t set it up in that loop. Anyway, below is an example that probably gets a bit more usage. Note the usage of b.pinMode().

https://github.com/beagleboard/cloud9-examples/blob/master/BeagleBone/fade.js

var b = require(‘bonescript’);

// setup starting conditions
var awValue = 0.01;
var awDirection = 1;
var awPin = “P9_14”;

// configure pin
b.pinMode(awPin, b.ANALOG_OUTPUT);

// call function to update brightness every 10ms
setInterval(fade, 10);

// function to update brightness
function fade() {
b.analogWrite(awPin, awValue);
awValue = awValue + (awDirection*0.01);
if(awValue > 1.0) { awValue = 1.0; awDirection = -1; }
else if(awValue <= 0.01) { awValue = 0.01; awDirection = 1; }
}