onPinFall and onPinRise not doing what they should?


I have been trying to get the interrupt functions to work, but I’m getting strange results. If I use onPinFall it appears to not work at all. If I use onPinRise the function is called when the pin goes high AND when the pin goes low.  I tried the interrupt example, direct cut and paste, using onPinFall and it didn’t work either. 
I’m using Linux Mint 18.3, Zerynth 2.1, and an Arduino Due.
I’ve attached my full program, and a copy of the output. You can see that the “released” function gets called but the “pressed” function is never called. You can also see a few places where  “release” is called when I have pressed the button, and is then called again when I release the button. It is also called twice when I have quickly pressed and released the button.
What am I doing wrong?
:frowning: Ian


Hi mogplus8,

this is a known issue, and we are already working on it.
SAM3X devices (ArduinoDue and Flip&Click) have a bug in their onPinFall function.
Try to build your application, at least for now, with the onPinRise waiting for our updates.

Stay tuned :) 


Ok, thanks Matteo. No rush, just thought I was doing something wrong.
:wink: Ian


Hi mogplus8,

onPinFall and onPinRise function are now fixed for sam3x based devices (arduino due and flipnclick).
To test it, you have to create a new virtual machine for your device (don’t worry the number of your available licenses will not decrement) and virtualize it again.

Let me know if this fixes your problem :slight_smile:


I can confirm that the problem is now fixed for Arduino DUE


Thanks Matteo. I have been away for the last few weeks and haven’t had a chance to test this again. I will have another go at it in the next few days hopefully. Thanks to nborrell for confirming.
While I have your attention I have another query about interrupts. I have 18 pins of my Due connected to switches, and I’d like to have an interrupt on each one. Is it possible to put an interrupt in a loop? i.e.

for swPin in range (22, 39)
      onPinFall (swPin, doSwitchCheck)
      onPinRise (swPin, doSwitchCheck)

Then the function doSwitchCheck has a bunch of if / elif / else statements in it to determine which pin activated the interrupt. Or do I have to code each interrupt separately?

Thanks, Ian


Hi Ian,

it is definitely possible to set your callbacks in a loop and to have the same function for all of your pins.
Anyway I suggest you to pass the pin as an argument to your callback:

for swPin in range (22, 39)
      onPinFall (swPin, doSwitchCheck, swPin)
      onPinRise (swPin, doSwitchCheck, swPin)

to ease the process of determining which pin activated the interrupt.
Let me know if everything works as expected :slight_smile:


Particle Photon here, both pinrise and pinfall do not work at all.

Verified the pins are reading low and high correctly with digitalRead, it just doesn’t kick off the callback functions

onPinRise(pir_pin, motion_on)
onPinFall(pir_pin, motion_off)


I too can confirm that onpinrise and onpinfall are not working for Nucleo F401RE. I just got one of these and just tried it. Zip, zero, zilch, nada, nothing. The interrupt never calls the callback. Unfortunately I can’t check it with my Due as I don’t have access to it any more. :frowning:


EDIT. It works when the input is a button. It doesn’t work if the input is a pin triggered by a PWM signal. Maybe it’s a timing issue? This is the program I’m running. On my board I have D15 directly connected to D14. Although I believe it is possible to read the value of D15 even though it is set as an output pin. The output prints in the loop are printed once only, as the loop is entered on startup (as sw1 is initialised to True) but is never entered again.

import pwm
import streams
print(" here we go…")
sw1 = True
PPMout = D15.PWM
PPMtrig = D14
pinMode(PPMout, OUTPUT)
pinMode(PPMtrig, INPUT_PULLUP)

def PPMset():
sw1 = True

onPinFall(PPMtrig, PPMset)

while True:
if (sw1 == True):
sw1 = False
print(“loop entered”)
pwm.write(PPMout, duty, 300, time_unit=MICROS, npulses=1)
print(“after pwm.write”)
duty += 100
if (duty > 2000): duty = 5000
if (duty > 4900): duty = 1000

:frowning: Ian

I tried the Input Capture Unit example too, it didn’t work either. The button interrupt does (that’s how I found out, trying this example) but the only print I ever see is from the button interrupt. The ICU interrupt is never executed.
:frowning: Ian


Bump. Any progress on this issue? I’m in the middle of moving house so unfortunately don’t have much time to test.


Am I the only one having this problem?


Hi @mogplus8,

the onPinRise and onPinFall functions are not thought to react to a fast PWM signal, but should definitely be triggered at least once. Have you tried to see with a Logic Analyzer the behaviour of the PPMout pin?