0

Wake Arduino from 4 buttons.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Wake Arduino from 4 buttons.

by kshepitzki on Sun Nov 19, 2017 10:53 am

I am working on a project using ATmega328 that requires waking up from sleep mode using button presses. Several articles explain how to do that by connecting the button to the interrupt line INT0 or INT1.

However I have 4 SPST buttons but only 2 interrupt lines. Each button needs to be able to wake the controller and as it wakes up the controller needs to know (e.g. by reading digital pins) which button was pressed.

The project is single battery operated so needs to be very energy efficient.
I am embedded SW eng', so I understand HW if explained slowly :-)

Any suggestions for a simple HW solution?

I look forward to your solutions

kshepitzki
 
Posts: 2
Joined: Sun Nov 19, 2017 10:52 am

Re: Wake Arduino from 4 buttons.

by adafruit_support_mike on Mon Nov 20, 2017 1:22 am

You can use pin-change interrupts instead of the edge- or level-based interrupts.

The pin-change interrupt is sort of a catch-all for signal input. It doesn't tell you whether the signal that changed was a rising or falling edge, just that something happened. There's also a single interrupt handler for all the pins that have the interrupt enabled.

For general wake-up, you shouldn't need much more than the interrupts themselves. The CPU has to start running just to reach the ISR. If you want to identfy the specific pin that changed, you'll have to keep track of the pin values before you sent the microcontroller to sleep, and read all the pins in the ISR to see which one changed.

adafruit_support_mike
 
Posts: 45941
Joined: Thu Feb 11, 2010 2:51 pm

Re: Wake Arduino from 4 buttons.

by kshepitzki on Mon Nov 20, 2017 1:53 am

Thanks Mike but how do I wire up 4 buttons such that on the one hand they all connect to the same interrupt pin but on the other hand they all separately connect each to a separate digital input line?

kshepitzki
 
Posts: 2
Joined: Sun Nov 19, 2017 10:52 am

Re: Wake Arduino from 4 buttons.

by adafruit_support_mike on Tue Nov 21, 2017 1:29 am

That's handled inside the microcontroller.

A pin-change interrupt watches up to 8 pins at the same time. If a signal connected to any of those pins changes, the interrupt handler will fire.

The tradeoff is that the pin-change interrupt doesn't tell you which signal changed.. all the interrupt tells you is 'at least one of them changed'. For what you want to do.. waking up the microcontroller when any button is pressed.. that's all you need to know.

adafruit_support_mike
 
Posts: 45941
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.