Using a Raspberry Pi 2 , and after confirming that wires aren't touching in places they're not supposed to be, I attached the wires from a single button to my 5v pin and GPIO pin 23 (no breadboard or anything at the moment). I plug my RPi's power in to my laptop without a charger plugged in and run the following javascript code (Nodejs 0.12.7).
Code: Select all
var Gpio = require('onoff').Gpio;
var moment = require('moment');
var firstButton = new Gpio(23, 'in', 'both', {debounceTimeout: 250});
firstButton.watch(function (err, value) {
console.log(moment() + ' Button Pressed | ' + value)
});To add to the issue, if I plug the Raspberry Pi in to my laptop again, but then an HDMI TV, the same issue happens.
What is it I'm doing wrong here? I'm new to messing with electrical. Do I need a breadboard with a couple other of little things to prevent this from happening when plugged in to the wall? Any help is appreciated. Thanks!
