[SOLVED] Arduino Due interrupts: not working!

Hello people,
I have an Arduino Due board and I’m trying to build a RPM counter for my engine.
Anyway the DUE board is not managing the interrupts, this is a simple sketch to verify the interrupt counter:

int pin = 3;
volatile int i = 0;

void test() { i++; }

void setup() {            
  Serial.begin(9600);   
  pinMode(pin, OUTPUT);
  attachInterrupt(pin, test, FALLING); 
}

void loop() {
  digitalWrite(pin, HIGH);
  Serial.print("Pin high, count="); Serial.println(i);
  delay(500);
  digitalWrite(pin, LOW);
  Serial.print("Pin low, count="); Serial.println(i);
  delay(500);
}

The count is always to 1.
I am running the latest available Arduino IDE 1.5.5 beta on Windows 7 x64.
Any help and suggestions are appreciated, thank you in advance,

kalo86

I think it might help to have the pin you define the interrupt for as INPUT. (it might just be necessary for the attachInterrupt command and you can change it afterwards)

schwingkopf: I think it might help to have the pin you define the interrupt for as INPUT. (it might just be necessary for the attachInterrupt command and you can change it afterwards)

Hi, thank you for the replay. I just tried with INPUT mode but the counter is always at 1. It's sad =(

The interrupt pin has to be defined as INPUT(otherwise it won’t recognize an interrupt). The pin that you want to change state of has to be define as OUTPUT (otherwise it won’t toggle its output state). Therefore you need to define two pins, one for INPUT one for OUTPUT and connect them on your board. Then it works perfectly. There is nothing wrong with your code otherwise (tested it).

The Due has a completely different way of handling GPIO pins, you can't assume it will be the same as the Uno etc...

Kalo86,

I've found a few problems with the interrupts on the due, possibly due to bugs the arduino library (I've filed an issue on github).

You can find a couple of workarounds in my post here, which should get your example working:

http://forum.arduino.cc/index.php?topic=199320.0

regards,

Robin

I'm sorry but I did all my tests without any electonic component connected to the arduino due pins, maybe for this reason the counter was always at 1. Since I connected the hall sensor with a test led, the counter now increases. I'm sorry, again. Now I am going to add the "solve" word to the topic. Regards,

kalo86