On/Off power button with "soft off" functionality

Hi Everybody,

I’m designing a product that will be battery powered and (hopefully) built using the Fin.
I’m wondering if anybody has implemented an on/off button that gracefully shuts down the board when pushed for off. It’d also be great to have the “hold for x seconds to force shut off” functionality.

Could the co-processor be used for this purpose?
Since my product will be battery powered, drain while off is a concern. Do we know how much power the system consumes when the pi module is shut off?

Hello Caleb,

The best approach for what you’re mentioning would be to use the coprocessor, since it has the capability of managing the Compute Module power rail. You can implement a button that directs the coprocessor to power the Compute Module on and off (force shut down) or communicate with the Compute Module to allow for a graceful power off.

The power consumption will depend on how heavy is the application running on the coprocessor. For example, if the CM is turned off and the coprocessor is running a very simple BLE application, the power consumption is around 20mW (we measured this using a 12V PSU).


1 Like

Sorry to re-hash an older question…however, I haven’t found any other references to this type of function.

Is there any additional information on the topic of adding an “ON/OFF” switch utilizing the coprocessor to perform the shutdown/startup? It appears as though it can be done (from the post above), but how would we go about implementing that kind of function?

I’m placing the FIN in an aluminum enclosure, and need to have an ON/OFF button (momentary switch) located on the outside of the case that will allow a graceful shutdown of the CM, as well as the FIN. Our customers don’t always want to leave their device powered on at night or on weekends…

Optionally, I’m sure that I can add a “Shutdown” option in my interface, but still need a way to turn the device back on after the shutdown. Seems as though an ON/OFF button offers the best solution.

Any further direction on this would be greatly appreciated.


Hi Joel

So as I understand it, you want to add a button to the coprocessor which will control the power status of the Compute Module. You can do the following -

  1. Look at the coprocessor pins here - and connect the push button circuit to any of the GPIOs.
  2. Next up you can take a look at our schematic and understand how the coprocessor controls the power rail to the compute module
  3. Now you will have to create an application for the coprocessor so that you can look for push button events and then make changes to the power rail. A sample application for the coprocessor that some of our customers use is this firmata application
  4. https://github.com/balena-io/balena-fin-firmata-flash is an example that you can see to understand how we flash the sample firmata application to the coprocessor from the compute module. You will have to do something similar to upload your application to the coprocessor

If you want to add a little more complexity, you can have your coprocessor application communicate with your application on the Compute Module and indicate that a shutdown request has been initiated - which will allow it to shutdown gracefully.

I’ve search everywhere how to make this. 1. None of the firmware examples are working (all fail with /dev/ttyUSB0 not found) 2. There is no example or documentation about how to setup the pins for power-on. Neither a way to test it since can’t power-off without firmware. So, could you help us trying to give a better and extensive explanation with the OS version you are using, git and pinouts? (PDF of your schematic don’t explain which is the pin number)


Hello @ricardoosorio ,

On your first item (firmata failing with /dev/ttyUSB0 not found), we’ll continue the discussion in the other thread as we have an idea on what might be the issue there.

With regards to the ON/OFF button, there’s no pin on the balenaFin that has this function. It will need to be implemented. What my colleague Anuj suggested above was to use a few of the co-processor GPIO pins to do so.

I’ll ask internally to see if we have any examples so you don’t need to write custom firmware, but the general idea would be as follows:

  • Use any GPIO pin from the coprocessor IO header (#25 on the balenaFin datasheet under the title “BalenaFin images and mapping”) to connect it to the button.
  • Assuming the compute module is on, then at a button press do the following:
    • On the coprocessor, schedule a power-off (by grounding PC9) and signal the compute module to shutdown
  • If the compute module was already shut-down, then the co-processor would just need to enable PC9 to turn the compute module on.


Thanks. When you say “enable PC9” you mean that 5v should happen on PC9 or is a pull to ground on PC9? Sorry if seems noob question :slight_smile:

Don’t get me wrong…but I’m always stuck with the documentation…

I really need some help here trying to turn it on using the hardware button. I used pin 18 (from 1-18) to power with 5v (used the gpio 5v). It did power on. But any time I push the button…a reset happens. So I guess is not the right way. I need to know how to power-on. Power-off I guess I will manage since I’ve got firmware working already.

Thanks Nico

Ricardo, I’m not very experienced with the fin myself but let me try and clarify what Nico suggested. You might have gotten the impression it’s possible to achieve this purely with hardware (by adding a button) but that’s not the case, you’ll definitely need to write some software.

First you’ll need to connect a button to a GPIO pin from the coprocessor (checkout the datasheet to figure out which one).

Then you’ll need to write some custom code that reacts to the button press.

  • If the CM was off then you’ll need to enable PC9, this means you’ll need to tell the coprocessor to set pin PC9 to HIGH/5v.
  • If the CM was on then you’ll need to do two things: shutdown the CM and set pin PC9 to LOW/0v.

Note that grounding PC9 or setting it to high must be done by the coprocessor so you’ll need to flash some firmware for it.
Shutting down the CM needs to be done from the CM itself to ensure a proper shutdown procedure is in place. You’ll need to send a signal from the coprocessor over to the CM using a GPIO pin on the CM and then shut it down. Here is an example in Python.

Let me know if this clarifies a bit the scenario.

I guess I understood what you mean. We will work that. But my suggestion is that balenafin product would earn a lot if the firmware already available for demo would have a sample already prepared :wink: Just saying. Since it’s a very basic feature (turn on/off…not by RTC but by a push button)

Many thanks and I will suggest the firmware for that once done

Hi all,

I’ve try to build a firmware using your git example and we weren’t able to make it work. This is crucial for us. We weren’t able to make it work.

BTW: Looking into the firmware, the sleep pin isn’t the PC9, but the pinout 16 (PD15). When set to 0 will sleep. When set to 1 wake-up the CM3. So again the documentation seems odd or wrong.

Please setup a chat or call with us to solve this issue if possible. Many thanks!

Hi - thanks for the feedback. We are tracking this feature request on GitHub - Add support for a power button · Issue #11 · balenablocks/finabler · GitHub - we’ll keep you posted on this thread when we get around to implementing it! In the meantime feel free to open a PR!

Hi - just saw your message about the incorrect documentation. Let me double check and get back to you about that


We know there’s some ambiguity in the docs, and have an open PR to fix that. Take a look at it here - Added clarity for Firmata pin numbering in docs. by Bucknalla · Pull Request #32 · balena-io-hardware/balena-fin-coprocessor-firmata · GitHub

If you want, feel free to add your review as well. In the meantime, take a look at the changes it proposes. Pin 16 in Firmata is the PW_on_3V3on the schematic. I have attached a link to that below.

For us is much more important to have the GitHub - balena-io-hardware/balena-fin-coprocessor-firmata: firmata firmware for the BGM111 co-processor on the balenaFin working. Because we already try the firmware and we were not able to make it work on balenafin 1.1.1. Something wrong in the code that crash.
Can someone try the firmware from github on balena 1.1.1 and test the commands after flash?

Thank you.

Hi Ricardo

As for implementing the requested power button functionality: this is an open issue which we have not gotten around to implementing just yet.

Then, you refer to code that is crashing - can you perhaps provide more information in this regard? What are the exact steps you followed, and the associated logs, including the errors?

Thank you, and kind regards