-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot get started with node.js sample #438
Comments
hi @wmmihaa,
ideally, you can't get access to the sensors before the board is not ready yet (due to the async nature of Node.js). |
Thanks @marcellobarile, |
alright but then the "led.turnOn" call should be placed inside the "onInit" handler. |
That is the exact sample I'm running: var GrovePi = require('node-grovepi').GrovePi
// put led in port D3
var led = new GrovePi.sensors.DigitalOutput(2);
// status will tell us if the led is on or off
var status = 0;
var board;
function toggle() {
if (status == 0){
console.log("toggle off");
led.turnOff();
status = 1;
}
else {
console.log("toggle on");
led.turnOn();
status = 0;
}
}
function start() {
console.log('starting')
board = new GrovePi.board({
debug: true,
onError: function(err) {
console.log('TEST ERROR')
},
onInit: function(res) {
console.log("OnInit");
if (res) {
// call toggle every second
setInterval(toggle, 1000)
}
}
})
board.init();
} // end start()
// called on Ctrl-C.
// close the board and clean up
function onExit(err) {
console.log('ending')
board.close()
process.removeAllListeners()
process.exit()
if (typeof err != 'undefined')
console.log(err)
}
// starts the test
start()
// catches ctrl+c event
process.on('SIGINT', onExit) |
Could there be any type of configurations of the pi I could have missed? I've enabled ic2 and gpio along with running |
Ad I didn't use the designated sd card (lost it), is this image downloadable? |
Well, you can download Raspbian For Robots that already has everything in it, or you can get a Raspbian and then run the above command and install it. Regardless, you have to run the same above command in order to get the GrovePi lib (mostly the python stuff) up to date. Here's the link to the image: Also, personally, I'd go with a fresh distribution. |
I have a newly installed pi3 with node.js 9.9.0 and npm 5.6.0. I created a groove directory and installed the node-grovepi package using:
npm install node-grovepi
I also ran the quick install command:
curl -kL dexterindustries.com/update_grovepi | bash
It seems to all be installed correctly, but I don't quite get it working. When trying the analog light for instance, I keep getting the same value (~20.0), but it makes no difference if I cover the sensor or hold it up to the light. If I put the sensor on a different port I get different readings (~0.01). So it seems like it can read the sensor but are not getting the right values.
If I try the leds nothing happends, not even an error...
Appreciate any help ;)
The text was updated successfully, but these errors were encountered: