The Kitchen Sink

This is the story of the evolution of an uninterruptible power supply for the likes of Raspberry Pi etc.  It takes over where various posts about UPS leave off, the last (detailed) entry being “The Dog’s Breakfast” – in  the search for a low-cost UPS and for individual micro boards and having been less than happy with much of what is out there. The latest video on this is on Youtube.

The Kitchen Sink

The current design has a number of advanced features for a simple, inexpensive UPS  – the software incorporates:

  • Programmable delays for everything
  • Programmable high and low trigger voltages  (hysteresis)
  • Programmable (piezo) warning alarm (default off)
  • Programmable JSON serial state and voltage monitoring
  • Programmable voltage correction for component tolerance
  • Variable shut-down period with auto-recovery
  • Battery voltage automatic logging and OLED graphing
  • Variable watchdog timer 1 minute to 255 minutes
  • Optional temperature sensing/monitoring and warning
  • Low(er) current display on standby
  • Simple graphical voltage monitor
  • Much cheapness

The hardware is in a state of flux, the design you see above uses a combined Lithium charger and voltage booster. Also looking at a separate charger and dual booster circuits – this is a matter of detail to get a good combination of charge and output. See at the end of this blog entry.

The first attempt

Here is what it COULD look like, we’re putting a prototype together but we’ve already found other uses for some pins so this won’t be the last – good job boards are cheap! Aidan put this little number together…

The Kitchen Sink

In the prototype, in addition to the charging and buck boost boards, an Atmega 328 board is used (Nano-type board with as low current as possible) and an SSD1306 display (in this case 128px by 32px), a MOSFET and 2 resistors. The most expensive (if you can call it that) items being the battery and display.  The display is an SSD1306 32 pixel display. Beware of some UK traders charging laughable amounts – they should be under £2.

I did look at using a graphical library with this – but the only fast one I could find at first was the U8G library and the strange thing about that is – their now defunct original library did a pretty good job of driving these displays – but the one they want you to use now, the U8G2 library – uses up nearly all the RAM on a 328 ON IT’S OWN without any other code… so that went in the bin. Since then I’ve discovered this – and a full graphic demo takes 316 bytes of RAM and 21% of program space – however as it turns out that too had it’s issues – to be fair I wrote in and issues with rectangles and fonts were fixed within days – so I did some good.. eventually however I went back to the original text-only library for reasons I’ll explain later.

In this version there is a 3V7 Lithium battery under the board, a 18650 would do as well. Currently using typical TIP4056 charging board and typical MT3608 voltage booster board, all of which are dirt cheap on AliExpress or even Ebay.

Look at the previous blog entry (“The Dog’s Breakfast”) for details of current hardware all of which is widely available.

The graphics

I thought it might be nice to have a little graphical display simply showing a log of the battery state over X amount of time. Well, that went from a simple idea to a major waste of time.

Being used to the ESP8266, I don’t worry too much about RAM other than program RAM. A few hundred bytes is neither here nor there. On the Arduino Nano and Uno type boards however it is a lot. With only 2k and with libraries and variables eating into that, you tend to want to keep RAM usage to a minimum.

The SSD1306 chip has an issue in that it is not that easy to READ the internal RAM buffer.  So in order to allow arbitrary text and graphics, most libraries maintain a buffer, which in the case of the 128*64 display is 1K bytes  and obviously for the 128*32, half of that. This makes a significant DENT in available RAM.

Because of that, I’d originally adopted (and went back to) the ssd1306Ascii library which handles text only. The reason for that is it manages without any buffer, writing directly to the SSD1306 chip. Characters must be on a byte boundary vertically.

I noticed another library which promised low RAM usage and discovered it had PIXEL operations – lovely – except after wasted hours I discovered that in fact there were no miracles – unable to read the state of a RAM location inside the chip – the minimal library offering wrote the pixel required ok, but wiped the adjacent pixels in that vertical byte.. and the point of that?  I wrote to the author who suggested I use the buffered version – and guess what – yes, that used a BUFFER.

With my only hope of graphics without eating up much of my RAM gone I went back to the original ASCII only library —- then it hit me.

Grahpics on the SSD1306 without a bufferThe routines for drawing text  (discuss here the 32 pixel high display – but the same applies to the larger one) write the character on vertical byte at a time.  It occurred to me that if I built up the screen from left to right, putting a bit value into a 32-bit integer – along with any border information, that I could build up a graph complete with border, while using only the 4-byte word – and of course the buffer I use to store data.

And it worked.. and the code online is updated.  Forgive the state of the display – I’m keeping the protective cover on it until I’m finished experimenting. I’ve updated the list of features at the top – I have two of these sitting on my bench being tested and up to now, well, I think we have a winner  – I just need a decent beeper to test the alarm feature – and they’re on the way from China.

So at this point you may be asking – but what about temperature sensing  – well my assumption here is that whatever battery is used will have protection built in – however as I needed it elsewhere I added an optional temperature sensor.. D11.  As I had a DHT22 handy I made that temperature and humidity toggling back and forth on the display – and why not – though a Dallas chip would probably be more appropriate and vertainly a hell of a lot smaller. Here’s the library – some good unrelated stuff also in there. If you don’t fit the sensor, nothing shows – so like the beeper it is entirely optional (and in most cases utterly un-necessary).  For now all it does is sound the alarm if the temperature is valid and gets to be over 40c. That value was entirely arbitrary.

The beeper is on D12 but experiments with a piezo element yielded the most pathetically quiet beep so I’m now waiting for one of those little black speakers to turn up.

Along the Way

In the process of experimenting, many different boards were tried out and several finished products – the PIZ-UpTime being one of them. Initially supplied by Pimori, I supplied this board with a 3.2v Lithium battery – of course I had no idea there were two types – 3.2 and 3.7v.  Without plugging the board into power, I attached the battery, at which point the board got very hot as did the battery.  I contacted Pimori who said that this was because of the wrong battery – which is nonsense as the board has to handle a flat 3v6 battery.  Anyway, I sent the board back, they did send me the correct battery which was nice of them and a replacement was supposed to come out and never did. Thankfully the designer, Percy Kawas of Alchemy Power stepped in and sent me a replacement board.

This works well, in that it plugs into a Raspberry Pi Zero and not only provides power to it but also offers a signal to GPIO26 to allow the Pi time to shut down before the battery gives up in the absence of power.

And that is good – but the board does NOT handle some situations – for example once the power signal has been sent to the Pi, if the power actually returns, we have a shut down Pi with no way to resurrect it without pressing the reset button. Not a lot of use if you are not there.


Alchemy Power also do a board suitable for a Raspberry Pi 3 – this is an altogether more meaty job with two batteries…

Alchemy Power

When I first looked at this board, it seemed that you had to press the reset button if the battery when flat and subsequently recovered – however it seems that the site text is now reworded, if you read the link above it indicates that the unit WILL survive a flat battery. I’ll test that at a later date.

One of our readers pointed me to this MP2636 Power Booster and Charger Module, which could be added to the Atmega and make  something with a little more power.  The claim for the latter is 2.5 amps charging and 2.5 amps output – though I doubt both at the same time.

Meanwhile Aidan and I have progressed with our own (non-commercial board. However, the version you see below has some issues with the PCB – mainly by the time we got the board we’d thought of better ways to do things and decided that two batteries were overkill mainly because of size. The next iteration will have a Raspberry Pi shape so as to be compatible with cases for that computer – and as we know, RPI cases are very cheap.

Kitchen Sink

Well, there is is up to now – software is online for anyone wanting to experiment and the principle is simple enough. Do check the video (link at the top of this blog).





56 thoughts on “The Kitchen Sink

  1. Did this project come any further than the state described here? I would be very interested in it.

    Cheers, Joe

  2. any updates on this project? looking forward to see more details, some schematic as still not 100% understood how the custom PCB has been realized to get rid of the custom modules used in the prototype

  3. Did this ever stabilize to the point where a. I can get a board printed from some PCB project files published somewhere b. I can populate this board with a bunch of components from a bill of materials c. there’s a link to the latest software that hopefully works d. there’s a reasonable chance of it working well after a.b+c? Yes I’m lazy.

  4. Hi, Is the DHT library that you use the Adafruit library .. Seem to be getting some messages trying to compile it. Also do you by any chance have a first version of the code where there were no switches or OLED displays ..Thanks

    1. Hi

      I don’t use the DHT library .. and no I don’t version my code… old is old… The code is up there – there’s a link in the blog.

    1. I could not read the original – but in the English translation there is no mention of handling two situations….

      1, Power goes down – battery drains – tells PI to turn off – Pi does that BUT power is then returned…..and battery comes back on – does it still reset the Pi otherwise you have a Pi dead in the water.

      Power goes off – battery drains – tells Pi to turn off, battery drains to limits, power comes back on – is power then restored to Pi or does it need manual intervention.

      One or more of the above is the usual failing point for most designs as they don’t put any intelligence on the boards.

  5. Thanks Peter for the very thorough design!

    Have you drawn a circuit diagram for the UPS? If not, I have a few questions: 1- With regards to supply for the Arduino Pro Nano, do you feed it directly from the battery or from the DC converter’s output? 2- What are the specifics of the MOSFET’s circuit (resistors, freewheeling diodes, etc.)?

    1. Yes we have a diagram, no we are not putting it out there right now as people can be cruel. Arduino is fed from buck output deliberately. MOSFET, no resistors, diode is schottky.

  6. Peter, here’s a very nice little WORKING ups device… unfortunately without battery protection, but IT WORKS and is SMALL and CHEAP! It can have some uses, not for our *Pi, though…

  7. Seems that the DFRobot option you mentioned has issues with voltage drops on load. I just read a comment on their website from someone who tried the module so it might not be ideal for the Raspberry Pi but could be suitable for lower power modules such as the EPS32.

    1. You’re probably right Dave…. it’s a real shame people don’t actually test stuff properly before shoving it out onto the market.

  8. Thanks so much on your quest to find a standalone UPS that can power the Pi. I bought the charge & boost circuit from your prototype version 1, still waiting for it to be delivered. Anyways I love the ideas people come up with here.
    I have also ordered a 18650 battery shield that has a TP4056 for charge and FP6298 Boost chip. According to the manufacturer, this chip can handle 4.5A max and conservatively 4A as printed on PCB.

    1. It’s all about the journey – if you do it yourself and learn along the way, then you are no longer fodder for the quick-buck merchants who want to sell you something that before the journey you would have no clue about.

    2. The same manufacturer produced FP6276, a little more power and real disable Vout, at the average price. Please check the old cheap chips G5177, MT5032 widely used in power step ups. And if you want efficiency when charge liion ETA6002, ETA1096 will be chance at the reasonable price I think.

  9. I tried a paypal checkout and the payment value didnt change, so free shipping it seems. I’m tempted to buy one and see how it behaves 😉

    1. leave it there… comment from that link, of just yesterday:

      “Testing with a multimeter i confirmed that the real output when on load is less than 5v and closer to 4.9v, when on heavy load (close to 2 amps) the output voltage drops to 4.3v, making my project run underpowered.
      It is very disappointing that an 8 dollar module does not keep up with a cheap less than a dollar dc-dc step-up 5v 2a module from ebay that only drops 0.2v when on the same load and same batteries. It should have been a good idea to give this module a higher output voltage to compensate when on load.
      I only recommend this module if your power draw is gonna be lower than 1.5 amps.”

      1. Fernando – you might want to take the comment that MrShark has found into account -one of the things that impressed me about the MT3608 module was the stability of output voltage … that is quite important.

    1. So this is interesting…

      The CLAIM is 2.5 amps charge – and 2.5 amps output… I’m guessing what they really mean here (somewhat misleading) is a tital 2.5 amps input which can go either way.

      Not as efficient as some – but at least on the surface this looks nice – however, as far as I can see there is no warning output – which means when the battery does go down – it will take an SBC down with it and possibly do harm to the data on the SD or the actual SD – hence the point of all the extra stuff I’ve done. You could of course use this with my MOSFET and processor board – in which case that extra current would be most welcome.

      Or for a board where unannounced shutdown is unimportant – say an ESP8266 then this would be more than good enough – indeed you could probably get away with powering 3 or 4 ESP8266s.

      So – it depends what you need it for, My goal after much frustration with existing products was to make a system that would safely power down and automatically recover, say a Raspberry Pi… now this board having more current capacity could possibly be used with a Pi (I say Pi – you know what I mean – Orange Pi, Nano Pi etc) with a hard disk attached.

      We’re still progressing the version with 2 booster outputs which would of course assure enough current for such a scenario.

      SO – I’ve never used DFROBOT (well, I might’ve done once) – and so that $8 doesn’t look bad, but what about post – given that most Chinese stuff via Aliexpress is free post…. I wasn’t planning on buying one of these and so I could not see from simply pressing ORDER, whether or not there is an additional postage cost which might make this less attractive. Anyone know better?

  10. Pete, have you considered a displayless version? I don’t know Atmel (I use PIC for my intelligent glue) so can you tell me if there is any communication facility? I’m guessing that serial must be available but probably not IP. However, using serial whilst there is still power, could the protected SBC relay UPS controller setup and status information to and from Node-Red? This would also mean that stats and control would be available without having to go look see.

    1. Hi there Pete

      I started with a displayless version – indeed you could simply disconnect the display once everything is set up… but you’d be hard pushed to do the range of settings I’ve put in there without a display. Serial is used for logging. At one point I though of using serial instead of a port bit – but the most popular SBC – the Raspberry Pi, has only one serial port (and even that is used for 2 purposes) so I figured a port bit would be better.

  11. “that adaptor – would become the most expensive item on the board”
    At £5.19 for 10 (£0.52 each)?

      1. There are 2 parts, the BQ24070 and the BQ24071.

        The BQ24070 is 4.4v output, the BQ24071 is 6v output. Both 4.2v input :-

        The BQ24071 seems to be the more expensive at about £15 for 5 from China.

        The BQ24070 is available for about £10 for 5 from China.

        There is a QFN20 to DIL adapter on eBay at $5.19 for 10 :-

        There are many pages on the web showing how to solder a smd to a board using ovens or even a frying pan.

        1. Thanks for that – I’m well familiar with soldering smd stuff – just not the ones with the connectors on the bottom! As for this chip – good – but… that adaptor – would become the most expensive item on the board – so another solution is needed – no intention of going mass production on this so it needs to be something you can do with a soldering iron and average to good skills. Those prices are way out generally – it would be way cheaper to use a pair of TP4056 – a lot cheaper.

        2. Ok, so I have the adaptors….. got it….

          But the output – 4.4v and 6v ??? not quite following that….

          Assuming that there is 5v coming into the chip… I can see how they’d bet 4.4v out -but 6v? Aside from surely needing a buck convertor – what use would 6v be?

          Also if one used this chip… does that mean no buck convertor is needed?? How would one shut the output down? Not sure I see a warning output to allow for graceful shutdown so I’m assuming you’d still need a 328 or similar to perform that function??

          The unit charges at 500ma max so there’s no advantage in terms of charging the battery… but am I right in saying this would do away with the need for a buck boost chip (hence the query about 4.4v and 6v… surely 5v would be about right?)

  12. I thought MCP73831 can be a single chip and board solution but if you say so it has limited power output. I am trying to find cheapest and yielded solution in limited time to feed esp8266 with 6v 600mA solar panel. This is why i need your advise sir.

    1. Well, that MCP chip would appear NOT to be the solution because it does have a 500ma limit.. HOWEVER – life is never as simple as it seems. The ESP needs no-where NEAR 600ma. It needs very short PEAKS of up to 800ma but it’s general consumption is MUCH lower than that (the peaks are when the WIFI is transmitting).

      But for example if you took my little board and used a solar panel with it – assuming the charging circuit can handle such a solar panel as an input – I see no reason why not -and depending on the activity of your ESP – there is not a lot left for charging… but then this circuit is over the top for an ESP – the protection software and hardware is designed to protect, say a Raspberry Pi which will be writing back and forth to SD in the course of it’s duties and losing power in the middle of that is generally not good..

      In the case of an ESP, turning it off at any arbitrary moment is usually not harmful.

      To get best effect however you might be best off with a chip able to take in solar power and charge a Lithium battery… more on that soon. Do let us know what solution you end up with – one of those little WEMOS uninterruptibles?

  13. Sir, as i researched, with MCP73831 chip it is easier to build up such a circuitry. Could you think to make another system with that chip also?. i will try your circuitry by the way.

    1. Burak – unless I’m misreading something – the MCP73831 is:

      a. More expensive
      b. Now-where near as widely available on pre-built boards
      c. Able to output only 500ma and therefore useless for powering any kind of MCU never mind charging a battery as well.

      So the short answer is – I can think of no reason to spend any time on that particular chip. Not sure which ones you researched?

      Did I miss something?

    1. YES but how well it does that will depend on the load and the state of the battery. I would rather have a charge board able to put out much more on demand.

  14. Re: ragworm – something’s off somewhere, because when I last used them a year or so ago they compared pretty well with Seed. Some sort of special offer? Small board? (Mine were about an inch square).

    Anyway, obviously not worth trying at that price.


  15. Hey Pete

    While not in the same price league as the $10 Chinese PCB, for commercial stuff we use Faraday Circuits (down road in Washington (UK)) £200 prototyping 5-day service. This gets you a 24″ x 36″ (?) double side panel for your design. We usually get 30+, ~100mm x 100mm boards on sub-panels from it. They’ll even do the gerber step & repeat.

    1. Hi Tony

      Well, you may recall that Aidan and I used Faraday Circuits for many years when Gordon was alive – during that time we must’ve spent a small fortune with them on prototypes – but things have moved on – if you absolutely need 5 day service then I think sheer distance to China would be an issue. However, if you can stretch that by a few days then I seriously suggest you have a chat with Aidan and re-think – because you are paying many times over the odds. We have had boards made by various providers in China and I can’t think of one that was rubbish – you’ll appreciate we both know what to look for in boards having been in the industry decades. For a small extra charge we get the metal masks for DIY SMT.

  16. BTW, as far as boards are concerned you might look at, who are based in Kent. I’ve found that they are much the same price as Seeed, and a lot quicker for UK customers.


    1. I just went to their site – custom pcb – and put in a 50mm square board…. 10 off – and it came back with a horrendous £99.04 – where do you get “same price as Seeed” from??

      1. Pete,
        You are exaggerating a bit: I got £82.53 for this 😉

        Well, OK, it does not make a big difference compared to $4.90 @ SeeedStudio….

        1. No… mine definitely said 99.04. Oh, well, if the original writer doesn’t come back on this I’ll treat it as an ad and delete it.

          Out of interest we use DirtyPCBs and a couple of others – delivery is often less than 2 weeks. There are several Chinese suppliers who’ll do prototypes for almost nothing – usually the post is the biggest part of it. Wish they’d been around when we were making commercial prototypes years ago and getting taken to the cleaners by local PCB suppliers.

    1. According to the earlier thread, plus Pete’s write up above…

      ” Currently using typical TIP4056 charging board and typical MT3608 voltage booster board, all of which are dirt cheap on AliExpress or even Ebay.”

      1. Thanks for the IC Part Numbers (TP4056, MT3608).

        There were many options discussed, and I was not sure what chips ended up in the design.

        1. Please note – these are the chips CURRENTLY in use – this could change. Similarly on the software by the end of day I’ll have replaced the OLED library with a better one (spent all day finding a small library with line drawing – finally found one and modified it – will appear in bitbucket soon.

          1. Correction, the small library with some additional work – proved to be just the job. That is all now put to bed and working.

Comments are closed.