Can Bela restart itself after pushing this button?
Suggestions on adding a Power On/OFf switch?
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.
Ok fixed now. Scrap the above: just update your Bela code to the latest master: https://github.com/BelaPlatform/Bela/archive/master.zip
Wicked, I'll take this down to the exhibition tonight and update it, hopefully it only fixes one thing haha
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?
- Edited
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.
giuliomoro Tried turning it on as described and it worked - thank you!
So to compare:
Bela Button
Short P9.27 to ground
Short press action: by default stops running Bela program, this action can be changed or disabled
Long press (2 seconds): graceful shutdown, calls cleanup function
PWR_BUT
Short P9.09 to ground
Long press (8 seconds): graceful shutdown, calls cleanup function ??
Pressing while Bela is shutdown while power is connected starts it up again
Is this correct? Does the PWR_BUT also call cleanup() in render.cpp? I'd like to use that function to trigger autosaving of parameters when a gracefull shutdown is triggered.
Ideally I'd like to have a button that is able to both shut down and boot up the Bela. The PWR_BUT seems to be able to do this, however pressing 8 seconds is a bit too much. The TPS65217C datasheets mentions the 8 seconds, and it seems like that time cannot be changed.
I have a momentary DPDT switch with one side connecting P9.27 to ground when pressed. Now I wonder if I connect the other side of the switch to P9.09 I get the best of both behaviours:
- When the Bela is turned on pressing 2+ seconds triggers a graceful shutdown (if one where to press for more than 8 seconds, the Bela would already be shutting down anyway)
- When the Bela is turned off pressing will boot the Bela
- Edited
Ward Does the PWR_BUT also call cleanup() in render.cpp?
Whether your running program calls it depends on how the program is stopped. When tapping on the Bela button, a flag (gShouldStop
) is set in the program so that the audio thread stops calling render () and exits
In turn, the main thread will call cleanup() and then exit. Any other threads should be exiting whenever Bela_stopRequested()
returns true. If these are AuxiliaryTask s, main waits on them before calling cleanup(). When the program finally exits, all global objects will be destroyed by calling their destructors before the program finally terminates.
When hold-pressing the Bela button, if you have a running program, it will be stopped as above and any new instance of the program which could attempt to start before the shutdown sequence is started and while the button is held down will fail to start (although I am not currently sure at what stage it will stop and whether it will call setup(), render() and/or cleanup ()).
If the program is stopped via make stop
, a SIGINT is sent to it. This signal is caught by the main thread, which sets gShouldStop and the program terminatea gracefully as above. Both SIGTERM and SIGINT are handled this way.
I am not sure how the shutdown procedure (which is probably called by both PWR button and Bela button) attempts to stop the running program (it probably offloads the task to systemd). As long as this sends a SIGTERM or SIGINT, cleanup() should be called and a graceful project exit takes place (there may be some timeouts after which the program is forcibly terminated).
In short: briefly tapping the Bela button or sending the program a SIGINT or SIGTERM immediately causes a graceful exit calling cleanup().
Hi all, is there any specific pin for the external power button on the multichannel expander? Can't find P9.27 on the pin diagram. Thanks in advance!
On the BelaMini and BelaMini Multichannel Expander The Bela Button is connected to P2.34 ("shutdown_req" here https://raw.githubusercontent.com/wiki/BelaPlatform/Bela/Images/BelaMiniPinout.png).
if you want to power on the board, as Ward is doing above, use P2.12 "SYS PWR BTN".
To clarify, the mapping is:
Function | Bela | BelaMini
Bela button | P9.27 | P2.34
Power button | P9.09 | P2.12
The functions mean:
- Bela button: short tap stops the currently running project, 2 second hold press triggers shutdown
- Power button: when on, a short tap triggers shutdown; when off, a short tap triggers a boot