Skip to content
dexdan edited this page May 7, 2019 · 5 revisions

A typical setup is to use a power bank (5000mah is plenty for a day) kept in a case together with pi, RileyLink and perhaps the phone. Please see the 'standard hardware setup' page for a description.

An alternative, which requires basic electronics / soldering skills, but which is not a requirement to use omnipy is described here. This gives a more compact pocketable setup.

It also enables the rig battery life to be read on Nightscout and on the Wear watch. The battery measurement circuitry requires a few more components and a bit more work to fit. The instructions which follow include battery measurement but this is optional. If you don't want to include battery measurement, ignore the 'optional battery measurement' steps.

Parts list

  • Raspberry pi zero headless - widely available
  • Micro SD card for pi - at least 8gb - widely available
  • LipoShim
  • Suitable header pins - often these come with the pi but if not you're looking for 2.54mm 2x20 double row
  • RileyLink with firmware v2.2 and 433MHz antenna (note if you already have one with 916MHz you can modify - see 'increasing radio range')
  • Lipo - 3.7v, something of 4000mah or more, something around 50mm x 90mm, the thickness not critical - I got mine from an unwanted phone power case, but this one is similar. Important note about lipo safety: Lipos can catch fire. You need to take particular care to ensure (a) you have the correct polarity of the lipo (there is no reliable standard for connectors or even wire colours so recommend you check with a volt meter); (b) you don't accidentally short out the lipo; and (c) that you don't pierce the lipo.
  • Lipo charger module such as TP4056 module.
  • MCP3002 (Only necessary if you want battery measurement included).
  • 180k resistor, and a 100k resistor (Only necessary if you want battery measurement included).
  • Suitable rigid box. I'm currently using a (trimmed) old plastic business card box I had laying around which is working pretty well (like this)
  • Soldering iron, solder, wires, snips, pliers, insulating tape, heatshrink tubing, sticky dots, craft knife, tape

Instructions

  1. First get your pi setup - follow omnipy setup link.

  2. Remove the SD card from the pi and put it somewhere safe. I strongly recommend making a backup image of the card.

  3. With snips, remove the power socket from the LipoShim. Solder wires to the LipoShim battery inputs.   (If you'd rather not, you could get hold of a 2-pole JST connector to plug into the LipoShim, or cut one off the lipo battery you get. I didn't do this because removing the socket saves a fair bit of height, ultimately resulting in a more compact solution). Note that you need moderately thick wires, this is for power supply, perhaps up to 1A 5v peak.

  4. (Optional battery measurement) The battery measurement circuitry uses a resistor bridge, and an analogue-digital converter IC. This diagram shows how the parts fit together:

(If you want to zoom in, a powerpoint version is available).

To get this setup, you need to start by applying 3cm of heatshrink tubing to the 180k resistor (failing that, covering in tape), and then soldering one end of it to the BAT+ pin in the LipoShim.

  1. Now snip down your header pins to give 6 x 2 pins. Solder these to the LipoShim with the plastic bit underneath (ie on the opposite side to the components).

  2. Apply the supplied rubber stick-on foot to the bottom of the LipoShim on the corner diagonally opposite the hole.

  3. Insert the header pins into the pi. These need to go right up to the end so the hole in the LipoShim lines up with the hole in the pi. You"re basically mounting the LipoShim on top of the processor and sd card holder. Solder header pins to pi. I found that the pins were actually a bit long - trim then down with snips after soldering if possible to save height.

  4. (Optional battery measurement) Referring to the diagram at step 4, now prepare you MCP3002 IC. This is a bit fiddly. Referring to the diagram and photos below, you need to bend pins 1, 4, 5, 6, and 7 down and then in an L shape, so that they will fit direct into the Raspberry Pi GPIO bus - I did this with small pliers. Pins 8 and 2 should be bent outwards and pin 3 should be cut off.

Showing underside of MCP3002 with pins bent

Then solder in the MCP3002 to the Raspberry Pi. There are 2 legs to be soldered in on one side, and 3 on the other, as per the diagram. These need to be soldered from beneath the IC. Check the joints for continuity with a meter.

  1. (Optional battery measurement) Referring to the diagram at step 4, fit the 100k resistor into pin 30 of the Pi, then join it to the 180k resistor coming from the Liposhim, and join the centre of the resistor bridge to the IC pin 2. Also use a short length of wire to connect pin 17 of the Pi to IC pin 8 (VDD).
  1. Now take your RileyLink. Either remove the battery socket with snips or (probably better - given height less critical for the RileyLink) just cut the battery wires off from the battery supplied with the RileyLink) and leave the plug in with a couple of cm of wire. NOTE: LIPOS ARE DANGEROUS AND CAN CATCH FIRE. This can happen if they get shorted. So make sure that you put insulating tape on both wires of the lipo that was supplied with the RL. You won't be needing that battery any more.

  2. Solder wires on to the plug to extend the power wires to the RileyLink. Cover joins with heatshrink tubing or insulating tape. (Note: the wires need to be reasonably thick as otherwise there is a risk that at peak times the power supply to the RL may be insufficient which may mean it fails to communicate).

  3. Use insulating tape bottom & top to join the Pi and the RileyLink tight together, side by side. You are aiming for a layout where the antenna of the RileyLink overhangs the lipo. The more overhang, the better range you will get from your rig.

  1. Solder wires to the BAT + and - connections on the [TP4056] charging module.

  2. Use sticky pads to fix the boards onto the battery. (Important: ensure you use enough sticky pads to give some spacing between the header pins and the lipo - you need to avoid the pins poking into the lipo, as piercing the lipo could cause a fire). Work out how you are going to mount the [TP4056] charging module so there is resistance when you push the charging plug in. In events I ended up wiring this (for mechanical strength) onto a piece of bridging plastic which is butted up against the boards.

  3. Solder together the negative power wires from the LipoShim, the RileyLink, the charging module and the negative power lead from the battery. Cover in insulating tape.

  4. Repeat for the positive wires.

  5. Use a short piece of wire to connect pins EN to GND on the liposhim. This powers off the pi. While doing this, insert your SD card and remove the wire. Your Pi will start to boot. You should see various LEDs - the blue power LED on the LipoShim, the green activity LED on the pi which should boot up, and possibly the green radio LED on the RileyLink. (Note that the little switch on the RileyLink  needs to be turned on, ie pushed toward the USB connector).

  6. Test things are working - ie that you can SSH to the pi, and that the RileyLink can control pods via AndroidAPS.

  7. Drop the setup into a [business card] box. It should be quite a tight fit.

  1. With a craft knife, lightly mark out the location of the USB charging socket on the charging module onto the case. Remove all the circuitry then cut out a hole for the charging. Reinsert the setup  and make an assessment of the height. Then use a craft knife to trim the box to height. Repeat the process (hole for charging & trim for height) with the lid. Mine ended up about 20mm thick, giving a pocketable overall size of 100x65x20mm.

  2. I cut some random other bits of plastic to size to fill gaps / stop things rattling around (also mounted the charging module onto one of these), then fitted them in place with sticky tabs.

  3. If needed - line all or part of the inside of the lid with electrical tape - I found the LEDs were rather bright overnight.

  4. If needed, make yourself a label for the back with contact details and perhaps a logo to indicate this is a medical device - eg https://goo.gl/images/rVvM4q

  5. The hardware aspect is done! You charge via the micro usb charge socket into the charging module - red LED on module when charging. That charges the battery which is shared between RileyLink and pi. I've found that 4200mah battery happily lasts a day (this should do around 30 hours on a full charge).

  6. Note: In this setup, if you need to turn off the pi (eg if you want to remove the sd card) type at the SSH shell:

sudo shutdown now

To turn the pi on again, take a short length of wire and use it to connect the EN and GND pins together on the LipoShim (effect of this is to turn off the power from LipoShim to the pi). Then remove the wire (which turns power to pi back on) and the pi will boot up.

Software setup

  1. It is necessary to install the software associated with the LipoShim - at the SSH command line enter

curl https://raw.githubusercontent.com/dexdan/clean-shutdown/master/zerolipo_omnipy | bash

This will install code to safely shut down the pi if the battery is running out. This is important - without it, sudden loss of power to the pi could trash the sd card. More details of the code, if needed, are at https://github.com/pimoroni/clean-shutdown/blob/master/README.md.

  1. (Optional battery measurement) Install libraries necessary for battery measurement. At the SSH command line enter

sudo apt-get install python3-rpi.gpio

This will install the GPIO libraries necessary to use the voltage measurement. If your version of Omnipy is prior to 1.4.2 (6 May 2019) you will also need to upgrade it to include battery measurement.

  1. (Optional battery measurement) In AndroidAPS, under preferences / overview / advanced settings, you can change the (rig) battery level at which you want the 'BAT' text on the home screen to turn amber or red. If you want to see the battery percentage on the watch, you need to do two things. First, in the Wear settings (on the watch), select 'show rig battery'.

Second, the AndroidAPS-omnipy code needs amending. In Android Studio, search for WatchUpdaterService.java. Change line 734 - FROM

String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim();

TO -

String rigBattery = Integer.toString(ConfigBuilderPlugin.getPlugin().getActivePump().getBatteryLevel()) + "%";

Then rebuild you APK and reinstall on your phone. This then will show rig battery on your watch. (The first % in the white band is phone battery; the second percentage rig battery).

The battery level is also available in Nightscout if you hover the 'pump' pill.

  1. If you are finding power doesn't last a day then try disabling the hdmi on the pi - this should save 400-600mah per day. See https://www.jeffgeerling.com/blogs/jeff-geerling/raspberry-pi-zero-conserve-energy.

CPU temperature

My experience has been that no heatsink is needed on the Raspberry Pi, given the relatively low CPU load put on the processor by Omnipy. However, if you want to check the CPU temperature to make sure, use the command /opt/vc/bin/vcgencmd measure_temp. Any temperature above 80degC is too hot and will require a heatsink. (Although my experience is that temperatures are in the low 40degCs.

Alternative rig setups

Alternatives to the Pimoroni LipoShim to power the pi from a lipo are the AdaFruit Powerboost 1000 (https://www.adafruit.com/product/2465), and the JuiceBox Zero (https://juiceboxzero.com/). The latter is not particularly recommended though as it is difficult to mount in a case, and some have reported overheating.