Comments (6)
This is the first time I've heard of this issue and I'm unable to reproduce the issue with the onoff integration tests on Buster.
Please provide a simple but complete program that can be used to reproduce the issue.
Please also provide the output of the following commands when run on the Raspberry Pi:
cat /etc/debian_version
uname -a
node -v
from onoff.
This appears to be a related issue raspberrypi/linux#2550, however onoff doesn't appear to suffer from this issue.
from onoff.
@fivdi Thanks for taking the time to look into this. I was out for a few days but I'll work on putting together a small repro. It might be related to other hardware I have on the pi (I have an ezconnect board between the pi and a PICAN2 CANBus card. )
from onoff.
@fivdi First, I don't think there is a fundamental problem so I will close the issue. But I did get some fairly interesting findings by messing with pin/port numbers and hardware.
The code I was testing with is super simple, just the blink example plus a watch on another pin:
var Gpio = require('onoff').Gpio;
var LED = new Gpio(4, 'out');
var ignitionSwitch = new Gpio(21, 'in', 'both', {debounceTimeout: 10})
var blinkInterval = setInterval(blinkLED, 250);
ignitionSwitch.watch((err, value) => {
console.log('ignition: ', err, value);
LED.writeSync(value);
});
function blinkLED() { //function to start blinking
if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off)
LED.writeSync(1); //set pin state to 1 (turn LED on)
} else {
LED.writeSync(0); //set pin state to 0 (turn LED off)
}
}
function endBlink() {
clearInterval(blinkInterval);
LED.writeSync(0);
// LED.unexport();
}
setTimeout(endBlink, 5000); //stop blinking after 5 seconds
However, when I first started, I accidentally used the pin number, not the GPIO number so line 3 read var ignitionSwitch = new Gpio(40, 'in', 'both', {debounceTimeout: 10})
, not 21.
With that code and without the PICAN2 board, I could not get the pi to hang. Of course, I also wasn't getting any hits on the pin either, because I was watching some non-existent pin. With that code and the PICAN2 board, the pi would hang anytime any pin was touched with a wire, even when the wire wasn't grounded or attached to voltage.
I can't really explain this, but with the code reduced to just this:
var Gpio = require('onoff').Gpio;
var LED = new Gpio(4, 'out');
var blinkInterval = setInterval(blinkLED, 1000);
function blinkLED() { //function to start blinking
if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off)
LED.writeSync(1); //set pin state to 1 (turn LED on)
} else {
LED.writeSync(0); //set pin state to 0 (turn LED off)
}
console.log('blink: ', new Date().getTime());
}
It would run forever without the PICAN2 but would hang as soon as any pin was touched while the PICAN2 was attached. I tried reproing that again just now and noticed that the console logging, which should happen every second, stalls for about 10 seconds when a pin is touched, and my bluetooth kb and mouse hang but then the "blink" console logs start up again so the pi isn't completely hung.
Yet, the original code with the pin properly set to 21 works correctly, with or without the PICAN2 board attached. Therefore, while I'm still confused as to why it was/is hanging/ish with no ignitionSwitch watch, I'm closing the issue.
from onoff.
Oh, and if you still want it:
debian_version: 10.4
uname: Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l GNU/Linux
node: v10.21.0
from onoff.
@jlit Thank you for providing the feedback.
A Raspberry Pi has 53 GPIOs but many of them are not broken out to the 40 pin GPIO header. See here. I don't know if it's valid to use GPIO40 and I don't know if using it can have negative consequences.
from onoff.
Related Issues (20)
- Problem using watch function with relay HOT 10
- Initialize GPIO without change pin status. HOT 6
- GPIO not working in a worker_thread - nodejs 14.15 HOT 2
- EACCES: permission denied, open '/sys/class/gpio/export' as superuser HOT 2
- Cannot run on non Rpi system HOT 1
- TypeError: writeSync is not a function HOT 4
- Raspberry Pi GPIO control in electron App HOT 8
- My computer does not have a /sys/class/gpio directory, but has /dev/gpiochip* HOT 1
- Interrupt misfire HOT 3
- Raspberry 4 - malloc(): corrupted top size HOT 3
- Error: EPERM: operation not permitted, write HOT 4
- Does not work with Compute Module 4. HOT 2
- Event is fired multiple times
- Superb library - I am running on Node v20 HOT 2
- Pi 5 Compatibility issues HOT 9
- Compatibility with ppp asked?
- RPI 5 gpio numbers HOT 1
- fs error HOT 6
- Newer version of epoll
- Button.watch spams endlessly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onoff.