Arduino MEGA2560 INT0 INT1 (NOT INT4 INT5 when attachInterrupt

I came across the need to use Interrupts on digital Pins 2 and 3, but couldn't get my code to work. After extensive searching, I found out that I was NOT USING THE CORRECT INT number. I was using INT4 and INT5 for Pins2 and 3 respectively, when I should have been using INT0 and INT1 (I got the INT4 and 5 info from the MEGA2560 DATASHEET Pinout, but the INT0 and 1 required extensive searching. I finally found a discussion in 2017 on GITHUB).
My question, WHY is there still NO MENTION of this fact in the PINOUT diagrams of the DATASHEET (Digital I/O Pin 2, PWM, PE4, Pin6, labeled "(OC3B/INT4)PE4")? I know if i read the DATASHEET from cover to cover, I might find the answer (or at least figure it out), but my FIRST goto source is internet search, and second is a drawing (because it is a good overall reference, although not perfect). It just seems to me a tiny asterisk, with a note somewhere near the bottom could have saved me a lot of aggravation. Just venting by the way, and hoping that someone else finds this in their search for the true interrupt numbers.

2 Likes

You should look at the Arduino language reference at the attachInterrupt reference.

Use the digitalPinToInterrupt(pin) function.

2 Likes

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