manix
Posts: 12
Joined: Thu Jul 25, 2019 7:50 am

Cannot detect interrupt properly on a pulled up line

Fri Apr 03, 2020 8:18 pm

This may not classify as advanced but is not particularly beginner level either.

This is my simple setup

Image

This is my test program, using nodejs and rpi-gpio.

Code: Select all

var gpio = require('rpi-gpio');

gpio.on('change', function(channel, value) {
    console.log('Channel ' + channel + ' value is now ' + value);
});
gpio.setup(36, gpio.DIR_IN, gpio.EDGE_BOTH);
I expect when I close the switch the voltage at point A to drop to 0 and trigger a falling edge interrupt, however all I see in my program is rising edge interrupts, i.e.:

Code: Select all

Channel 36 value is now true
Channel 36 value is now true
Channel 36 value is now true
I had my doubts, as this is not the best library for GPIO manipulation, that there might be some kind of bug, but I physically separated GPIO16 from A (pulled out the jumper cable on the pin) and then I saw a falling edge interrupt

Code: Select all

Channel 36 value is now true
Channel 36 value is now true
Channel 36 value is now true
Channel 36 value is now false
I also measured the voltage at point A which is about 2.7V regardless of whether the switch is open or closed.

There are a total of 3 switches and all of them are working normally, tested with a multimeter. It is not a switch issue because I see the same behavior across all of them.

Something that may be worth mentioning is that the distance between A and SW1 is about 4 meters. And that's also why I'm pulling up, as I can't move SW1 physically and there is already ground there, this way I'm saving 1 cable of about 4 meters.

I'm missing something which is probably really silly, but oh well..

Oh and I'm aware there are internal pull-up resistors but I'd rather use external ones.

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Cannot detect interrupt properly on a pulled up line

Sat Apr 04, 2020 9:21 am

All GPIOs from GPIO9 upwards than the first by default have pull-downs set; this is probably why pulling out the jumper resulted in a "false" reading.
It also explains the 2.7v reading when the switch is open (the internal pull-down is about 50k)
It might be worth changing the pull to either none or up.

However, with the switched closed, shouldn't you read 0v?
This seems to indicate a wiring problem.

Another thing that might be worth exploring is the value of your pull-up resistor - 10k seems rather large, given the length of your cable. Maybe reduce it to 1k, and also add a capacitor close to the Pi, to further reduce any RF pick-up.

manix
Posts: 12
Joined: Thu Jul 25, 2019 7:50 am

Re: Cannot detect interrupt properly on a pulled up line

Sat Apr 04, 2020 7:57 pm

Yes, after quite some digging I found table 6.2 on page 102 of http://www.farnell.com/datasheets/1521578.pdf which shows that the pins I was using have a default pull down state and also looking at the internal schematic of GPIO pins http://www.mosaic-industries.com/embedd ... ifications I was able to work out the exact 2.7 voltage at A which made sense. What didn't make sense was the solution to the problem - I edited /boot/config.txt to set up the 3 pins I'm using as no pull

Code: Select all

gpio=16,19,26=pn
And after rebooting my problem went away. I honestly can not make sense of how this solved my problem but that's the facts.

Return to “Advanced users”