# On/Off power button with "soft off" functionality

**URL:** <https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908>\
**Category:** balenaFin\
**Created:** [April 6, 2019, 2:51pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908 "2019-04-06T14:51:58Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![c4l3b](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/c4l3b/32/1740_2.png) [@c4l3b](https://forums.balena.io/u/c4l3b)\
**Post date:** [April 6, 2019, 2:51pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/1 "2019-04-06T14:51:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ntzovanis](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ntzovanis/32/1150_2.png) [@ntzovanis](https://forums.balena.io/u/ntzovanis)\
**Post date:** [April 8, 2019, 10:05pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/4 "2019-04-08T22:05:57Z")

</div>

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

Cheers,  
Nico.

---

<div class="post-metadata">

**Author:** ![AlphaFab](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@AlphaFab](https://forums.balena.io/u/AlphaFab)\
**Post date:** [November 20, 2020, 4:34am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/19 "2020-11-20T04:34:15Z")

</div>

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.

Regards,  
-joel

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [November 20, 2020, 6:48am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/22 "2020-11-20T06:48:04Z")

</div>

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](https://github.com/balena-io/balena-fin/blob/master/documentation/markdown/balenaFin/v1.1/datasheet/datasheet.md#32-silicon-labs-bgm111-connector-pinout) - and connect the push button circuit to any of the GPIOs.
2. Next up you can take a look at [our schematic](https://raw.githubusercontent.com/balena-io/balena-fin/master/documentation/PDF/balenaFin/v1.1/schematics/20173009_balena-fin_v10.pdf) 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](https://github.com/balena-io/balena-fin-coprocessor-firmata)
4. [https://github.com/balena-io/balena-fin-firmata-flash](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.

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 5, 2021, 5:04pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/24 "2021-04-05T17:04:35Z")

</div>

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)

Thanks

---

<div class="post-metadata">

**Author:** ![ntzovanis](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ntzovanis/32/1150_2.png) [@ntzovanis](https://forums.balena.io/u/ntzovanis)\
**Post date:** [April 5, 2021, 6:26pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/26 "2021-04-05T18:26:27Z")

</div>

Hello @ricardoosorio ,

On your first item (firmata failing with `/dev/ttyUSB0 not found`), we’ll continue the discussion in the [other thread](https://forums.balena.io/t/firmware-update/282951/3) 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](https://forums.balena.io/t/what-would-be-the-proper-way-to-add-a-power-button-for-balenaos/40927/34)

- If the compute module was already shut-down, then the co-processor would just need to enable PC9 to turn the compute module on.

Cheers,  
Nico.

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 5, 2021, 6:53pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/27 "2021-04-05T18:53:22Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 5, 2021, 7:49pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/28 "2021-04-05T19:49:07Z")

</div>

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

 ![1](https://global.discourse-cdn.com/balena/original/2X/4/40bcdf567bca923204b3f706f5d139aed332bf0c.jpeg)  
 ![2](https://global.discourse-cdn.com/balena/original/2X/b/b1bc9dd835265c1098171269394152882bba1f43.jpeg)

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 5, 2021, 8:14pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/29 "2021-04-05T20:14:07Z")

</div>

> [@ntzovanis](#):
>
> - 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](https://forums.balena.io/t/what-would-be-the-proper-way-to-add-a-power-button-for-balenaos/40927/34)

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

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [April 6, 2021, 4:14pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/30 "2021-04-06T16:14:16Z")

</div>

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](https://github.com/balena-io/balena-fin/raw/master/documentation/PDF/balenaFin/v1.1/datasheet/datasheet.pdf) 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](https://forums.balena.io/t/what-would-be-the-proper-way-to-add-a-power-button-for-balenaos/40927/23) is an example in Python.

Let me know if this clarifies a bit the scenario.

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 6, 2021, 8:06pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/34 "2021-04-06T20:06:19Z")

</div>

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 😉 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

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 7, 2021, 1:49pm UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/35 "2021-04-07T13:49:58Z")

</div>

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.

 ![balena_h_—_balena-fin-coprocessor-firmata](https://global.discourse-cdn.com/balena/original/2X/a/ac212302af48bf34608f3378971736dca7212803.jpeg)

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

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [April 8, 2021, 7:18am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/36 "2021-04-08T07:18:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [April 8, 2021, 7:21am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/38 "2021-04-08T07:21:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [April 8, 2021, 9:15am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/42 "2021-04-08T09:15:12Z")

</div>

Hi

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](https://github.com/balena-io-hardware/balena-fin-coprocessor-firmata/pull/32)

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_3V3`on the schematic. I have attached a link to that below.

- [Schematic](https://github.com/balena-io/balena-fin/blob/master/documentation/PDF/balenaFin/v1.1/schematics/20173009_balena-fin_v10.pdf)

---

<div class="post-metadata">

**Author:** ![ricardoosorio](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ricardoosorio/32/5675_2.png) [@ricardoosorio](https://forums.balena.io/u/ricardoosorio)\
**Post date:** [April 8, 2021, 11:12am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/43 "2021-04-08T11:12:41Z")

</div>

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](https://github.com/balena-io-hardware/balena-fin-coprocessor-firmata) 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.

---

<div class="post-metadata">

**Author:** ![AlidaOdendaal](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/alidaodendaal/32/1641_2.png) [@AlidaOdendaal](https://forums.balena.io/u/AlidaOdendaal)\
**Post date:** [April 16, 2021, 8:53am UTC](https://forums.balena.io/t/on-off-power-button-with-soft-off-functionality/5908/48 "2021-04-16T08:53:09Z")

</div>

Hi Ricardo

As for implementing the requested power button functionality: this is an [open issue](https://github.com/balenablocks/finabler/issues/11) 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  
Alida
