beagleboard / bonescript

Scripting tools for the BeagleBoard and BeagleBone
http://beagleboard.org
MIT License
32 stars 9 forks source link

FALLING edge interrupt not being installed properly #20

Open jadonk opened 6 years ago

jadonk commented 6 years ago

From @maxwellhadley on February 26, 2014 12:49

I'm using bone script 0.2.4, node.js v0.8.22 on a BBB. uname -a gives: Linux beaglebone 3.8.13 #1 SMP Thu Sep 12 10:27:06 CEST 2013 armv7l GNU/Linux

Using pin p8_12, when I attach an interrupt of type bonescript.FALLING, I actually get an interrupt of type bonescript.CHANGE. Attaching an interrupt of type bonescript.RISING works as expected.

What should happen: Attaching an interrupt of type bonescript.FALLING should attach an interrupt which is triggered on the 1 -> 0 change of the input pin state only.

Copied from original issue: jadonk/bonescript#76

jadonk commented 6 years ago

From @droidicus on March 19, 2014 2:36

Could not duplicate with: Bonescript 0.2.4 node --version v0.10.25 uname -a Linux beaglebone 3.8.13-bone41 #1 SMP Tue Mar 4 22:51:47 UTC 2014 armv7l GNU/Linux

What image are you running? Is that an un-patched 3.8.13 kernel? You may want to try a recent kernel patch set and see if that fixes the problem (I think the right place to get this is https://github.com/beagleboard/kernel/tree/3.8 ). It sounds like this could be a kernel module issue.

jadonk commented 6 years ago

From @maxwellhadley on March 19, 2014 20:3

I'm running the 2013.09.04 Angström image, opkg upgrade-ed as of the day of the bug report. Is this not the latest image? How did you end up with node.js 0.10.25? Did you test on Angström or Debian? I agree it sounds like a kernel module (or possibly node.js) issue

jadonk commented 6 years ago

From @fivdi on March 19, 2014 20:50

How long is the interrupt line being held low? This is only a guess, but if it's not being held low for long enough, or bouncing, perhaps the following is happening:

1) The interrupt line is pulled low 2) The kernel informs BoneScript that there was an interrupt 3) The interrupt line is pulled high 4) BoneScript reads the state of the interrupt line and determines that it's high

jadonk commented 6 years ago

From @maxwellhadley on March 19, 2014 21:0

Brian, Jason,

The code is at https://github.com/maxwellhadley/node-red-nodes/blob/master/hardware/BBB/145-BBB-hardware.js

The interrupt is installed at lines 323-328, in function PulseInputNode().

The interrupt handler is interruptCallback() at line 275

I’ve tested using an Agilent pulse generator to drive the input pin, as well as a button and I don’t remember seeing any difference. It was the same button I used to check out my debounce code in the same source file (lines 120 on) which was tricky because the button didn’t bounce at all unless provoked!

Thanks,

Max On 19 Mar 2014, at 20:50, Brian Cooke notifications@github.com wrote:

How long is the interrupt line being held low? This is only a guess, but if it's not being held low for long enough, or bouncing, perhaps the following is happening:

1) The interrupt line is pulled low 2) The kernel informs BoneScript that there was an interrupt 3) The interrupt line is pulled high 4) BoneScript reads the state of the interrupt line and determines that it's high

— Reply to this email directly or view it on GitHub.

jadonk commented 6 years ago

From @fivdi on March 19, 2014 23:32

That's a fairly big example :). What do you mean when you say "an interrupt of type bonescript.CHANGE"? The following piece of code will enable interrupts on both rising and falling edges:

b.attachInterrupt(inputPin, true, b.CHANGE, interruptCallback);

Can the issue be reproduced with the example here: http://beagleboard.org/Support/BoneScript/attachInterrupt/

jadonk commented 6 years ago

From @droidicus on March 20, 2014 3:56

I used the 2014-03-04 Debian image from http://beagleboard.org/latest-images

It took a little bit of work to update my software to work with the new image and the updated Node.js, but so far it has been a lot more stable, and I have had to jump through fewer hoops to get various things to work.

If you want to stay with the Angstrom image, I would still recommend trying a more recent kernel patch set. I wrote a quick test to check this (toggle an output pin every 100ms, connect the output to an input pin with a short jumper wire, attach interrupt to the input, log to console), but I don't have access to it right now. I will try to remember to upload it tomorrow.

jadonk commented 6 years ago

From @droidicus on March 21, 2014 1:49

Here is the test file that I wrote. Can you connect the indicated pins, and try this on your image?

var b = require('bonescript');
var outputPin = "P9_12";
var inputPin = "P8_12";
var ledPin = "USR3";
var mydelay = 100;
var state = b.LOW;

b.pinMode(inputPin, b.INPUT);
b.pinMode(outputPin, b.OUTPUT);
b.digitalWrite(outputPin, b.LOW);
b.pinMode(ledPin, b.OUTPUT);
b.attachInterrupt(inputPin, setLED, b.RISING); // CHANGE RISING FALLING
console.log('Please connect ' + inputPin + ' to ' + outputPin +
    ' with a 1kohm resistor');
toggle();

function setLED(x) {
    b.digitalWrite(ledPin, x.value);
    console.log("INT'ed: ", x.value);
}

function toggle() {
    state = (state == b.LOW) ? b.HIGH : b.LOW;
    b.digitalWrite(outputPin, state);
    setTimeout(toggle, mydelay);
}
jadonk commented 6 years ago

From @maxwellhadley on March 23, 2014 20:23

On my BBB, this program gave the following output:

x---------------------------------x root@beaglebone:~/pin_test# node pin_test Please connect P8_12 to P9_12 with a 1kohm resistor debug: Started GPIO interrupt listener debug: Attaching handler to /sys/class/gpio/gpio44/value WARNING: ev_io is deprecated, use uv_poll_t INT'ed: 1

/usr/lib/node_modules/bonescript/index.js:451 if(m.output.handler && (typeof callback == 'function')) callback(m); ^ TypeError: Cannot read property 'handler' of undefined at ChildProcess.f.attachInterrupt.intHandler (/usr/lib/node_modules/bonescript/index.js:451:20) at ChildProcess.EventEmitter.emit (events.js:99:17) at handleMessage (child_process.js:273:12) at Pipe.channel.onread (child_process.js:293:9) root@beaglebone:~/pin_test#

I'm not sure what is going on here...