interrupts and rotary encoders

i am following the playground article on the rotary encoder interrupt usage.

i am having trouble understanding the basics of interrupt usage...
this is taken from the comment for the code

/* read a rotary encoder with interrupts
Encoder hooked up with common to GROUND,
encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below)
it doesn't matter which encoder pin you use for A or B

uses Arduino pullups on A & B channel outputs
turning on the pullups saves having to hook up resistors
to the A & B channel outputs

*/ (my underlines)
from the reference it clearly states that interrupts ONLY work on pin 2 and 3, but in Paul comment he mentioned that i can use any of the digi inputs. so, those this mean i have only to interrupt "boosted" inputs (2&3)? or are they some kind of control pins, which i can use with any other pin?

thanks to all that contributed to that article!
Max and Paul Badger

i'd say that he means it does not matter if you connect your encoder's pin "A" to arduino's port 3, and "B" to 4 or the other way around.

you're right that interrupts only work on pin 2 and 3. Paul's code only uses one interrupt on pin2, and "just reads" the value from pin4. Basically that means you could read a second rotary encody using the interrupt functionality of pin 3 plus any other digital in.

i hope this helped.

best, kuk

ps: by just having one channel triggering an interrupt you only get half of the resolution of your encoder. If you need the full resolution you have to use two interrupts per encoder.

thanx. i have another inturrupt question.
i find i cannot call a serial.print from both the loop function and the interrupt at the same time.
any specific reason?

interrupts do (as their name implies) interrupt you program. that means, they might easily stop your program from running at all.
that is if you interrupt too often and your interrupt routine can't even finish before the next interrupt is triggered.

you shouldn't send serial messages from within the interrupt routine. keep it as simple as possible. keep it as fast as possible. count your values and give the control back to the main loop.

if you need to send a serial message when an interrupt occured, set a variable (interrupt_did_happen=true) and then send the message from within the main loop:

if (interrupt_did_happen ){
//send message here
}

again, i hope this helps. if not, it might be good to post some code. or maybe try to explain what you want to do. this was just a shot in the dark (though i know what my difficulties with interrupts were).

//ku k