rakeshpai / pi-gpio

A simple node.js-based GPIO helper for the Raspberry Pi
MIT License
711 stars 126 forks source link

opening for output may be causing a change in GPIO state (to 0) occasionly #32

Open markv1 opened 9 years ago

markv1 commented 9 years ago

when running the following code repeatedly (setting the GPIO pin to 1 -relay off multiple times), occationally i hear the relay click and get a momentary contact on. I also see a GPIO-Admin: could not flush data to /sys/class/gpio/export: device or resource busy. I am using a RPb+ and sainsmart 8ch relay board. The momentary contact on when the relay is already off is the most problematic.

gpio.open(pin,'output', function(err) { gpio.write(pin,highLow,function() { gpio.close(pin);
}); });

lucasmoglia commented 9 years ago

Hi! Did you find any solution to this problem? Because i'm having the same trouble. I'm using a setTimeout function but the pin is activated just for a second or less.

Thanks!

skoold2003 commented 9 years ago

Are you referring to the fact that the pin value is set to 0 on open? I added a line to the end of the setDirection method as shown here:

fs.writeFile(sysFsPath + "/gpio" + pinMapping[pinNumber] + "/value", 1, (callback || noop));

This sets the default export value to 1. This should be added to the library IMO but I'm not sure how to request that.