davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Forcing GPIO2 state after shutdown

Sun May 20, 2018 9:58 pm

Is it possible?

I'm using physical pin 3 (GPIO2/SDA1) on the rpi zero W header to control a LED. The pin is connected to the gate of a FET, so the LED is on when the pin is high.

I want the LED to go off when the pi is shutdown. It would also be nice if the LED was off at power up, until my code turned it on, but I can get it off pretty fast at power up. Having the LED on after shutdown is confusing to users of my gadget.

I've read in posts that the GPIO retain their current state after shutdown, but I can confirm this isn't true. I config the pin to be and output and set it zero using wiringPi (gpio). The LED is off until I execute "sudo shutdown -hP now" . Then the LED goes low.

Changing to a different pin would be painful. I'd have to turn another pass of the pcb.

Can dt_overlay be used in /boot/config.txt to control what state pin 3 will be at shutdown? Can I mess with the device tree somehow to get what I want?

Thanks!

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Forcing GPIO2 state after shutdown

Sun May 20, 2018 11:46 pm

Maybe this will work...

Use gpio-poweroff on a different pin. If I understand the posts I've read, Ican put a line like this:

Code: Select all

dt_overlay=gpio-poweroff,pin=6
in /boot/cmdline.txt.

So, with this overlay, if I write to the pin (1 if I choose activeHigh), power will removed from all gpio? So, all GPIO will be in (hi z)?

This might work for what I want. Not ideal, since the gate of the FET that controls the LED would be floating, but leakage would probably pull it low. I could hack a pulldown resistor if needed.

Note, it doesn't help that 3.3V goes low, since the anode of my LED is on 5.0, not 3.3V.

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 5:21 pm

I added this line:

Code: Select all

dt_overlay=gpio-poweroff,gpiopin=2,active_low=1
to /boot/config.txt

But, the pin (header pin 3, GPIO2/SDA1) still goes high after doing a shutdown.

Do I have the pin number correct? I should use the BCM physical pin number?

Is my expectation correct? This should result in the pin going low at shutdown?

User avatar
DougieLawson
Posts: 33630
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 6:34 pm

Every pin number in /boot/config.txt is the GPIO numbering scheme.GPIO2 is used for the I2C interface (and has a 1.8Kohm external pull-up), you may want to pick a different pin.

https://pinout.xyz should help you find them.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 6:59 pm

Like I said in the first post, changing to a different pin would be painful.

Yes, I understand GPIO2 is used for I2C (that's why I said GPIO2/SDA1). But, I'm not using I2C.

Are you saying the gpio-poweroff overlay not work for this pin? Or, just suggesting I try a different pin as an experiment.

If the latter, good suggestion and I'll do so.

Also, I AM using the I2S pins for a DAC, but those don't include GPIO2. I tried commenting the dtoveraly for the DAC in /boot/config.txt, but it made no difference wrt the pin going high at shutdown:

Code: Select all

#dtoverlay=hifiberry-dac
dt_overlay=gpio-poweroff,gpiopin=2,active_low=1

User avatar
DougieLawson
Posts: 33630
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 7:13 pm

With a 40-pin header I always start at physical pin#29 and work down to pin#40 (GND pins excluded). They're never used by systems functions (I2C, SPI, UART, etc.) as they didn't exist on the original 26-pin RPi1B.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 7:54 pm

Are you saying the gpio-poweroff overlay not work for this pin? Or, just don't know?

User avatar
DougieLawson
Posts: 33630
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 8:33 pm

I don't know because I've never had a desire to test gpio-poweroff (because all 15 of my raspberries run 24/365.25). I was just giving general advice to start from pin#29 and upwards as those pins are less likely to conflict with other pin uses.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Forcing GPIO2 state after shutdown

Mon May 21, 2018 9:39 pm

Yes, if the pcb you're designing in not space constrained, that's a good rule of thumb. But, my pcb uses the space where a gpio connector would be for components. It's more space efficient using the pins near the +5 side of the header, if you need +5 anyway. I only have to loose at little space for a couple pins at each end of the connector (+1 in the middle for I2S).

So, it would really nice to know what limitations exist (if any) for configuration of the GPIO pins, rather than just avoiding them because they can be configured for something like I2C.

GPIO2 actually defaults as an input with a pull-up, but there's no issue configuring it as an output. So, I'll be surprised if it's "special" wrt gpio-powerdown.

I'll try another pin as a test.

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 2 guests