Adding power led switch to Adafruit I2S Audio Bonnet

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

Hello community

Im making an airplay audio receiver for the Adafruit I2S Audio Bonnet with a raspberry pi zero w2

I would like to power on and off the pi using a Rugged Metal Pushbutton with White LED Ring

Anyone could guide me or send me a link to make this happen sending the power through the bonnet into the pi?

Thanks!

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

Here's instructions on how to safely shut down the Pi using a switch: https://www.makeuseof.com/tag/add-power ... pberry-pi/

Note that this doesn't disconnect power, it shuts down the Pi in response to a button press. You can then safely disconnect power. To restart the Pi you would have to disconnect and reconnect power.

Pay special attention to the section labelled The Importance of Safely Powering Down.

Dave

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

Thank you Dustels

Would this work doing it from the bonnet i mention?

if so which pins should i use?
Thanks

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

The article specifies pins 39 and 40, but 40 is used by the bonnet. Pin 38 is unused (GPIO20) It's the pad labelled "20" to the right of the header connector (above the Adafruit logo). One side of the switch goes to that and the other side goes to ground (there are ground connections at the far left of the bonnet), labelled "G".

Dave

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

hello thanks for the reply

i followed your guides but with no result

I changed in the code to gpio 20 instead of 21 as well

what should i try?

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

Does sudo poweroff shutdown the Pi when you execute it from the command line?
At the python3 RE, does

Code: Select all

import os
os.system("sudo poweroff")
shutdown the Pi?
Did you make sure that the line you added to /etc/rc.local reflects the location of shutdown-press-simply.py?
Does executing shutdown-press-simply.py from the command line work as expected?
If you replace os.system("sudo poweroff") with an output (e.g. print("Hello")) does it print "Hello" when you push the button?
Can you post a clear photo(s) of your connections to the bonnet?

This is clearly not our guide. I just did a bit of googling and this seemed like a reasonable solution.

Dave

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

Thanks for the patience and help

Running the command using sudo in the terminal works

i will try the options you mention

for now here is a picture of my conections
Attachments
IMG_0679.jpg
IMG_0679.jpg (728.85 KiB) Viewed 94 times

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

everything seems normal since shutdown-press-simply.py is in pi directory ( which is the main right?)

but i noticed when i try to run these the following appears:
Attachments
Screen Shot 2022-08-11 at 3.42.28 PM.png
Screen Shot 2022-08-11 at 3.42.28 PM.png (12.96 KiB) Viewed 90 times

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

First that soldering/wiring is a short waiting to happen. The button doesn't need that massive wire. It's just grounding a logic input so any small gauge hookup wire will do; it should go through the hole with no exposed with above the board and any excess clipped off the bottom after soldering. You have so much bare stranded wire exposed that it's just asking for trouble. See https://learn.adafruit.com/adafruit-gui ... -soldering and https://learn.adafruit.com/collins-lab-soldering.

What if you try

Code: Select all

./shutdown-press-simple.py
when cwd is ~ or

Code: Select all

~/shutdown-press-simple.py
/home/pi is simply the home directory of the default account. That it's a default account is the only special thing about it. Making yourself a new account and get rid of the pi account is usually the first thing to do when installing a new RaspberryPi. The pi account is an easy way to break into a Pi since every new Pi install has it.

Dave

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

Thank you for all the considerate suggestions, i will work on the wiring and soldering.

when i try this

CODE: SELECT ALL | TOGGLE FULL SIZE
./shutdown-press-simple.py
when cwd is ~ or
CODE: SELECT ALL | TOGGLE FULL SIZE
~/shutdown-press-simple.py

on the terminal nothing happens just blank

this is how the terminal of the nano shutdown-press-simple.py looks like
Attachments
Screen Shot 2022-08-11 at 6.08.08 PM.png
Screen Shot 2022-08-11 at 6.08.08 PM.png (43.77 KiB) Viewed 85 times

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

"on the terminal nothing happens just blank"

Do you mean it just sits there or do you get the prompt back?

You need to press the button for it to execute the power down. Otherwise it will just sit there waiting.

Dave

User avatar
Ignaciogaticarojas
 
Posts: 10
Joined: Wed Feb 23, 2022 10:56 am

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by Ignaciogaticarojas »

It just sits there like in the picture. When i press the button nothing happens
Attachments
Screen Shot 2022-08-11 at 7.21.44 PM.png
Screen Shot 2022-08-11 at 7.21.44 PM.png (11.61 KiB) Viewed 77 times

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding power led switch to Adafruit I2S Audio Bonnet

Post by dastels »

You might have a wiring problem. double check. See if you can read the state of the button input. Printing it out in a loop will quickly show if the button is being seen.

This should do it if you change the button number accordingly.

Code: Select all

from gpiozero import Button

button = Button(2)

while True:
    if button.is_pressed:
        print("Button is pressed")
    else:
        print("Button is not pressed")
Dave
Last edited by dastels on Thu Aug 11, 2022 8:02 pm, edited 1 time in total.
Reason: Add code

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

Return to “General Project help”