Wake Arduino from 4 buttons.

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kshepitzki
 
Posts: 2
Joined: Sun Nov 19, 2017 10:52 am

Wake Arduino from 4 buttons.

Post by kshepitzki »

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

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Wake Arduino from 4 buttons.

Post by adafruit_support_mike »

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.

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

Re: Wake Arduino from 4 buttons.

Post by kshepitzki »

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?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Wake Arduino from 4 buttons.

Post by adafruit_support_mike »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”