# Question about interrupts

**URL:** <https://forum.xod.io/t/question-about-interrupts/71>\
**Category:** Hardware Interfacing Questions\
**Created:** [August 8, 2017, 7:10am UTC](https://forum.xod.io/t/question-about-interrupts/71 "2017-08-08T07:10:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![damianabaddon](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/damianabaddon/32/42_2.png) [@damianabaddon](https://forum.xod.io/u/damianabaddon)\
**Post date:** [August 8, 2017, 7:10am UTC](https://forum.xod.io/t/question-about-interrupts/71/1 "2017-08-08T07:10:50Z")

</div>

Hi, I plan to make a opto encoder and I want to know if an input signal in the io pins (rising edge or falling edge) internally trigger an interrupt? There are documantation about low level operation and other topics like this?  
Thanks for this great app, it’s a bit like microflo but much more light.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [August 8, 2017, 8:49am UTC](https://forum.xod.io/t/question-about-interrupts/71/2 "2017-08-08T08:49:53Z")

</div>

Hello!

There is no functionality that lets to deal with interrupts yet. It is in plans but not yet implemented.

The idea is to have a low-level general purpose node that watches for a particular INT and provides outputs:

- How many times the interrupt triggered because of rising/falling signal
- What’s the timestamp of the last triggered interrupt

Then all other things like encoder driver node could be based on such node.

Thank you for the feedback.

---

<div class="post-metadata">

**Author:** ![damianabaddon](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/damianabaddon/32/42_2.png) [@damianabaddon](https://forum.xod.io/u/damianabaddon)\
**Post date:** [August 8, 2017, 5:42pm UTC](https://forum.xod.io/t/question-about-interrupts/71/3 "2017-08-08T17:42:25Z")

</div>

Great! I think With this node and a loop suport, xod will be usable in the real world soon!

Off topic:  
Please, It’s a great app, don’t turn it in another kid toy, the educative apps are very important but I think the FBP in general and xod in particular have a big professional potencial for speedup the embedded programming.

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [August 9, 2017, 8:59am UTC](https://forum.xod.io/t/question-about-interrupts/71/4 "2017-08-09T08:59:25Z")

</div>

> [@damianabaddon](#):
>
> don’t turn it in another kid toy

We are trying. It’s quite hard to keep a balance, but we seek design decisions carefully so that they don’t restrict advanced applications and at the same time are accessible for a child (teenager).

---

<div class="post-metadata">

**Author:** ![i3laze](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/i3laze/32/288_2.png) [@i3laze](https://forum.xod.io/u/i3laze)\
**Post date:** [April 17, 2018, 6:09pm UTC](https://forum.xod.io/t/question-about-interrupts/71/5 "2018-04-17T18:09:39Z")

</div>

Any updates on implementing an interrupt node? It doesn’t sound that difficult.

I’m migrating a project from Arduino IDE… so far so good.  
My Pro Mini is battery-powered and sleeps the whole time, except when PIR-input triggers interrupt wake:

```auto
#include <JeeLib.h>
ISR(WDT_vect) {
  Sleepy::watchdogEvent();
}

void setup() {
    attachInterrupt(digitalPinToInterrupt(PIR_PIN), Interrupt, CHANGE);
}

void loop() {
  if (not Motion and not MotionEnded)
    Sleepy::powerDown();
  else 
    ...
}

```

How can I currently hardcode the code above into XOD?

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [April 17, 2018, 9:31pm UTC](https://forum.xod.io/t/question-about-interrupts/71/6 "2018-04-17T21:31:32Z")

</div>

Hello!

No changes yet. It’s not on the top of the backlog, unfortunatelly. Meanwhile, I can think you can try to make a C++ node which has inputs:

- `PORT` — awake the program when changed
- `SLP` — pulse to sleep

The code would be roughly:

```cpp
void evaluate(Context ctx) {
  if (isInputDirty<input_SLP>(ctx)) {
    // ... power down ...
  }

  auto port = getValue<input_PORT>(ctx);
  attachInterrupt(digitalPinToInterrupt(port), loop, CHANGE);
}

```

With some level of hacking I’m pretty sure you can make it work.

---

<div class="post-metadata">

**Author:** ![williamobrien-sk](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@williamobrien-sk](https://forum.xod.io/u/williamobrien-sk)\
**Post date:** [March 8, 2020, 3:24pm UTC](https://forum.xod.io/t/question-about-interrupts/71/7 "2020-03-08T15:24:15Z")

</div>

Just wondering if there are any nodes or examples of using interrupts? Thx

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [March 9, 2020, 1:49pm UTC](https://forum.xod.io/t/question-about-interrupts/71/8 "2020-03-09T13:49:43Z")

</div>

I don’t think many people have been working with interrupts in XOD. There is nothing in libraries or documentation pages. There have been several discussions in this forum, so searching the forum is probably your best bet. Unfortunately, I don’t know if that will give you any answers or just show who else was interested in using interrupts…

The only example I know of off hand is the delay node uses an alarm interrupt.

---

<div class="post-metadata">

**Author:** ![williamobrien-sk](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@williamobrien-sk](https://forum.xod.io/u/williamobrien-sk)\
**Post date:** [March 25, 2020, 11:10pm UTC](https://forum.xod.io/t/question-about-interrupts/71/9 "2020-03-25T23:10:48Z")

</div>

The following example code was posted in March 2019 regarding how an interrupt node could look like by [nkrkv](https://forum.xod.io/u/nkrkv)

quote…

There’s no interrupt management built in XOD C++ runtime (yet). A quick solution one could try is the following (very rough draft, unchecked):

```auto
volatile uint8_t interruptCount = 0;

void myISR() {
  // Record we have had an interrupt
  ++interruptCount;
}

void evaluate(Context ctx) {
    if (isSettingUp()) {
        // Register handler once
        auto pin = getValue<input_PORT>(ctx);
        attachInterrupt(digitalPinToInterrupt(pin), myISR, RISING);
    }

    if (interruptCount) {
        // Process a single interrupt
        --interruptCount;
        emitValue<output_OUT>(ctx, 1);
    }

    // Come back on next transaction
    setTimeout(ctx, 0);
}

```

I tried to make an node based on this but failed as I know little about code etc.

Can anyone help to make an interrupt node based on the above?  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [April 24, 2020, 11:10pm UTC](https://forum.xod.io/t/question-about-interrupts/71/10 "2020-04-24T23:10:58Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
