Budget Portable Power Supply

I just made a portable power supply out of a few components. I wanted something more flexible than my bench supply.

So the parts list is: TP4056, which can charge a LiIon or LiPo battery at the same time as powering a circuit from it, or USB. In powerbank terms it would be called pass-through. It also provides over [dis]charge protection but I don’t think reverse polarity protection (could be solved with a diode). I made another post detailing how to adjust the charge current, but I’ve left it at the default 1A for this project. I buy these in packs of five usually, they come to about 26p each.

Next up is the MT3608 DC-DC boost convertor, not sure why they’re called that when the chip is actually a B6286K. That can boost 2v input to 28v (24v?) 2A output, adjustable with the onboard potentiometer. Cost me 29p. I used some small jumper cables to join the OUT +/- of the TP4056 to the IN +/- of the boost.

Taking the output from that we have the voltmeter which samples the input and displays it on a nice 7-segment display. Cost me 76p. You have to wire the red and white wires both to the boost converter’s output as the display only works down to 4.5v, but in this configuration you can can power the boost converter from 2v and have the voltmeter still display as long as the boost’s output is 4.5v or more. Largely irrelevant in this project as the TP4056 output is always going to be above about 3.3v or so from the batteries. A smaller alternative without the case is this for 75p.

I soldered some pin headers onto the boost converter’s output pads alongiside the voltmeter wires. I also soldered some JST cables to the BAT +/- pads of the TP4056 as eventually I’ll use a LiPo battery instead of the Li-Ion (which I just temporarily connected using magnets). To charge the battery just connect a powerbank or whatever to the micro USB connector on the TP4056 board (not the one on the boost board). JST cables cost me 10p each in a pack of ten pairs (red+black female & red+black male, times ten).

So total cost of £1.40, plus the price of the battery.

I made some 3D printable containers for the individual parts but probably won’t use them for this project:

Update: I’m thinking about making a case that will hold the battery, boost, charger and voltmeter with a JST connector or Dupont cables or screw terminals as output, access to the potentiometer for adjusting the voltage and the micro USB port for charging; as everything is about the same size:

Big Update

Its been quite a while since my last post, so here’s a big one…..

I’ve been doing a lot of 3D printing since I received my FlashForge Creator Pro 2016. I learned OpenSCAD and FreeCAD, my designs are here. I’ve made various enclosures for Arduino’s and Raspberry Pi’s, as well as USBASP cases, voltmeter cases, solder tip holders, calliper battery savers, resistor forming tools, soldering helping hands, bottle openers, trolley tokens, SD card holders, PIR cases, Dremel accessories, various 3D printer upgrades and the usual calibration prints.

Yesterday I upgraded Dad’s Lenovo B570 laptop to Ubuntu 16.04 from 12.04, which was fun due to its broken EFI setup – basically it has a BIOS and not SecureBoot but the installer sees it as using GPT+EFI instead of a simple MBR. Weirdness such as failure to boot from USB and then failure to boot from HDD once I’d installed from DVD ensued. Boot-Repair fixed the problem, from what I can see it installed some dummy EFI files in the EFI partition, which the 12.04 install obviously nuked. Had to disable hardware acceleration in Chrome to prevent Flash flickering, but otherwise it seems to be working fine.

Today I modified an SG90 servo for continuous rotation, basically removed the wiper on the potentiometer and replaced it with a couple of SMD resistors, and cut the tab off of the largest gear. I found that there is no trimpot to adjust the zero position on my servo so I altered my code to send 100 instead of 90 for “stop”, which I found using some trial and error. Values lower than 100 move clockwise (the lower the number, the faster movement) and greater than 100 moves anti-clockwise (the higher, the faster).

When you write a value to the servo, you’re no longer giving it a degree value, you’re setting a pusle width. So instead of “rotate to 40 degrees” you’re saying “run for 1200uS”, just like a DC motor with H-bridge, which is essentially what is inside a servo. The upside is that the servo can rotate 360 degrees, the downside is that you don’t know where its rotated to as the microcontroller receives no feedback.

My test code is below – its moves it left, right, fast, slow and stop.

continuous_servo.ino

#include <Servo.h>
 
// create servo object
Servo myservo;
 
// speeds for my sg90
#define FASTCW  45
#define SLOWCW  90
#define STOP    100
#define FASTACW 135
#define SLOWACW 110
 
void setup()
{
    // attach servo to D9
    myservo.attach(9);
}
 
void loop()
{
    myservo.write(FASTCW);
    delay(2000);
 
    myservo.write(STOP);
    delay(1000);
 
    myservo.write(FASTACW);
    delay(2000);
 
    myservo.write(STOP);
    delay(1000);
 
    myservo.write(SLOWCW);
    delay(2000);
 
    myservo.write(STOP);
    delay(1000);
 
    myservo.write(SLOWACW);
    delay(2000);
 
    myservo.write(STOP);
    delay(1000);
}

Makefile

BOARD_TAG = uno
MONITOR_PORT = /dev/ttyUSB0
include /usr/share/arduino/Arduino.mk

I’ve also been making custom power cables lately, such as a USB to DC jack for giving 5v to older projects such as a 555 astable from a powerbank. It seems that microUSB should be the new go-to connector for power instead of 2.1×5.5mm DC jacks these days. I’ve actually got some USB-to-DIP breakout boards as well as the TP4056 Li-On charger boards. I’ve also got some USB boost regulators on the way that apparently can output up to 28v or something silly. My next custom cable will likely be banana plugs to pin headers as its a pain trying to put a male pin header on a screw terminal.

Finally I had a play with a MCP23017 port expander which I was thinking of using when my ESP8266 projects don’t have enough pins – like my RTC clock could have done with 1-2 more buttons. But it seems like a lot of wiring e.g. 8 pins before you’ve even added any I/O, and a lot of calls to the Wire library e.g. 4 calls just to send an output like lighting an LED, so I think I’ll hold out for ESP32’s to be generally available before doing any more pin-intensive projects.

Motion Sensing Nightvision Camera

I fancied figuring out if it was my cat or the neighbourhood cats pooping in my side alley (oh er missus!) so thought I’d find a use for my PiNoIR camera and that spare B+

I usually use RaspiMJPEG for webcam sorts of things like timelapse or somesuch, but it seems in a state of flux – the internal motion-detection system simply doesn’t work it would seem, and the external system is still using Motion and not the MMAL version, so its slow and can only cope with about VGA resolution on a B+, and it doesn’t seem to work in timelapse mode, and seems flaky at best anyway.

MotionEyeOS seemed like it was much more professional and motion-detection with timelapse worked really well, but again was limited to pretty low resolutions with weird aspect ratios. Also doesn’t seem to use motion-mmal anymore (think it did when it was motionpie).

Anyway, I figured the problem was software motion-detection using image analysis, so I decided to go the hardware route and use a PIR. So far I’ve come up with this Python script which is based on the excellent picamera module. It can do useful things like vertically flip the image (on the GPU!) which is handy as my Sainsmart camera module is a bit hard to mount the right way around!

Also the code uses interrupts so events don’t get missed and the CPU is mostly asleep. I chose to use 1080p resolution, but you could go up to to full 5MP (or 8MP on the new camera boards!) if you wanted to, forget 640×480

The only problem is that the PIR sensor doesn’t work through double-glazing, so I need to mount it in a box outside, which I was going to do eventually anyway.

#!/usr/bin/python
 
# import module
import picamera
import time
import RPi.GPIO as GPIO
 
# setup gpio mode
GPIO.setmode(GPIO.BCM)
PIR_PIN = 14
GPIO.setup(PIR_PIN,GPIO.IN)
 
# instantiate class
camera = picamera.PiCamera()
 
# vertical flip
camera.vflip = True
 
# set resolution
camera.resolution = '1080p'
 
# interrupt function
def onMotion(PIR_PIN):
    filename = time.strftime("image-%Y%m%d-%H%M%S.jpg")
    camera.capture(filename)
 
try:
    GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=onMotion)
 
    # loop until interrupted
    while 1:
        time.sleep(100)
 
except KeyboardInterrupt:
    GPIO.cleanup()

You have to run the script using sudo, or from an init script like /etc/rc.local perhaps, and maybe set a directory to write the files to rather than just cwd.

Edit: just bought a v1.3 Raspberry Pi Zero and cable for this, as it should use a lot less power than the B+ and is a lot smaller to encase.

Pi Zero Print Server

After looking at wireless print servers costing £35+ I decided to make my own using my spare Raspberry Pi Zero (original without camera connector).

I needed a wifi dongle and USB connection for the printer, so have bought a Zero4U USB hub HAT and case, in fact I bought two of each as the shipping was fixed, so it came to £23 shipped from the Czech Rebuplic, so shouldn’t take too long to arrive.

I’ve got a spare 16Gb Class4 microSD card – we’ll have to see how that goes, otherwise I have a 32Gb Transcend on order. I’ve got a 5v 2A power supply and DC jack to microUSB adapter, as I don’t fancy the official power supply (its upside-down and looks fragile).

I’ve got Ralink RT5370 and Realtek RTL8188 wifi dongles on order, although I already have a RT5370 to use, but its nice to have spares that cost a Pound or two!

I installed the latest Raspbian Lite and added cups and sane to the installation.

The printer is a Brother DCP-7055 and I know it works with Ubuntu 12.04/14.04 as it used to be connected locally, however that was using x86-64, I’m not sure ARM is supported by Brother’s drivers, it seems printing at least will work with the HL-1250 ppd file or possibly the 7045N Postscript driver or brlaser, but almost definitely the brscan4 driver won’t work as its x86-only.

I don’t think I can connect a laptop to the miniUSB port on the Zero4U whilst its connected to the Zero, so to scan I’ll have to unplug the Zero from the printer unless Brother can be convinced by my constant tweets/emails to make ARM packages!

In other news my acrylic weld glue and needle bottles have arrived, so got to have a go at assembling the ESP8266 clock cases soon – and Dremel that button hole a bit more.

Update: Brother confirmed no current or future plans to support the ARM platform. The DCp-7500 worked out of the box with Raspbian’s built-in brlaser3 installation and DCP-7030 PPD file. No chance in getting the scanner working though, scanimage didn’t even detect it.

The Zero4U is pretty cool, although the acrylic case is a bit weak, took 5-6 days to arrive. The miniUSB port is blocked by the case so you can’t use it at the same time with a Zero and desktop PC anyway.

I assembled the acrylic case for the ESP8266 clock, it was a bit of a nightmare with the weld solvent, but it went together really well. I even managed to add some rails to make the lid removable.

TP4056 Charger Boards

I thought I’d write up my findings when using the TP4056 Li-Ion charging boards as a lot of people seem to be interested in them lately for charging circuits containing ESP8266 wifi chips which are rated from about 3.3-3.6v. Ideally a Li-Ion, LiPo or LiFePo4 battery. Note that the TP4056 can’t be used to charge LiFePo4 batteries (or NiMH, Alkaline etc).

First up, a couple of links to Julian Ilett’s videos of the older unprotected USB-mini board and another video comparing the newer protected USB-micro board which some people refer to as MP1405.

The boards I received seem to be a slight modification on the newer boards, they have a green LED instead of a blue one and the chip layout is different, but still use the DW01 battery protection IC and 8205 mosfet to (dis)connect the charger. There doesn’t seem to be any reverse-polarity protection like a diode. I paid £1.36 for five.

As my intended use was to allow my ESP8266 circuit to be enclosed in a box with no access to the battery, and be charged from any micro-USB source (computer, phone charger, powerbank, mains charger….) I swapped out the default 1k2 resistor (marked “122”, near IN-) which pulls around 900mA charge current, for a 2k2 one, which took the charge current down to about 540mA, only slightly above the average 500mA USB rating. It does slow down the charge rate, but would prevent poorly-built USB devices from pulling more current than they can handle. I used these 0603 metric (aka 0201 imperial) SMD resistors, which are just about hand-solderable – I actually managed to solder a through-hole resistor onto one board too!

There’s a couple of LED’s on the board:

Green on, red flashing = no battery
Red on, green off = charging
Green on, red off = charged
Both off = unplugged from USB

I was going to remove them to save quiescent current, but it turns out that when USB is disconnected (so you’re running off the battery) they are both turned off.

Also, you can still use your circuit when its plugged into USB, the “OUT+” outputs just under 4.2v irrespective of the battery’s charge (or even if the battery is disconnected). I’m not sure if it charges the battery whilst its powering a circuit, but believe so. Obviously the older mini-USB modules don’t have the output pads, they are purely for charging a battery, not powering a circuit.

One thing to note is that the modules seem to be optimised for being stored in a warehouse for a while, as they don’t actually turn on when you first connect a battery and measure about 150mV on all the pins. The answer is to plug them into USB, which then wakes the device. You can unplug them then if you like and they will output 3.7v from the battery on the OUT+ pin (or whatever the battery voltage is).

The board seems to get pretty hot whilst charging, which then cools as the battery voltage gets above about 4v and less current is flowing. The underside of my board got to 50c even with the 540mA charging current, according to a few websites this is the TP4056 chip itself, so I fitted a 6x6x3 heatsink that I had left over from a Raspberry Pi3 kit to the chip which seemed to drop the heat by about 5c, not sure if its worth it really.