buteman
Posts: 146
Joined: Tue Jul 03, 2012 9:06 am
Location: Barrow upon Humber

Setting a GPIO pin as output and high at boot.

Tue Feb 21, 2017 11:24 pm

I am not new to linux but I am trying to get details of GPIO. I have do some python stuff using a Pi 3 as the brains of a wheeled robot and various other things so I have no problems with that. I am using Raspian
What I am trying to find out is how early in the boot process I can set a pin to output and high and leave it that way until I shut the Pi down. As it shuts down, as late in the process as possible, I want to set the output low.
What I am wanting is to build a unit which keeps power on to the Pi while that pin is high and then remove power a few seconds after it goes low.
I expect I need to know how many seconds power has to be supplied manually until the pin goes high.
Can anyone give me some idea where to look please?
There are few rewards greater than accomplishing a difficult task. Just because something doesn't cost money doesn't mean there is no cost. Every success makes the next one easier. Of course that takes determination and patience.

User avatar
rpdom
Posts: 19170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Setting a GPIO pin as output and high at boot.

Wed Feb 22, 2017 6:41 am

You could set the gpio-poweroff option in /boot/config.txt. That can set almost any gpio pin to go high (or low) early in the boot sequence, and change state to low (or high) when it is safe to remove power.

You must use the BCM numbering for the gpio pins.

For example, to set physical pin 16 (BCM 23) high during boot and then go low when shutdown is complete, you'd use

Code: Select all

dtoverlay=gpio-poweroff,gpiopin=23,active_low
If you don't specify a gpiopin= it will default to 26 (physical pin 37).

If you don't put 'active_low' it will go low at boot time and go high when shutdown is complete. 'active_low' reverses that value.

buteman
Posts: 146
Joined: Tue Jul 03, 2012 9:06 am
Location: Barrow upon Humber

Re: Setting a GPIO pin as output and high at boot.

Wed Feb 22, 2017 4:51 pm

Great thanks, that looks as if it's exactly what I need. So I guess I will design and built a circuit for it to control.
Once I get it working I will post it somewhere so anyone else who might want this can use it.
There are few rewards greater than accomplishing a difficult task. Just because something doesn't cost money doesn't mean there is no cost. Every success makes the next one easier. Of course that takes determination and patience.

Return to “Beginners”