Putting A-Star 328PB Micro to sleep

Hey, I am currently building a project with a few sensors on the A-Star 328PB Micro. I am also using the arduino ide and trying to figure out how to power the microcontroller to sleep and back to normal mode. I can’t find much documentation or anything to figure it out. I was hoping someone could point me in the right direction of learning how to do this.



Unfortunately, we do not have any example programs or specific guides for how to do that. The starting point for that would be to go over the “Sleep Modes” section (13.2) of the ATmega328PB datasheet, which is available on each A-Star 328PB product page under the “Resources” tab. That includes descriptions for each of the possible sleep modes and has instructions for how to enter and exit the sleep modes. The procedure requires manipulating the registers, so if you have never done programming like that before you might try looking up and going through some more general guides/tutorials about that first.

- Patrick

Actually, a better approach would probably be to use the sleep functions from the avr-libc library which is included in the Arduino environment. That should be easier than working with the registers directly.

By the way, it might also be useful to use some of these power management functions to disable unneeded peripherals before putting the microcontroller to sleep.

- Patrick

1 Like

I will check this out and am currently playing around with it. Have just started, but if I have any issues I will post them here. Thanks for the links!

Hey Patrick, I do have a question to clarify something. The interrupts on this product Pololu - A-Star 328PB Micro - 3.3V, 8MHz are only pins 2 and 3, or can they all be used? I am a bit confused because each pin has a PCINT section and I am not sure what that means.

Sorry, another quick question. I got the sleep powering on and off happening through the tutorial you linked above. Thanks so much. But I currently have encoders connected to both interrupt pins. As far as I was aware encoders needed interrupts and I am using them both, or can I move the encoders onto other pins to use the sleep function on the interrupt?

PCINT means pin change interrupt. They are similar to the external interrupts that it sounds like you are already used to, but there are some important differences. This blog post gives a good overview of what pin change interrupts are and how to use them. It should be possible to move both your encoders and your trigger for putting the A-Star in sleep mode over to pin change interrupts if you want to.

- Patrick