Created Thu, 03 Mar 2016 04:06:51 +0000 by jwzumwalt
Thu, 03 Mar 2016 04:06:51 +0000
How2 interrupt attachInterrupt()
Postby jwzumwalt » Tue Mar 01, 2016 4:37 pm I am trying to get attachInterrupt() to work in Pinguino. The interrupt is supposed to toggle the LED at reqular intervals.
The Arduino format for using attachInterrupt() is shown at
https://www.arduino.cc/en/Reference/AttachInterrupt
a simple example is shown
I tried 1 thru 14 for the interrupt number without success... any ideas?
int pin = 13;
int state = LOW;
void blink() {
state = !state;
}
void setup() {
pinMode(pin, OUTPUT);
attachInterrupt(<1 thru 14>,blink,LOW);
}
void loop() {
digitalWrite(pin, state);
}
How do I have an external pin event trigger a interrupt routine? I'm not picky about /RISING/FALLING, I'll settle for anything.
Sat, 05 Mar 2016 00:53:54 +0000
Check out the first example on this page - maybe it will help you : https://github.com/fubarino/fubarino.github.com/wiki/Code-Examples
*Brian
Sat, 05 Mar 2016 05:41:12 +0000
Check out the first example on this page - maybe it will help you : https://github.com/fubarino/fubarino.gi ... e-Examples *Brian
After reviewing the above example you provided, it appears that the attachInterrupt() is not working with Pinguino. Can anyone else confirm this
Sat, 05 Mar 2016 12:46:28 +0000
The attachInterrupt works fine with the Pinguino micro.
I have tested all 5 interrupts and found where they are connected to:
Sun, 06 Mar 2016 23:49:20 +0000
Would you please post the program listing you used? thx
Mon, 07 Mar 2016 00:48:57 +0000
I don't have it now, but I will see if I can recreate it here:
void setled() {
static bool lval = false;
lval = !lval;
digitalWrite(26, lval);
}
void setup() {
pinMode(26, OUTPUT);
attachInterrupt(0, setled, FALLING);
}
void loop() {
}
If I got the LED pin number right then pressing the user button should toggle the LED.
Mon, 07 Mar 2016 07:18:54 +0000
The above code did not seem to work. I modified the program to see if it was working and it does appear to lock up.
int lval = 0; int state = 0; void setled()
void setup() { pinMode(10, OUTPUT); pinMode(13, INPUT); attachInterrupt(0, setled, FALLING); }
void loop()
Mon, 07 Mar 2016 08:38:48 +0000
Salut,
I tested it on my Olimex PIC32-Pinguino-Micro:
volatile int state = 1;
void blink() {
state = !state;
}
void setup() {
pinMode(PIN_LED1, OUTPUT);
pinMode(PIN_LED2, OUTPUT);
attachInterrupt(0, blink, FALLING);
}
void loop() {
digitalWrite(PIN_LED2, state);
digitalWrite(PIN_LED1,!digitalRead(PIN_LED1));
delay(500);
}
Pushing the button will toggle the led, the second LED is only used to show that the processor is working (simple blink)
I hope, this helps.
Ciao, Mathias
Mon, 07 Mar 2016 15:45:02 +0000
YAHOOO!!!
It worked!
I did rearrange things to prove to myself the interrupt routine was doing the work Thanks, everyone for the help.
// green led blinks using loop delay.
// yellow led toggles if button pushed using interrupt routine
int state = 1;
void blink() {
state = !state;
digitalWrite(PIN_LED2, state);
}
void setup() {
pinMode(PIN_LED1, OUTPUT);
pinMode(PIN_LED2, OUTPUT);
attachInterrupt(0, blink, FALLING);
}
void loop() {
digitalWrite(PIN_LED1,!digitalRead(PIN_LED1));
delay(500);
}
Mon, 07 Mar 2016 16:18:19 +0000
Great!
The Olimex documentation is a bit confusing as it refers to it more from a Pinguino point of view.
Ciao, Mathias
Mon, 07 Mar 2016 16:36:15 +0000
I primarily use the Pinguino.cc IDE and I just discovered that half my problem is UECIDE IDE and Pinguino.cc IDE do not use the same pin assignments. For example Pinguino.cc uses pin 32 for the green LED but UECIDE does not recognize this. However, I was able to confirm that this function works with UECIDE but DOES NOT WORK WITH PINGUINO.CC
I assume, but could not verify this function works with Mpide because Mpide requires a different bootloader.
Mon, 07 Mar 2016 17:00:54 +0000
You cannot use the Pinguino Micro with MPIDE unless you either replace the bootloader or re-program MPIDE to use pic32prog in the right way and also compile with the special Pinguino Micro linker script.