• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Physical button

Scheduled Pinned Locked Moved Hardware
10 Posts 5 Posters 6.0k Views 5 Watching
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.
  • L Offline
    lolobyte
    last edited by Jan 25, 2017, 12:28 PM

    Some old reset buttons from scrapped computer.

    Works well an they are small.

    P 1 Reply Last reply Jan 28, 2017, 2:11 PM Reply Quote 0
    • Y Offline
      yawns Moderator @PointPubMedia
      last edited by Jan 25, 2017, 12:51 PM

      @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
      • P Offline
        PointPubMedia @lolobyte
        last edited by Jan 28, 2017, 2:11 PM

        @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 Jan 28, 2017, 2:14 PM Reply Quote 0
        • J Offline
          Jopyth Moderator @PointPubMedia
          last edited by Jan 28, 2017, 2:14 PM

          @PointPubMedia You can connect multiple buttons to the PI.

          Helpful sticky: How to troubleshoot

          L 1 Reply Last reply Feb 18, 2017, 1:20 AM Reply Quote 0
          • P Offline
            PointPubMedia
            last edited by PointPubMedia Feb 5, 2017, 9:21 PM Feb 5, 2017, 8:23 PM

            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
            • L Offline
              lucallmon @Jopyth
              last edited by Feb 18, 2017, 1:20 AM

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

              L 1 Reply Last reply Feb 18, 2017, 1:31 AM Reply Quote 0
              • L Offline
                lucallmon @lucallmon
                last edited by lucallmon Feb 18, 2017, 1:33 AM Feb 18, 2017, 1:31 AM

                @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
                • L Offline
                  lucallmon
                  last edited by Feb 20, 2017, 11:56 AM

                  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 Feb 20, 2017, 4:12 PM Reply Quote -1
                  • J Offline
                    Jopyth Moderator @lucallmon
                    last edited by Jopyth Feb 20, 2017, 4:12 PM Feb 20, 2017, 4:12 PM

                    @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.

                    Helpful sticky: How to troubleshoot

                    1 Reply Last reply Reply Quote 5
                    • 1 / 1
                    • First post
                      Last post
                    Enjoying MagicMirror? Please consider a donation!
                    MagicMirror created by Michael Teeuw.
                    Forum managed by Sam, technical setup by Karsten.
                    This forum is using NodeBB as its core | Contributors
                    Contact | Privacy Policy