So I'm going to try running the Bela from the battery 5V DC input and running my project from boot. I was wondering if anybody had a neat way to include an on/off switch? I have a throw switch and saw an example of someone with a Raspberry Pi basically splitting a USB cable and adding a switch into the circuit to cut off the power or let it through to the microcontroller. I'm wondering if this "hard off" would harm the Bela in any way and if there's a way to stop a project, and shut down the Bela (or at least reduce power significantly) any suggestions are welcome.

Thanks,
Neil McGuiness

Hey Neil,
To power it on you could use the power button from the Beaglebone. If needed - and if you are good at soldering and don't mind voiding your warranty - you could remove it and solder some wires on its pads.

If you hold press the button on the Bela cape for 2 seconds and then release it, it will shutdown the board gracefully. This button is also broken out to P9.27, so you could connect a pushbutton between P9.27 and ground. Don't know if this helps in your case. We do non-graceful shutdowns the whole time and the SD never gets corrupted. I think Raspbian was particularly bad in this regard, but Debian (which we are using) seems ok.

In practice, in most of our application we use mobile phone-style 5V rechargeable batteries which have a power switch and we use that switch to turn on and off the board.

    2 years later

    Yes, the button on the Bela Mini cape has the same effect as the one on the Bela cape described above. If you are interested in a button to be able to turn on/off the board while connected to a power source that is always on, you could use P2_12, as described here.

    Does this act the same as the IDE stop reset button? or strictly for power on, off?

    P2_12 is strictly for power on/off (hard, not graceful). The button on the cape stops the running program if pressed briefly, or does a graceful shutdown if hold-pressed.

    nice — is there a pin for the reset to put an external button in place? I'm embedding into a structure and most of the supercollider work i'm seems to use 30-80% CPU, and when it gets to that high end, the whole system just disconnects and starts screaming out the speakers.

    Rather than take the piece apart to get to that button, i'd love to be able to throw a button on a pin to reset the IDE — both with the Mini and the Bela

    Can Bela restart itself after pushing this button?

    you can execute a custom action when pressing the Bela button: just place a shell script in /opt/Bela/local/bela_button_hold.sh and make it executable. This will be executed after holding the Bela button for two seconds. If the file looks like this:

    #!/bin/bash
    
    reboot

    (remember to make it executable with chmod +x /opt/Bela/local/bela_button_hold.sh)
    this will reboot the board.

    But ... why do you need this?

    If your program just gets very busy, you could instead just restart your script?

      giuliomoro The bela is in a box remotely, when supercollider starts going crazy, hitting the reset button helps minimise the damage to ears — but it could be real life variable that messed with it. So having it auto start the supercollider server after reset would be very handy. especially since after boot it, there are no computers nearby to ssh in

      that's ok. Just set your program to start at startup and add the file outlined above. This should work?

      well i thought it would but this error shows up on boot:

      -- Logs begin at Thu 2016-11-03 17:16:43 UTC. --
      Nov 03 17:17:16 bela stdbuf[685]: make: Leaving directory '/root/Bela'
      Nov 03 17:17:16 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Nov 03 17:17:16 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Nov 03 17:17:16 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Nov 03 17:17:16 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Nov 03 17:17:16 bela systemd[1]: Stopped Run Bela at boot.
      Nov 03 17:17:16 bela systemd[1]: Started Run Bela at boot.
      Nov 03 17:17:16 bela stdbuf[704]: make: Entering directory '/root/Bela'
      Nov 03 17:17:16 bela stdbuf[704]: make: Warning: File 'build/core/Spi_Codec.d' has modification time 60744057 s in the future
      Nov 03 17:17:17 bela stdbuf[704]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:28 bela stdbuf[704]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:28 bela stdbuf[704]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:28 bela stdbuf[704]: bash: line 1:   719 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:28 bela stdbuf[704]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:28 bela stdbuf[704]: make: *** [runonly] Error 134
      Oct 19 13:10:28 bela stdbuf[704]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:28 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:28 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:28 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:28 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:28 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:28 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:28 bela stdbuf[740]: make: Entering directory '/root/Bela'
      Oct 19 13:10:29 bela stdbuf[740]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:31 bela stdbuf[740]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:31 bela stdbuf[740]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:31 bela stdbuf[740]: bash: line 1:   755 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:31 bela stdbuf[740]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:31 bela stdbuf[740]: make: *** [runonly] Error 134
      Oct 19 13:10:31 bela stdbuf[740]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:31 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:31 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:31 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:31 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:31 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:31 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:32 bela stdbuf[789]: make: Entering directory '/root/Bela'
      Oct 19 13:10:32 bela stdbuf[789]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:33 bela stdbuf[789]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:33 bela stdbuf[789]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:33 bela stdbuf[789]: bash: line 1:   819 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:33 bela stdbuf[789]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:33 bela stdbuf[789]: make: *** [runonly] Error 134
      Oct 19 13:10:33 bela stdbuf[789]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:33 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:33 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:33 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:33 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:33 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:33 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:34 bela stdbuf[823]: make: Entering directory '/root/Bela'
      Oct 19 13:10:34 bela stdbuf[823]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:35 bela stdbuf[823]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:35 bela stdbuf[823]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:35 bela stdbuf[823]: bash: line 1:   838 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:35 bela stdbuf[823]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:35 bela stdbuf[823]: make: *** [runonly] Error 134
      Oct 19 13:10:35 bela stdbuf[823]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:35 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:35 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:35 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:35 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:35 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:35 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:36 bela stdbuf[842]: make: Entering directory '/root/Bela'
      Oct 19 13:10:36 bela stdbuf[842]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:37 bela stdbuf[842]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:37 bela stdbuf[842]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:37 bela stdbuf[842]: bash: line 1:   857 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:37 bela stdbuf[842]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:37 bela stdbuf[842]: make: *** [runonly] Error 134
      Oct 19 13:10:37 bela stdbuf[842]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:37 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:37 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:37 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:37 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:37 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:37 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:37 bela stdbuf[861]: make: Entering directory '/root/Bela'
      Oct 19 13:10:37 bela stdbuf[861]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:38 bela stdbuf[861]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:38 bela stdbuf[861]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:38 bela stdbuf[861]: bash: line 1:   875 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:38 bela stdbuf[861]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:38 bela stdbuf[861]: make: *** [runonly] Error 134
      Oct 19 13:10:38 bela stdbuf[861]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:38 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:38 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:38 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:38 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:38 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:38 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:39 bela stdbuf[879]: make: Entering directory '/root/Bela'
      Oct 19 13:10:39 bela stdbuf[879]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:40 bela stdbuf[879]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:40 bela stdbuf[879]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:40 bela stdbuf[879]: bash: line 1:   894 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:40 bela stdbuf[879]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:40 bela stdbuf[879]: make: *** [runonly] Error 134
      Oct 19 13:10:40 bela stdbuf[879]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:40 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:40 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:40 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:40 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:40 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:40 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:40 bela stdbuf[898]: make: Entering directory '/root/Bela'
      Oct 19 13:10:40 bela stdbuf[898]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:41 bela stdbuf[898]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:41 bela stdbuf[898]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:41 bela stdbuf[898]: bash: line 1:   913 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:41 bela stdbuf[898]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:41 bela stdbuf[898]: make: *** [runonly] Error 134
      Oct 19 13:10:41 bela stdbuf[898]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:41 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:41 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:41 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:42 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:42 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:42 bela systemd[1]: Started Run Bela at boot.
      Oct 19 13:10:42 bela stdbuf[917]: make: Entering directory '/root/Bela'
      Oct 19 13:10:42 bela stdbuf[917]: Running bash -c 'rm -rf /tmp/sclangfifo && mkfifo /tmp/sclangfifo && sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd <> /tmp/sclangfifo'
      Oct 19 13:10:43 bela stdbuf[917]: terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
      Oct 19 13:10:43 bela stdbuf[917]:   what():  boost::filesystem::create_directories: Invalid argument
      Oct 19 13:10:43 bela stdbuf[917]: bash: line 1:   932 Aborted                 sclang /root/Bela/projects/SIMILARWEIGHT_debug/_main.scd 0<> /tmp/sclangfifo
      Oct 19 13:10:43 bela stdbuf[917]: Makefile:515: recipe for target 'runonly' failed
      Oct 19 13:10:43 bela stdbuf[917]: make: *** [runonly] Error 134
      Oct 19 13:10:43 bela stdbuf[917]: make: Leaving directory '/root/Bela'
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Service hold-off time over, scheduling restart.
      Oct 19 13:10:43 bela systemd[1]: Stopped Run Bela at boot.
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Start request repeated too quickly.
      Oct 19 13:10:43 bela systemd[1]: Failed to start Run Bela at boot.
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Unit entered failed state.
      Oct 19 13:10:43 bela systemd[1]: bela_startup.service: Failed with result 'exit-code'.

      Which puts me in a worried state. This is just a fresh Bela image

      ok sorry about that. I am on it. This seems a problem with the latest supercollider when running as a daemon. I will try to do something about it now. If you are in a hurry, update your Bela code through the IDE to this version, or re-flash the image with a v0.3.5b.

      Wicked, I'll take this down to the exhibition tonight and update it, hopefully it only fixes one thing haha 😉

      3 years later

      giuliomoro thanks for the info for the graceful power off. Is there a similar solution for triggering startup/power on using a momentary switch? I think I had read somewhere about someone using P9.09 to do that with a Beaglebone Black?

      The BeagleBone's System Reference Manual says:

      PWR_BUT [P9.09] is a 5V level as pulled up internally by the TPS65217C. It is activated by pulling the signal to GND.

      So you should be able to turn on the device by briefly connecting P9.09 to ground and you can also gracefully turn it off doing the same.

      On Bela Mini you should use P2.12 instead.