This is my simple setup


simulate this circuit – Schematic created using CircuitLab

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

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.:

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

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.

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.

  • Before you get too far check the switch is working properly. I suggest you use my abyz.me.uk/rpi/pigpio/examples.html#Python_monitor_py (needs the pigpio daemon to be running so sudo pigpiod followed by ./monitor.py 16). – joan Apr 3 '20 at 19:47
  • @joan I can confirm the switch is operating properly. There are 3 switches in total, and the behavior is the same for all of them. I tested them all with a multimeter and none are showing signs of any funny business. – php_nub_qq Apr 3 '20 at 19:57
  • what voltage level is represented by true? – jsotola Apr 3 '20 at 20:35
  • Are you saying monitor.py correctly shows the edges? If it does that indicates the problem is with your software. If it does not that indicates the problem is with your hardware. – joan Apr 3 '20 at 20:47
  • @jsotola true is supposed to be logic high or 1, which for the raspberry I think is >2V – php_nub_qq Apr 3 '20 at 20:53

Apparently all pins have enabled pull up/down resistors by default, listed in this document on page 102.

The pins I was using have a default pull-down setting, which explains the 2.7V at A given that the internal resistors are 50k.

I don't know how, but removing the default pull-down resistance solved my problem. Usually more advanced libraries have APIs for this but in my case I had to edit /boot/config.txt and add the following line


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.