
Tech-One (Customer) asked a question.
How to use interrupts on the P1AM-100
I am having problems getting interrupts to work on the P1AM-100 The same code works fine on the ARDUINO UNO. I just change the pin assignments. I am using a rotary encoder switch and i can not get interrupt function to work.
Can you post a picture of your wiring as well?
I just re-read your code and I think your issue is actually the order of your GPIO setup statements. I believe you have to declare your pins as inputs before the attachinterrupt function. Try changing your code like below and let me know if that fixes it.
Hi AdamC,
Yes that corrected my problem. Thank You, I appreciated you helping me.
When I run the program the encoder count does not count every click and some times count in reverse. would you happen to know of a better way to decode an encoder ?
Best Regards
Tech-One
It's a little harder to diagnose that without it in front of me. The first thing I'd try is to debounce your signals(either in hardware or software, plenty of guides out there on both) to make sure any chatter on the switching isn't causing what you're seeing.
Another option is to consider the P1-02HSC module. It's setup to capture quadrature signals like from a rotary encoder.
Thanks
Adam
Please see attached drawing of the Rotary Encoder Switch Wiring.
Thank You
Thanks for the diagram! I'd try the code change from my other comment. If that doesn't work, could you share the actual part number for the encoder?