Bonescript simple examples not working

616 views
Skip to first unread message

Vincent lc

unread,
Jul 14, 2016, 5:01:17 AM7/14/16
to BeagleBoard
Hi,

I just install Bonescript on my cloud9. Now I'm trying to use some simple examples.
However, when I tried to use them I got some error, nevertheless, I didn't understand why, and how I can solve them.

First example : Toogle LED
var b = require('bonescript');

var leds = ["USR0", "USR1", "USR2", "USR3","P8_07"];

for(var i in leds) {
    b
.pinMode(leds[i], b.OUTPUT);
}

var state = b.LOW;
for(var i in leds) {
    b
.digitalWrite(leds[i], state);
}

setInterval
(toggle, 1000);

function toggle() {
   
if(state == b.LOW) state = b.HIGH;
   
else state = b.LOW;
   
for(var i in leds) {
        b
.digitalWrite(leds[i], state);
   
}
}

 The error that I got :
 
/root/labs/cloud9_app/node_modules/bonescript/src/hw_mainline.js:84
   
if(!pinmux) { throw p + " was not found under " + my.is_ocp(); }
                                                   
^
ocp
:P8_07_pinmux was not found under /sys/devices/platform/ocp


Remark : if I change the line
 var leds = ["USR0", "USR1", "USR2", "USR3","P8_07"];
by
var leds = ["USR0", "USR1", "USR2", "USR3",];

My program is working because it didn't use a gpio pin which request a configuration.


Second example : set a PWM signal and change the duty cycle of it :
source : http://beagleboard.org/support/BoneScript/ServoMotor/

var b = require('bonescript');
var SERVO = 'P9_14';
var duty_min = 0.03;
var position = 0;
var increment = 0.1;

//b.pinMode(SERVO, b.OUTPUT);
updateDuty
();

function updateDuty() {
   
// compute and adjust duty_cycle based on
   
// desired position in range 0..1
   
var duty_cycle = (position*0.115) + duty_min;
    b
.analogWrite(SERVO, duty_cycle, 60, scheduleNextUpdate);
    console
.log("Duty Cycle: " +
        parseFloat
(duty_cycle*100).toFixed(1) + " %");  
}

function scheduleNextUpdate() {
   
// adjust position by increment and
   
// reverse if it exceeds range of 0..1
    position
= position + increment;
   
if(position < 0) {
        position
= 0;
        increment
= -increment;
   
} else if(position > 1) {
        position
= 1;
        increment
= -increment;
   
}
   
   
// call updateDuty after 200ms
    setTimeout
(updateDuty, 200);
}



Error :
  /root/labs/cloud9_app/node_modules/bonescript/src/hw_mainline.js:84
   
if(!pinmux) { throw p + " was not found under " + my.is_ocp(); }
                                                   
^
ocp
:P9_14_pinmux was not found under /sys/devices/platform/ocp


To confirm that my code was working I have tested it on the original kernel install on the beaglebone.
Both were working on it. So, I was wondering if it didn't come from the dts/dtbo file.
To test that I copy the one form the original kernel in my own one. It didn't succeed either.

Here are my current configuration :
# node --version
v0
.12.7

# npm --version
2.11.3

# node -pe "require('bonescript').getPlatform().bonescript"
0.5.0

# uname -a
Linux beagle09 4.1.21-bone-rt-r20 #3 Wed May 25 13:55:22 CEST 2016 armv7l GNU/Linux


Did someone have an Idea on what's wrong ? Am I missing something ?
If you have any questions do not hesitate.
Thanks by advance for your help

Regards
Vincent
" Enjoy life no matter what ! "



sba...@mtu.edu

unread,
Aug 12, 2016, 9:42:24 AM8/12/16
to BeagleBoard

Hi Vincent,

I am facing the same problems. Did you find some solution?

Regards,
Shantayan

Wally Bkg

unread,
Aug 13, 2016, 3:05:10 PM8/13/16
to BeagleBoard, sba...@mtu.edu
Bonescript has had various breakages because of kernel changes for over a year now.  No solid solution yet, but Jason & Robert seem to be working on it, look for a new image on beagleboard.org when Jason puts it up.

In the meantime, I evaluated several images in June and July, search for my posts and Bonescript and I believe there were a few kernels than mostly had working Bonescript functions,  I don't remember which images they were, but they are listed in my posts.

Vincent lc

unread,
Aug 19, 2016, 11:09:44 AM8/19/16
to BeagleBoard, sba...@mtu.edu
Hi,

I didn't find "solution to fix it". However, there is some alternative to it :  create your own library, or find other one.
You can maybe have a look at the following one:
https://github.com/wphermans/Bonejs?files=1

This one uses the file reading operation to interact with the peripheral.

The other solution (slower), could be to execute shell command with JS

example of function to export a GPIO pin:
/*------------------------------------------------------------------------------------
function to export a gpio Pin
    Parameter : the pin that you want to export  
*/

function gpio_export(pin)
{
   
   
var path_export=path+"/export"; // export path

   
//method where we execute the shell command

     
var command = "echo "+pin.toString()+" > "+path_export //the shell command that want to do
   
     
//execution of the command
       process
.exec(command,function (err,stdout,stderr) {
           
//if there is some error print them
           
if (err) {
                console
.log("\n"+stderr);
           
} else {
                console
.log(stdout);
           
}
       
});

}

I hope that it will help you.
If you have further questions, do not hesitate.


Regards
Vincent
" Enjoy life no matter what ! "

Reply all
Reply to author
Forward
0 new messages