2

I am able to control a servo with pi-blaster from the command line successfully. However when I try to use pi-blaster.js to do so in Node.js (either at the node command line or from within a Node file) it does nothing.

works:

sudo echo "17=0" > /dev/pi-blaster

or

sudo echo "17=0.1" > /dev/pi-blaster

does not work:

var piblaster = require('pi-blaster.js');

piblaster.setPwm(17, 1 ); # 100% brightness
piblaster.setPwm(22, 0.2 ); # 20% brightness
piblaster.setPwm(23, 0 ); # off

I have already verified that pi-blaster.js is loaded correctly by Node.js as well.

1

I contacted the pi-blaster.js creator and found out that the npm version of the module was slightly out of date for recent bug fixes. He gave me the bug fixes and pushed the changes to the npm package manager so this problem should not reoccur for others.

However, if the problem does reoccur for someone: the actual problem in the pi-blaster.js code was that the series of nested if and else statements were not using curly brackets which caused the script to fail silently. Adding the curly brackets fixes the problem.

In case anyone wants more info these are the relevant GitHub issues:

https://github.com/sarfata/pi-blaster.js/pull/8

https://github.com/sarfata/pi-blaster.js/issues/9

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.