Is it possible to shutdown properly an OrangePi Zero in case of power loss?

Recommended Posts

Hi there,


I am about to use an OrangePi Zero to handle the temperature and display some information on a custom contraption related to network.
The problem I have is that this contraption will be powered on and powered off at will, without notice.
So... I guess that after some time, the Zero running Armbian won't be that happy about being shut off brutally.

I have seen some setups with supercapacitors for Raspberry Pis, but has anyone in here tried something similar with the OrangePi Zero? Or anything else that would delay the power loss, so that the board can shutdown properly?
I made searches about supercapacitors with Armbian, but only found some information related to RTC (which would be nice to have too...).

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

Wait. The PCB was broken, the cells not. And I fixed it that time.

It can be charged and discharged the same time. The problem is that as soon as I disconnect mains the SBC restarts probably due to voltage drop on switch-over. This may be fixable using a small capacitor or something. I found the PCB I bought:

Link to post
Share on other sites
7 hours ago, gounthar said:

I think it is called passthrough, but there may be other names.

That was also my first idea and it redirected me to a thread on reddit which was not that helpful.

I also could not find anything in the ebay description that could suggest such a feature. Probably because it is not fully functional due to the voltage drop mentioned above.


Maybe I can find some time and put an oscilloscope in between to see what we are dealing with...

Link to post
Share on other sites
2 hours ago, MacBreaker said:

I had also had a lot power outages.


I bougt a "Bms 18650 Batterie Schild V3 Expansion Board"
( with a 18650 Batterie, and the problen was solved.


Interesting. The downside I noticed so far is that the loading current seems to be limited to .5 amps which is not enough if you run certain SBCs with a decent load...

Link to post
Share on other sites
8 hours ago, gounthar said:

Thanks for the link. That's very basic, and does not totally address my issue, but that would help anyway.

I would need to shutdown properly when a main power loss is detected, and then start once again when the main power comes back.

if there would only be a SBC which has on board LIPO charging features with powerdetection and that boardvendor would sell cells which fit to the board...


oh wait..


such boards exist.. :lol::blink:

Link to post
Share on other sites

Aight, I was able to do some testing with the powerbank mentioned above and I guess I was lucky I did not kill my board with it. :lol:

An overview:



From the left to right.

First the SBC was powered by the powerbank with close to 5 volts.

Then I attached mains 5v to the powerbank and got a 9 volt spike which luckily was short enough (around 1ms with inclined edges) to not cause any damage.

While charging the voltage drops a bit and seems quite rough.

Then I disconnected mains again and you can see a voltage drop that causes the board to restart. Here it is in high resolution:


The voltage came as mentioned above not very high already, very close to undervolage. The drop to two volts finally kills it and let it reboot as soon as the voltage rises again.


tl;dr: I'll discard the idea using the powerbank to create a crude UPS.


Link to post
Share on other sites

You could just add some larger capacitor in parallel to the power bank. If chosen right it should surpress the voltage spike and buffer enough so it does not drop. Might even use more than one to get a better frequency response. Or put a 5.2 volt zener / tvs diode across the board to protect it from the spike. 


I can edit this with some wiring later if needed. 


EDIT: Some wiring idea:




Use some resistor voltage divider on the powerbank input (eg. 10k to 10k which gives you 0.5) to get some measurement to your sbc. With the given voltages this would be: 5V in -> 5V * (10k / (10k + 10k)) = 5V * 0.5 = 2.5V .

If you feed this to some GPIO you can either use some analog pin to measure it directly (and initiate shutdown if it goes to low) or you can hook it up to some digital one if you only want to know wether it is high or low. Might need to change the resistor ratio then. Do not exceed your max gpio voltage!


On the Powerbank output add either D1 or D2  (zener or transient voltage surpressor diodes) rated for slightly above 5V. These will get rid of nasty voltage spikes for you. Additionally use some small capacitor (to remove high frequency ripple) and some larger one in parallel (to reduce low frequency ripple / voltage drops) to buffer over the voltage drop when powerbank is switching on / off.






Link to post
Share on other sites

Thanks for the effort but I still will not put any more time into this. The reason is that this powerbank also has bad output voltage as seen above. It is well below 5v and probably close to undervoltage shutdown of the board. Also I did these measurements without any load on the board, just idle OS.

THOUGH, I did measure the stuff via GPIO and powered it through DC jack so the voltage drop across the board is included. But this could also be solved only by increasing the input voltage which is not possible and not worth the effort.

Link to post
Share on other sites

Yeah that might work.


Keep in mind though that this module will still output 3.3V if the input is lower than 5V. Checking the datasheet it seems like this regulator has a dropout voltage of about 1.2V. So 4.5V input would still allow this module to output 3.3V signaling to your SBC that everything is OK while at 4.5V input to your SBC it will probably fail.


This is obviously not ideal!


EDIT: Easiest way to do it would be to instead of the converter just use a potentiometer (10k or something like that). Connect the ends to 5V and GND, and adjust it until the slider is at about 3V (measure with multimeter). Then attach the slider pin to some GPIO and check GPIO state. Keep turning down the voltage just until the GPIO reads as LOW. Turn back up a bit until it is HIGH. Then once the input drops below 5V the poti output will also drop slightly causing the GPIO to go LOW -> use this as shutdown. 


This is also not perfect, beware: never turn the poti to high (watch out for anything >3.3V on your GPIO) also you might have to experiment 'till you have a good setting. Minor power fluctuations should not cause a shutdown. 

Link to post
Share on other sites

Nice, I have received the same kind of boards lately, but I'm afraid it is too simple. It won't allow to balance the charge for several batteries, so I have to use just one (which is perfectly fine for my use), and I'm not sure of how it will behave when the main current stops.
I have to make tests (replacing the SBC with a USB fan for example).
What worries me about your board is


1.Don't use output to connect more than 1200mA devices;otherwise, PCB will burn

I know most of the time, our loads don't need much current, but I would not leave this board doing its job far away from sight.


Other charging PCBs are on their way to my home, so that I can do more tests.

Link to post
Share on other sites

Two new boards have been tested.
This one did not work for me, partially because I did not understand what it is supposed to do... It's written in Chinese, and I have not been able to get 5V out of it... yet, only 4.2V.

This second one worked for me despite my very crude soldering job and the salvaged 18650.
So, after a few dozens of minutes charging the battery, I just unplugged the power on the charging board, and did not get any error on the OrangePi Zero...
Now, I would like to get some information on the voltage and other relevant information on the board to see if that's working properly, or if it's just luck...

And... I have to plug the 3.3V step down converter to one GPIO pin (linked to the main power), and see what's going on.



Link to post
Share on other sites

So... I was thinking of using this library to detect the voltage drop on one GPIO pin.
I have checked and the converter board I found goes from 3.3V to 0V in a heartbeat.

I have not yet found a definitive OrangePi Zero GPIO guide for dummies, so if you know one, or just the pin I could use for that, please let me know.
I suppose we could get inspired by this clean shutdown project.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.