Hey folks!
I nailed my problem pretty much down so I hope you guys can help me now because I think I’ve tried everything, you know how it is
Short Story
attachInterrupt(2, foo, FALLING) doesn’t work on D0 like it should on Fio v3 based on this http://arduino.cc/de/Reference/AttachInterrupt and assuming Fio v3 ~ Leonardo. Whereas it works on UNO with 0 as argument on D2.
Long Story
What I’m trying to achieve is to make a MPR121 Sensor work with the Fio v3 based on this code:
https://github.com/labatrockwell/arduin … sor_MPR121
I got it working with the UNO, so my next step was to check out the correct pins for the Fio v3, like SDA goes to D2, SCL on D3 etc. Here I referred to this Schematic:
http://dlnmh9ip6v2uc.cloudfront.net/dat … io-v30.pdf
The main question where I had to do some research was where to map the interrupt to because with the original code
attachInterrupt(0, foo, FALLING);
Resource: https://github.com/labatrockwell/arduin … mpr121.ino
I’d need to hook it up to D2 which now is used as SDA - so just set it to a free one right?! No.
That’s where I’m currently stuck, I adapted the above code to
attachInterrupt(2, foo, FALLING);
and connected the IRQ wire to RXI / D0 Pin on my Fio v3 but it’s not working. Do you have any idea how to debug this or what I could’ve done wrong here?
P.S.: I also stumbled upon this issue http://forums.adafruit.com/viewtopic.php?f=19&t=45652 but I’m not sure how far it’s related. Just read in there that the Fio v3 board layout seems to be wrong so I used the pins_arduino.h one of the users links to with no effect (here: https://github.com/pauschu/SF32u4_board … _arduino.h).
After further testing I see following behaviour. If I set the interrupt to 0 I can interrupt on D2, all the other pins like suggested on Sparkfun Fio v3 Hookup Guide (see quote below please) are not working for me.
The Fio v3 has five external interrupts, which allow you to instantly trigger a function when a pin goes either high or low (or both). If you attach an interrupt to an interrupt-enabled pin, you’ll need to know the specific interrupt that pin triggers: pin 3 maps to interrupt 0, pin 2 is interrupt 1, pin 0 is interrupt 2, pin 1 is interrupt 3, and pin 7 is interrupt 4.
https://learn.sparkfun.com/tutorials/pr … iew-fio-v3
Is Pin 3 actually D2 on the Fio v3 or should this be D3 because otherwise this is completely messed up Since I need D2 and D3 for I2C communication I need to make use of another interruptable pin which I can’t get to work at the moment. Has anyone of you guys got interrupts working on pin 7 f.e. or any other than 2 & 3.
Thanks in advance and happy making!
It seems the v3 Fio uses the 32U4 MCU and so should have the same pin mapping for interrupts as does a Leonardo or a SFE ProMicro or Arduino Micro. I have a Micro and have used both the int0 and int1 interrupts.
http://arduino.cc/en/Reference/AttachInterrupt
Leonardo & Micro - D3/int0, D2/int1, D0/int2, D1/int3, D7/int4
I’ve not tried the others and given that int4 has some odd special handling per the 32U4 PDF, I’d worry that the base Arduino core functions can actually use it. I can certainly do a quick test of pins 0 and 1 and see if the ext interrupts work … but then so can’t you. Light the onboard LED if int0 occurs. Extinguish it if int1 occurs. Write both ISRs to trigger in the falling edge and use the internal pull-ups. Touch a ground wire to each pin and see what happens.
EDIT : In fact I just did the above and they (even D7/int4) work. Here’s the .ino file used ;
//basic code to test interrupts
void setup(){
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
Serial.begin(9600);
attachInterrupt(2, ISRpin0, FALLING);
attachInterrupt(3, ISRpin1, FALLING);
}
void loop(){
Serial.print("Pin0 is ");
Serial.println(digitalRead(0));
Serial.print("Pin1 is ");
Serial.println(digitalRead(1));
delay(1000);
}
void ISRpin0(){
digitalWrite(13, HIGH);
}
void ISRpin1(){
digitalWrite(13, LOW);
}
Hi, first off I’d like to thank you for your effort and time. I used the internal pull-ups like you suggested and I can also measure that this is working correctly on pin 0 and 1 or as labeled on the board RX and TX. Unfortunately int2 and int3 are not working for me because when touched with a grounded wire nothing happens. Neither is my Serial message printed nor the LED is lit or turned off like I defined in the to be triggered functions. I also tested it with a device fresh from the box and came to the same result so I can rule an hardware issue out. If anyone also owns an Arduino Fio v3 and could test this or got it working already, I’d be grateful if you could help me here as it seems the Micro and Fio v3 are different in this point. This is the complete code I based my testing on:
void setup(){
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(13, OUTPUT);
Serial.begin(9600);
attachInterrupt(2, fu, FALLING);
attachInterrupt(3, bar, FALLING);
}
void fu() {
Serial.println("fu");
digitalWrite(13, HIGH);
}
void bar() {
Serial.println("bar");
digitalWrite(13, LOW);
}
void loop() {}
Count me as confused. I looked at the schematics for the FIO v3 and the Micro and the same 32U4 pins are connected to the same D0-D3 pins as on the other. So unless the pin mapping is somehow AFU in the description table used when you choose your board in the IDE … I don’t see how it works on my Micro and not on your FIO. Could you “lie” and tell the IDE that your FIO is a Micro, and see what happens ??
:dance: Bingo, that was it. Though I can’t establish a serial connection - probably because I chose “Arduino Micro” as the board to upload to - I can see the wire-test working and therefore the interrupts. Does that mean the pin mapping is wrong and if so can we fix it by editing the pins_arduino.h file for the Fio v3?
davidphilip:
Does that mean the pin mapping is wrong and if so can we fix it by editing the pins_arduino.h file for the Fio v3?
Honestly I don't know. I'll guess the IDE is still using a non v3 description for the Fio, a 328p MCU vs the 32U4, so there may be more screwed up than just the pin mapping. OTOH now that you have some clue as to what's wrong, and given someone else must have run across this problem before, perhaps Google can now find the answer.
FWIW: https://learn.sparkfun.com/tutorials/pr … ng-windows
Ha! Updating the addon files for Fio and Micro (https://github.com/sparkfun/SF32u4_boar … master.zip) in the hardware folder resolved the issue. Looks like my versions were outdated and the ones I already tried to update them with before — also from github — were too. Thanks for your help and happy making folks!