Go Down

Topic: EnableInterrupt library- to attach interrupts to Arduino pins (Read 10565 times) previous topic - next topic

GreyGnome

Fri Oct 16 17:01:49 CDT 2015
Version 0.9.1 of the EnableInterrupt library has been released. Arduino Zero support added. Bug fixes in examples/OOSimple (thanks RobertClemenzi). And don't forget about the ATtiny support added in 0.9.0! See the Release Notes in the extras directory for details.

The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here.

Finally, direct download link is here

GreyGnome

Sat Oct 17 11:56:01 CDT 2015
Version 0.9.2 of the library has been released. I discovered a rather pernicious bug, wherein the library
was setting the global interrupt enable bit. This could cause a serious and difficult-to-debug race condition, as it is not the job of the library to manage that bit. The chips come with interrupts enabled so existing code should not be affected. My thanks to http://gammon.com.au/interrupts (the How are interrupts queued? section).

The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here.

Finally, direct download link is here

GreyGnome

Mon Oct 19 07:45:08 CDT 2015 Version 0.9.3 of the library has been released. Thanks to RobertClemenzi, who pointed out that "Useless.cpp" is not included with the distribution zip file.

The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here.

Finally, direct download link is here

GreyGnome

Fri Nov  6 19:13:20 CST 2015 Version 0.9.4 of the library has been released. Thanks to RobertClemenzi, who pointed out 2 bugs: 1. A spurious comma in some array definitions caused a compiler warning, and 2. More importantly, it was impossible to use arduinoInterruptedPin if this library was used to support other libraries.


The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here.

Finally, direct download link is here


Constantin

Hi GreyGnome,

First of all - many thanks for putting this awesome library together! Unfortunately, I seem to have a likely simple issue that I cannot resolve on my own, hence this request for help.

I am running Arduino 1.6.6 and am trying to compile the 1284p example from the library. As a target MCU, I have selected what I think is the latest version of the mighty 1284p @ 1 MBPS. When I try to compile, I get the error message that

Quote
Mighty1284p:96: error: #error This sketch supports 1284p-based Arduino-likes only.
 #error This sketch supports 1284p-based Arduino-likes only.
If I eliminate the IFDEF looking for the MIGHTY1284P in the 1284P example, then the example compiles. I presume that I need a updated version of the processor file to have that definition - where would I find it?

Constantin

Some quick notes,

When compiling the latest library (version 0.9.4) I got some compile errors for the 1284p highspeed.ino example. The source of the errors is allegedly in the <EnableInterrupt.h> file.

Line 1305 is missing a semicolon. I added some other lines following the pattern elsewhere in the file, resulting in the following  snippets.
Quote
#if defined MIGHTY1284
#ifdef INTERRUPT_FLAG_PIN10
  INTERRUPT_FLAG_PIN10++;
#endif
#endif
further down in what is now line 1358:
Quote
#if defined MIGHTY1284
#ifdef INTERRUPT_FLAG_PIN11
  INTERRUPT_FLAG_PIN11++;
#endif
#endif
and finally in what is now line 1398:
Quote
#if defined MIGHTY1284
#ifdef INTERRUPT_FLAG_PIN2
  INTERRUPT_FLAG_PIN2++
#endif
#endif
With these three changes, the program compiles, at least with the default PIN 8 designation. Change it to another pin like 29, and the program crashes again. The 'regular' (i.e. non-high-speed) EnableInterrupt works fine, BTW.

jim_beam

Hi
and first of all great thanks to GreyGnome for the EnableInterrupt Library!!  ;)

I have coded an rotary push button Encoder mit the IE-Lib. It works great. Now I am trying to build my own library for the rotary encoder starting with the  OOSimple.ino example and started to split/hide most Code into .h and .cpp files. But I need some advice on how to fit the interruptFunctions and Setup-Functions into .h and .cpp.

It's more a general question on OOP than on the IE-Lib implementation I guess, sorry for that.
Thank you very much in advance.

.ino
Code: [Select]
// EnableInterrupt OOSimple object-oriented example sketch.
// See https://github.com/GreyGnome/EnableInterrupt and the README.md for more information.

#include <EnableInterrupt.h>
#include "Simple.h"

void *simpleObject0; // this is numbered 0. You can create more, for example void *simpleObject1
void *simpleObject1;

// Modify this at your leisure. See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Summary


#ifdef __cplusplus
extern "C" {
#endif
// If you create more objects, you need to create more interruptFunctionN()'s
// that update their simple variables, for example interruptFunction1() .
void interruptFunction0() {
  updateSimpleVariable(simpleObject0);
}
#ifdef __cplusplus
}
#endif


void interruptFunction1() {
  updateSimpleVariable(simpleObject1);
}



void setup() {
  Serial.begin(115200);
  Serial.println("---------------------------------------");

  // If you want to enable more pins, you will need to recreate these 3 lines for
  // your new pin, object, and function.
  pinMode(ARDUINOPIN, INPUT_PULLUP);  // See http://arduino.cc/en/Tutorial/DigitalPins
  simpleObject0 = createSimple();
  enableInterrupt(ARDUINOPIN, interruptFunction0, FALLING);

  pinMode(ARDUINOPIN1, INPUT_PULLUP);  // See http://arduino.cc/en/Tutorial/DigitalPins
  simpleObject1 = createSimple();
  enableInterrupt(ARDUINOPIN1, interruptFunction1, FALLING);

//  Setup_Interrupts(*simpleObject0,*simpleObject1);

}

void loop() {
  delay(1000);                          // Every second,
  Serial.print(F("Pin 0: "));
  Serial.print(getSimpleVariable(simpleObject0), DEC);      // print the interrupt count.
  Serial.print(F(" Pin 1: "));
  Serial.print(getSimpleVariable(simpleObject1), DEC);      // print the interrupt count.
  Serial.println();
}

// Problem to fit/hide interruptFunctions and Setup-Functions in .cpp / .h


Simple.h
Code: [Select]

#ifndef SIMPLE_H
#define SIMPLE_H

#define LIBCALL_ENABLEINTERRUPT //https://github.com/GreyGnome/EnableInterrupt/blob/master/examples/SimpleWithLibrary/Useless.h
#include <Arduino.h>                            // general Arduino
#include <EnableInterrupt.h>

#define ARDUINOPIN 13
#define ARDUINOPIN1 12


class Simple {

  public:
    Simple() {
      init();
    }
    void updateSimpleVariable();
    uint8_t getSimpleVariable();

  private:
    volatile uint8_t _sv; // a simple variable. Notice that it is volatile.
    void init();
};

#ifdef __cplusplus
extern "C" {
#endif
void *createSimple();
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
uint8_t getSimpleVariable(void *anObject);
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
void updateSimpleVariable(void *anObject);
#ifdef __cplusplus
}
#endif

// This does not work!

//#ifdef __cplusplus
//extern "C" {
//#endif
//// If you create more objects, you need to create more interruptFunctionN()'s
//// that update their simple variables, for example interruptFunction1() .
//void interruptFunction0();
//#ifdef __cplusplus
//}
//#endif

// This does not work!
//void Setup_Interrupts(*simpleObject0,*simpleObject1);


#endif // SIMPLE_H


Simple.cpp
Code: [Select]
#include "Simple.h"

void Simple::init() {
  _sv=0;
}
void Simple::updateSimpleVariable() {
  _sv++;
}

uint8_t Simple::getSimpleVariable() {
  return _sv;
}

#ifdef __cplusplus
extern "C" {
#endif
void *createSimple() {
  return new Simple();
}
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
uint8_t getSimpleVariable(void *anObject) {
  return static_cast<Simple*>(anObject)->getSimpleVariable();
}
#ifdef __cplusplus
}
#endif


#ifdef __cplusplus
extern "C" {
#endif
void updateSimpleVariable(void *anObject) {
  static_cast<Simple*>(anObject)->updateSimpleVariable();
}
#ifdef __cplusplus
}
#endif

// This does not work!
//#ifdef __cplusplus
//extern "C" {
//#endif
//// If you create more objects, you need to create more interruptFunctionN()'s
//// that update their simple variables, for example interruptFunction1() .
//void interruptFunction0() {
//  updateSimpleVariable(simpleObject0);
//}
//#ifdef __cplusplus
//}
//#endif


// This does not work!
//void Setup_Interrupts(*simpleObject0,*simpleObject1 ){
//  // If you want to enable more pins, you will need to recreate these 3 lines for
//  // your new pin, object, and function.
//  pinMode(ARDUINOPIN, INPUT_PULLUP);  // See http://arduino.cc/en/Tutorial/DigitalPins
//  simpleObject0 = createSimple();
//  enableInterrupt(ARDUINOPIN, interruptFunction0, FALLING);
//
//  pinMode(ARDUINOPIN1, INPUT_PULLUP);  // See http://arduino.cc/en/Tutorial/DigitalPins
//  simpleObject1 = createSimple();
//  enableInterrupt(ARDUINOPIN1, interruptFunction1, FALLING);
//}



GreyGnome

Please use Github for support. See https://github.com/GreyGnome/EnableInterrupt/issues

For some reason I am not getting emails when posts are made to this thread; in any event, this is the announcement thread.

Thanks.

GreyGnome

Wed Apr 27 18:07:02 CDT 2016 Version 0.9.5 of the library has been released. Added the arduinoPinState variable, which is available when EI_INTERRUPTED_PIN is defined. Added support for platformio http://platformio.org/ (thanks dorkusprime!).

The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here. Issues can be raised here.

Finally, direct download link is here

GreyGnome

Fri May  6 07:32:38 CDT 2016 Version 0.9.7 of the library has been released.
Fixed a compile error for the ATmega1284p. I realize that my testing procedures were flawed. Fixed that too. And from 0.9.6, which barely saw the light of day: Fixed a couple of bugs: update of the arduinoPinState variable in the External interrupts, and a major bug affecting interrupts on ports C and D on 1284p chips.

The library is available in the Arduino 1.6.x  IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here. Issues can be raised here.

Finally, direct download link is here

GreyGnome

Fri Sep 22 17:45:34 CDT 2017 Version 0.9.8 of the library has been released. There were a number of outstanding pull requests that were merged into the library. Thanks to Loranzo Cafaro for his switch debounce example, to Jevon Wild for his changes to make the library more functional with PlatformIO (http://docs.platformio.org/en/latest/what-is-platformio.html), Ricardo JL Rufino for some PlatformIO fixes to the library.json file, and Sara Damiano for adding support for the Sodaq Mbili and EnviroDIY Mayfly.

The library is available in the Arduino 1.6.x  (and above) IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here. Issues can be raised here.

Finally, direct download link is here

GreyGnome


Version 1.0.0 of the library is released! From the Release Notes:
_What's New?_ Fri Jun 22 06:49:57 CDT 2018 Alex Reinert contributed Bobuino support. Thanks, Alex! And at this point, I think it's long past due that we stick a non-beta sticker on this thing. Congratulations, EnableInterrupt- you are all grown up. Version 1.0.0 it is.

As always, if you see any issues with the library, post a bug report in the issues area (below). I have been much less active in the Arduino world lately, but I keep half an eye on it and promise to respond. And if you want, you can pay me to work on Arduino full time in which case I'll get on it immediately! But, barring that...


The library is available in the Arduino 1.6.x  (and above) IDE Library Manager (from the Sketch Menu -> Include Library -> Manage Libraries).

The library's home page is here. See the wiki here. Usage information can be found here. Issues can be raised here.

Finally, direct download link is here

Go Up