The Dogs Breakfast

This started off as a simple discussion on UPS for the likes of the Raspberry Pi and other micro boards but developed into so much more.  Some great conversation, some ideas – and a project at the end which could fit a lot of requirements at very low cost. Read on…

Part diagram for ups

What you see above is just the basics – in reality you NEED a processor to make this work well – a simple £1.20 Atmega 328-based board will do – and I’ve done that, added a display and written the software… but let’s go back a little first…

The Early Days

So the basic idea is simple enough – each of these boards is DIRT cheap… the MT3608 boosters are able to output 2 amps. the smaller charging board however is only able to output a little over 0.5 amps – useless for powering, say a Pi3.  So – the little board at the bottom charges the battery as long as there is incoming 5v.  Similarly as long as there is incoming power, the top booster powers the Pi…. it’s output being 5.8 roughly, dropped by a diode. The middle board, powered by the battery, has a SLIGHTLY lower output voltage and so thanks to the diode arrangement does nothing.

Oh, as has been pointed out elsewhere – don’t take that 4200maH figure above too literally – Chinese artistic licence. Indeed, don’t buy that battery…

If the power fails, the top board outputs nothing – and so the middle board takes over.

The Catch

Here’s the thing, if the battery gets well down and the power comes back up, the top board takes over powering the load, the middle board does nothing and so the bottom board can concentrate on charging the battery as quickly as possible.

Much Cheapness

If you have an old laptop battery, the total cost of this up to now is around £3 or so. Next, stick the smallest cheapest Arduino-clone on, in a final version controlling the outputs of those MT3608 boards (they have an enable pin on the chip) and using the analog input to measure battery voltage, ensuring the PI (or whatever) is given the opportunity to shut down when the battery is low – and also (new thought having read what Tesla has done) limiting the battery charge to below full – limiting to 85% apparently does WONDERS for the battery life. I have also made a prototype below using a cheap combined charge/boost board and a MOSFET to turn the output on and off while giving me 5v for the Arduino type board. Works a treat.

And yes I’ve seen lots of boards out there that do all this, yes they’re expensive – as the cheap ones by and large fail to provide UPS somewhere along the line – usually during recovery from a flat battery. so – I thought, why not DIY… I just happen to have a pal who’s a whiz at PCBs.

The argument for Two Boosters

Of course part of the reason for using TWO of these boosters is the inadequacy of the charging circuits based on the common TP4056 – but thanks to Antonio pointing me to a link to a Chinese lady paralleling them up – I then went off on a search and found these…   a cheap 3 amp circuit (the only worry is it says in the ad that it is a 4056 circuit but I’m not seeing a 4056) and a slightly more expensive multi-4056 circuit. With this one only then needs a single booster circuit which does not then need outgoing diodes. The multi-4056 circuit seems to be simple enough – all grounds common – all inputs common, all outputs/battery+ commoned. 3 amps output would typically allow for running, say. a PI and providing a reasonable amount of charge to the battery at the same time.

Thanks to this video – https://www.youtube.com/watch?v=uJmQ9W3Yqc8  we have a circuit for multiple 4056 in parallel – which is another option for experimenters.

tmp874F

Looking at the spec of the chip it should be able to handle 800ma without breaking a sweat – so 4 of them would give 3.2 amps.  I personally would not use those light outputs – I’d take them to the NANO (with internal pull-ups, bearing in mind the LED outputs are open collector). That would then give the NANO additional information.

According to THIS spec sheet – pin 8 on the TP4056 is an enable pin, normally high. They could be paralleled up and taken to the NANO – which already could control the output (via the enable pin on the MT3608) – ensuring the battery is never too discharged – but now the enable on the 4056 along with the analog input on the NANO could ensure that the battery is never fully charged – and that of course increases battery life.  I2c (2 pullup resistors) would allow for programming things like maximum charge voltage, minimum discharge voltage and more – and remaining Nano pins could if needed be used as status LEDs.

A Revelation

This item turned up for me  – https://goo.gl/Zo2Cdt

Charger and buck convertor

For £1.20 this claims to be a charging module with boost step out of 5v, 9v etc etc… adjustable.

So first things first – this unit really is as small as it looks. On applying power it has 2 dim lights – one green, one red.  On applying a load, the green light goes out  – the red light comes on full. Input can be 4-8 volts – I fed in 5v USB – so just under 5v.  At this point no battery is involved.  Just for the sake of it I set the output to 5.1v and applied the output to a Pi2. Well, that’s out – the voltage dropped to 4.6v. However I put an ESP8266 on there and there was no perceptible voltage drop.

Incidentally for the sake of it I checked the unconnected output and it would go as high as 26v so you might find some completely unrelated use for this – like higher voltage fairy light control etc.

The claim is that you can charge at up to 1 amp and discharge at up to 2 amps. I’m making no such claims but “works for me on a Pi2”.

Testing

To test further I stuck a 4.2v Lithium battery on the “Battery” side – with no load and no power, no lights came on – a good thing – on test the power out was 5.1v as you might expect.   I wired up a Pi2 and this time the output voltage stayed rock steady – my first test of course was a little unreal because the unit is meant to work with a battery. Still no lights. I plugged in USB and the red light on the board came on cleanly.  The battery almost immediately jumped to 3.8+volts. I disconnected and reconnected the USB power several times with no discernable effect on the Pi.

Without power, I watched the battery voltage go down to 3.6v – still 5.1 on the Pi – I must stress at this point, this was a Pi without an SD in it –  I was not about to screw up an SD for experiments. The buck convertor on the board was running cold, a good start. At 3.13v the output was still 5.1v, no noticeable drop.

Now bear in mind this is not a solution for UPS – there is no circuitry here for warning the Pi of impending doom without a controller (see below), but I’m wondering as a protection against power glitches and short term outages – well you can’t argue with £1.20 – you could fit this inside many cases!!  Actually I could think of a number of uses for this – only got a 12v fan handy? Not problem? Want to drop the supply to the 5v fan to make it a little quieter? No problem… the list goes on.

A Winner

Some good thought has gone into this board, predominantly single-sided, the bottom track layer is almost all ground and the designer has put PTH holes under both chips to get some heat transfer going – which may account for it running cool up to now.

This circuit of course suffers from the charge circuit going to the battery and the battery going to the booster… this means that when the battery is flat – and power is re-applied, the charger circuit will not only have to charge the battery but also run the load… time will tell how well that works.

I decided to leave this attached to the SD-free Pi for a while for the battery to die. More on this later…. already this is better than some of the attempts I’ve seen so far some of which can’t even handle pulling the power lead out! It kind of makes up for some of the little boards I’ve bought recently which have been so bad they just ended up in the bin!

2.8v and still the output was rock-solid at 5.1v….  in reality I think I’d be wanting the power output to turn off well above this point. 1.8v and STILL a solid 5.1v out… this was starting to look unusually good – and at this point the output stopped. Not completely I may add – it’s voltage dropped to 1.8v while the battery went back to 2v.  Nice behaviour so far. Now to reconnect the power.  I should say you’re not supposed to take Lithium batteries that low – I was just learning.

I plugged in the power and the Pi came on – however a measure of the battery voltage indicated that the charge chip could not keep up – the voltage of the battery started to go back down to under 2v.

The Pi remained active but I imagine only just – and eventually stopped again, only to start up moments later – I imagine this situation would have continued forever.  This would have worked a treat with something like an ESP8266 board as it’s average current would be much lower but with the Pi, this would not work out in practice… so  – as elsewhere to make this work what would be needed is the ability to turn the output off until the battery sufficiently recovered.

I disconnected the load and let the battery charge. it took no more than a few minutes for the battery to get enough charge that the circuit could run the Pi and slowly top up the battery at the same time.

The answer here would be turn the output off at say, 3.1v and not allow it to go back on until the battery was at say, 3.6v. And that, pretty much is what I’ve done (don’t get hung up on those figures – they’re programmable).

The CHIP is marked B6287Y – a kind reader has pointed out that this is in fact the MT3608 – so that looks like a good choice of chip.

HOWEVER in the process of all of this I spotted a flaw in my initial thinking – and I’ll bet others have been caught out with this.

So we add a NANO or similar to control this – the power gets down to, say 3.2v and we issue a warning for the PI to turn off. The voltage gets down to, say 3.1v and we turn off the output. Now the battery will of course recover instantly but falsely – so we don’t turn the power back on until the battery gets back to 3v6.  That all SOUNDS good – and there are those who use a GPIO to do just this. But..

BUT… what happens if the warning comes on – and shortly thereafter BEFORE the cut-off voltage is reached, the power comes back on ????   We’ve already set the Pi on a course to reset!!!  Solution, continue on as if we HAD reached the cut off point and modify the idea from there. When the battery voltage reaches 3.6 (in the example below)  turn it off for 10 seconds then back on. If the output was OFF – no harm done but a few seconds wasted – if it never GOT turned off then this power cycles the Pi to let it turn on normally. I wonder how many designs fail at this point.

Right now I’m sitting in front of that combined board – I have the Nano board running off the 5v output – which begs the question – how do I turn the output off for reset and shutdown? Well, easy – a P-channel MOSFET.  That is running – I’ve covered the case where the shutdown signal is set but the power then comes back on (simply proceed with the shutdown – and then start again.

tmp705EA Quick Aside

While I think on – just an aside– everything I’m doing here uses one battery which makes like easy – one could use 2 or 3 in parallel – but when it comes to using the batteries in SERIES life gets a little more complicated.  Banggood just sent me some 3S 20A 18650 protection boards – in which you can connect up to 3 batteries in series and it will protect them individually – which is handy for people like me who are terrified of Lithium batteries.

Entitled 3S 20A Li-ion Lithium Battery 18650 Charger PCB BMS Protection Board 12.6V Cell these boards are dirt cheap but claim to be able to handle 20 amps load. With 3 cells, the charging voltage is 12.6v – output power claim is 20 amps but how quickly you can charge them is a little vague, I’m not sure I’d want to try charging at 20 amps Smile Important to stress this is just a protection board – the comments on their site include links to voltage and current limiters. The little chips they use are DW01KA and here’s a link to more info.

The Dog’s Breakfast

Well, i spent much of the past weekend on this UPS subject – aside from answering umpteen blog questions – and taking the grandkids to the lake!

Just to show what can be done for VERY little cost… I’ve done the software , I’ve had the breadboard out and I’m very pleased with the result – which really is only the beginning…

Dog's breakfast

This is what is referred to in the trade as “a dog’s breakfast”. Above was my first attempt It is NO-WHERE NEAR as complicated as it looks thanks to all those wires.

This one is an utter bodge and I managed to achieve voltage drops in a single wire of well over 0.2v…… however, ugly and sinful as it looked – the bottom half of this was a working UPS in the true sense of the word.

tmpA8EB

See that green wire to the right of the  lower board? Pretend that is three buttons called UP, DOWN and SET (you’re going to have to use your imagination here.  See that Arduino-type board on the right? Pretend that doesn’t have a USB chip and LED.  And that  800maH Lithium battery, well, that’s the only battery holder I had at the time. Think of it as a 18650 – and finally think of all of those wires as being on a PCB, thicker and shorter. Oh and forget the two LEDs on the breadboard – they were there for testing.

Oh and it should be about maybe 25% of that size.

Now that you have a true mental image of this… you know, sometimes it is easier to stick a camera in front of me…

Here’s a video – I finished my first prototype over the weekend and well, I got carried away with the software – take a look… https://youtu.be/44Lvdf7o4GQ

The Dog’s Breakfast 2

Then came the tidied up breadboard. It actually worked – and worked well – it had most of the things I wish other designs had and yet remained cheap – which is a bonus… got the little things (even getting the warning GPIO signal the right way around is important – I originally had that HIGH when on standby until I noticed it was actually trying to power the PI as the little green light on the Pi was JUST glowing!!!)

Dog's breakfast 2

The display in this pic has now been replaced with a 32px version and the software improvements just keep coming.

tmp8FBA

and at the Pi end….. of course there are many scripts to respond to a port bit and turn the Pi (or other device – I keep saying Pi just for ease)… or better yet in my case – as always Node-Red comes to the rescue – 2 minutes works and…. it sends an email before turning off. That of course is just icing on the cake. Or you could trigger an alarm somewhere via MQTT…. or….

tmp1C3E

And now –  well, last night I headed off to my friend Aidan’s to get three buttons fitted (and disconnected that wasteful RED LED). This morning I got up early to finish the software and update BitBucket.

The Kitchen Sink

As this is starting to grow, I’ve separated later efforts into their own blog entry called “The Kitchen Sink”.

Facebooktwitterpinterestlinkedin

100 thoughts on “The Dogs Breakfast

    1. Update: Nope, it’s not a solution – this Geekworm Power Pack Pro V1.1 also uses I2C so will not work with Raspberry touch screen. Does anyone knows any LCD & touch screen for Raspberry with decent enclosure and proper communication with RPi protocol?

    1. Cool!, thank you for pointing me to this! I have bought an PiJuice (https://uk.pi-supply.com/products/pijuice-standard) as well as took a part in funding LiFePo4wered (https://www.crowdsupply.com/silicognition/lifepo4wered-pi-plus), none of them are good with official Raspberry 7″ touch display – just because this display are purely designed and occupies I2C totally not allowing other devices to use it. Ralphs / Tinkerkman solution can be a cure for this. Will wait for next video as well.

  1. hey guys, take a look at this very interesting PSU!
    https://www.youtube.com/watch?v=VLNguCP7kjE
    as you see, he attaches and detaches the plug and the battery while turned on, seems without issues (we don’t know as there’s no display attached to see what happened…)

    far from being cheap, sure: https://uk.pi-supply.com/products/pijuice-standard

    they have a PoE hat, too: https://uk.pi-supply.com/products/pi-poe-switch-hat-power-over-ethernet-for-raspberry-pi

  2. Cheers Pete. Do you think the final mosfet can be eliminated by using the pi run pad to restart the pi . In that way the pi can be let to shut down at leisure in case any process takes longer?

    1. My comment would be that it does not SEEM to have intelligence in the form of a processor.

      My ideal supply – and that I’ve pretty much achieved will….

      1. Run of mains until the power fails
      2. Run off battery until the battery fails
      3. When the battery fails it will inform the Pi and give it time to shut down before removing power.
      4. If the power returns BEFORE running right down it will non-the less complete the power cycling of the Pi to ensure we can’t end up with a Pi shut down permanently or needing manual intervention.
      5. Ideally it should be programmable for voltages and delays etc.

      I’ve gone way past that with the little Arduino design but of course, you have to make it rather than buy it…

      This particular model – I would ask those questions – it does not look like it would have any of that.

      1. You’re right about the intelligence part!
        I was just wondering about whether the module mentioned satisfied the power requirements; as I recall from your previous experiments, the other modules fail to provide enough juice.

        Not just RPi or MCUs, but I want to use UPS for other boxes such as Android TV box or automation gateways that may need up to 2A current, hence the query.

        Once you’re done with your design, could you please share the working schematic and PCB design please?

        1. Might be a long wait…. mine is done the hard way on breadboard, we had a board made but there were too many issues. Aidan will have another go but this is only a tiny part of the number of projects he’s onto. I personally would like to see a variation that uses 2 MOSFETS – to bypass the unit altogether when the battery is really low but the power is back on… to make sure that works reliably could take some experimenting – expect that to be an early spring project.

          1. I am still waiting for early spring to show in the UK – hope it will be soon and you will try MOSFET way 😉

  3. I’d like to present some thoughts, as I see you guys going into directions which I have explored 2-3 years ago.
    1. forget about stepup modules when using the 3.7V Lipo all 40 pin Raspis will work fine on 4V down to 3.6V (a charged Lipo’s voltage 4.2V)
    2. to address the issue of short periods of power coming back and being off again, you will need a microcontroller which goes through a state machine. Once the boot is initiated, you go through, and if power is off after that, you can shut down again. You will obviousely wait a few seconds after power is back before you initiate reboot.
    3. the mentioned 4056 charging circuits are ideal, in my design which I have linked in my earlier post, I change the resistor for setting charge current to a higher value like 5k or 8k, this prevents smaller power supplies to go down too much if you have a completely discharged Lipo.
    I hope this helps.

  4. Hi Pete,

    Nice little project. Have you considered adding an ltc4150 to the mix, it’s a nice little chip for knowing exactly how charged/discharged your battery is. It also can give a good indication of the health of the battery.

    Using lipo’s with coulomb counting gives a much better indication of state of charge than simply measuring battery voltages.

    Glen.

  5. Rather than using the tp4056 boards, I found similar sized boards that charges and give a 5V output when on battery or supplied so the same as your newer boards but much smaller. I’m not sure if these have been mentioned here see: goo.gl/eLT11z . I’ve been using them and seem much more useful that the 4056 boards, they are very small and dirt cheap. It comes with a USB socket to supply the 5V, I simply solder onto the pins to get the 5V but if you removed it the board would be tiny.

    1. So the short answer is NO they’ve not been mentioned here as I was not aware of them…. IF the claims are true – I like the increased charge and so I’ve ordered 5 -you’ll see that I’m using a single board in my new “dogs breakfast” MK2 prototype so these would work a treat with the MOSFET stuck on the output… however – 1 amp out is a little lower than the chips I’m using – but then charging is a little higher – so they’d likely be good for many SBCs but probably NOT the RPI3… however – small is good – they’re on the way, check this space in maybe 3 weeks?

      And thanks for that – as you say – dirt cheap…. just like the 328-based boards I’m using to control them!!! Good – excellent.

  6. Seeing as you’re nearly there it doesn’t seem fair to add anythings else BUT! There are some established USB interfaces for UPS systems that might make some work dead easy? http://networkupstools.org has a lot of info and software both for the UPS and clients. Now you’ve gone with some some intelligence perhaps it is easy to implement this stuff? The network bit I think is for a number of devices hanging off one UPS. At the very least there is some info on what might be tunable parameters and what people like to see on displays.

    1. New info always appreciated – however – works – cheap – reliable – and I’m not trying to impress buyers:-) people are more than welcome to change the software to whatever their hearts desire – I have loads of space left in the 328.

  7. Amazing!

    After testing many wrongly considered “UPS” boards, My home automation Raspi is backed by a horrendous https://www.amazon.es/gp/product/B00IMCF8FA .

    It is dumb, heavy, and expensive (46€), but -on the other side- it can power my Internet router, the fiber ONT and a network switch.

    I solved power-down detection pinging a couple of devices periodically.

      1. My UPS is so cheap it hasn’t got any monitoring ports.

        Anyway I am using NUT with a fake ups plugin I cooked. Instead of asking the ups, my plugin check some (non-power-protected) LAN connections in order to notify (Telegram) me and start shutdown.

    1. Haha, yes, I have two APC ES-500’s old enough that I’ve had to manually replace the batteries. My main Pi, router, switch & NAS are connected.

      They were enough to see me through working from home during the “Great Flood” in Sheffield a few years ago where we had power for 2 hours at a time then off for 2 hours.

      1. Well, check the latest update to the blog – a lot of work last night – got the buttons on – worthwhile software additions and fixes (now an optional warning beeper).. I’m pretty chuffed with where this is heading.. of course, only for smaller projects with the current hardware.

  8. Ok, so I spent the day working on a prototype of a simplified version of what Aidan is busy laying out right now – and importantly – getting the software to do the job – I got a bit carried away with the latter…

    Anyway rather than try to describe what I’ve spent my time doing – here’s a video

    https://youtu.be/44Lvdf7o4GQ

  9. Hi Peter . At first glance – it does look like you’ve found one that does the shutdown correctly!!! Well, that’s one – this needs further investigation…

    That 1 minute could be better. Not sure what he has against batteries (charging circuit for a supercap will be easier).

  10. I should write a bible on UPS requirements..

    None – NOT ONE of the solutions I’ve seen to date has been properly thought through as an “uninterruptible supply”.

    Here are what I think are minimal requirements (and incidentally “we’re working on it” having almost given up looking for inexpensive solutions.

    An uninterruptible supply should clearly be able to handle a couple of amps output – that’s an easy one.

    It should be able to shut down the target processor via a port bit (or should I say give the processor information to shut down). That is missing from some but again is an easy one.

    It should, in the event of the battery going flat and having shut down the processor, be able to recover in the event of the power coming back on.

    And to do that, there are TWO essentials – at least one of which is missing from every solution I’ve seen:

    From a flat battery, when the power is restored, the unit should give the battery a little time to recover some energy and THEN turn on the output- and should be able to handle enough incoming current to supply the load AND give some current to the battery to charge it.

    And here’s the REAL killer…

    When the voltage goes down and the signal is sent to the Pi (or whatever) to shut down, IF the the power is restored BEFORE the power is turned off… the unit should WAIT to give ample time for the Pi to shut down – and then STILL REMOVE power, wait a few seconds and RESTORE power in order to ensure that in all cases the Pi (or whatever) actually comes back up.

    Am I the ONLY person who needs unattended setups?

    SO – I’m sitting here with a half built prototype and apparently Aidan is doing a board layout – I’ve no idea how well this will all work – we can but try… meanwhile – my “work in progress” – don’t ask questions about it because it’s a “work in progress” – is linked below – look near the end where I handle hopefully all possible states… it really isn’t rocket science.

    This is intended for an Atmega328 chip but the idea applies to any cheap chip really…

    https://bitbucket.org/snippets/scargill/RBLqyE

    1. “… the unit should WAIT to give ample time for the Pi to shut down – and then STILL REMOVE power, wait a few seconds and RESTORE power in order to ensure that in all cases the Pi (or whatever) actually comes back up.”

      @Pete – Have a look at the links I provided above. In particular the “data sheet” which says

      “Once a shutdown has been initiated there is no way back: The procedure must be completed even if power is restored while shutting down. This is an important feature for protection against repeated power failures.”

      If you wanted more control – you could just do this after the PI has booted – using a combination of hardward watchdog “addon” and maybe mosfets / relays? (provided by another shield perhaps?)

      Just thoughts on a UPS “modular system” approach

    2. Peter, where did the dht.h come from? I have looked in a few places and the arduino variant is in caps… I am getting the parts together to build by own ups along the line of yours… It will take a while for the parts to arrive…

Comments are closed.