Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.15.0 is available! For more information about this release, check out this topic.

    Physical button

    Hardware
    5
    10
    4412
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PointPubMedia
      PointPubMedia last edited by

      Hey guys…

      Anyone use physical button on a Raspberry Pi … if yes… which one you buy?

      yawns 1 Reply Last reply Reply Quote 0
      • lolobyte
        lolobyte last edited by

        Some old reset buttons from scrapped computer.

        Works well an they are small.

        PointPubMedia 1 Reply Last reply Reply Quote 0
        • yawns
          yawns Moderator @PointPubMedia last edited by

          @PointPubMedia said in Physical button:

          Hey guys…

          Anyone use physical button on a Raspberry Pi … if yes… which one you buy?

          Try searching for “push button” on ebay or other online shops. Just make sure it is a momentary push putton which does not latch

          1 Reply Last reply Reply Quote 0
          • PointPubMedia
            PointPubMedia @lolobyte last edited by

            @lolobyte said in Physical button:

            Some old reset buttons from scrapped computer.

            Works well an they are small.

            So that means the maximum is only 1 button ?

            J 1 Reply Last reply Reply Quote 0
            • J
              Jopyth Moderator @PointPubMedia last edited by

              @PointPubMedia You can connect multiple buttons to the PI.

              lucallmon 1 Reply Last reply Reply Quote 0
              • PointPubMedia
                PointPubMedia last edited by PointPubMedia

                I got some momentary push button… which pin I need to connect the other cable from the button If I’m using pin 24 ?

                EDIT: Should I need to enable something else under raspi-config / interfacing options ?

                EDIT2: Make it working fine with one button!

                If I’m using more than 1 button, like 24 and 25… can I use the same GND for both ?

                1 Reply Last reply Reply Quote 0
                • lucallmon
                  lucallmon @Jopyth last edited by

                  @Jopyth how do you control multiple buttons? I have 2 connected but I can only get one to work.

                  lucallmon 1 Reply Last reply Reply Quote 0
                  • lucallmon
                    lucallmon @lucallmon last edited by lucallmon

                    @Jopyth @KirAsh4 I have two buttons set up–1 to shutdown the pi, and another I was hoping to set it up to run “pm2 restart mm” to restart the MM. I have 2 separate .py scripts, 1 for each. And I edited the /etc/rc.local file to run the scripts at startup. I’m not sure what I’m doing wrong though. Here’s my rc.local file:

                    #!/bin/sh -e
                    #
                    # rc.local
                    #
                    # This script is executed at the end of each multiuser runlevel.
                    # Make sure that the script will "exit 0" on success or any other
                    # value on error.
                    #
                    # In order to enable or disable this script just change the execution
                    # bits.
                    #
                    # By default this script does nothing.
                    
                    # Print the IP address
                    _IP=$(hostname -I) || true
                    if [ "$_IP" ]; then
                      printf "My IP address is %s\n" "$_IP"
                    fi
                    
                    python /home/pi/.sd_button.py,
                    
                    python /home/pi/.rs_button.py
                    
                    exit 0
                    
                    

                    the files .sd and .rs_button.py files are the ones. here is the .py for the shutdown that works on GPIO pin 25 and ground:

                    #!/bin/python
                    #This script was authored by AndrewH7 and belongs to him (www.instructables.com/member/AndrewH7)
                    #You have permission to modify and use this script only for your own personal usage
                    #You do not have permission to redistribute this script as your own work
                    #Use this script at your own risk
                    
                    import RPi.GPIO as GPIO
                    import os
                    
                    gpio_pin_number=25
                    #Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use
                    #Make sure you know which rapsberry pi revision you are using first
                    #The line should look something like this e.g. "gpio_pin_number=7"
                    
                    GPIO.setmode(GPIO.BCM)
                    #Use BCM pin numbering (i.e. the GPIO number, not pin number)
                    #WARNING: this will change between Pi versions
                    #Check yours first and adjust accordingly
                    
                    GPIO.setup(gpio_pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                    #It's very important the pin is an input to avoid short-circuits
                    #The pull-up resistor means the pin is high by default
                    
                    try:
                        GPIO.wait_for_edge(gpio_pin_number, GPIO.FALLING)
                        #Use falling edge detection to see if pin is pulled
                        #low to avoid repeated polling
                        os.system("sudo shutdown -h now")
                        #Send command to system to reboot
                    except:
                        pass
                    
                    GPIO.cleanup()
                    #Revert all GPIO pins to their normal states (i.e. input = safe)
                    
                    

                    and here is the one that doesn’t work:

                    #!/bin/python
                    #This script was authored by AndrewH7 and belongs to him (www.instructables.com/member/AndrewH7)
                    #You have permission to modify and use this script only for your own personal usage
                    #You do not have permission to redistribute this script as your own work
                    #Use this script at your own risk
                    
                    import RPi.GPIO as GPIO
                    import os
                    
                    gpio_pin_number=18
                    #Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use
                    #Make sure you know which rapsberry pi revision you are using first
                    #The line should look something like this e.g. "gpio_pin_number=7"
                    
                    GPIO.setmode(GPIO.BCM)
                    #Use BCM pin numbering (i.e. the GPIO number, not pin number)
                    #WARNING: this will change between Pi versions
                    #Check yours first and adjust accordingly
                    
                    GPIO.setup(gpio_pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                    #It's very important the pin is an input to avoid short-circuits
                    #The pull-up resistor means the pin is high by default
                    
                    try:
                        GPIO.wait_for_edge(gpio_pin_number, GPIO.FALLING)
                        #Use falling edge detection to see if pin is pulled
                        #low to avoid repeated polling
                        os.system("sudo reboot")
                        #Send command to system to reboot
                    except:
                        pass
                    
                    GPIO.cleanup()
                    #Revert all GPIO pins to their normal states (i.e. input = safe)
                    
                    

                    it’s essentially the same but it’s in GPIO 18 and ground. Also, I’ve alternated the pin and that didn’t change anything.

                    Here’s what my pi currently looks like: https://goo.gl/photos/eJrMh8i9ZZHC4RCr8

                    Any thoughts?

                    1 Reply Last reply Reply Quote 0
                    • lucallmon
                      lucallmon last edited by

                      you guys were no help. lol.

                      This is what fixed it: https://www.raspberrypi.org/forums/viewtopic.php?t=68183&p=497867

                      J 1 Reply Last reply Reply Quote 0
                      • J
                        Jopyth Moderator @lucallmon last edited by Jopyth

                        @lucallmon said in Physical button:

                        you guys were no help. lol.

                        This is what fixed it: https://www.raspberrypi.org/forums/viewtopic.php?t=68183&p=497867

                        @lucallmon That is just rude and unnecessary in my opinion. Keep in mind that everyone here is doing this voluntarily and (usually) in their free time. Maybe you should not crosspost next time, only discuss problems related to the MagicMirror project and keep a friendly and respectful attitude towards everyone around here.

                        1 Reply Last reply Reply Quote 4
                        • 1 / 1
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy