Skip to content

Creating my own artificial pancreas

This post elaborates on my findings about creating my own artificial pancreas with the Open APS documentation

First of all, I would really like to applaud Dana Lewis, Scott Leibrand and the whole community behind Open Aps for making this possible. Their hard work, dedication and open source mentality, gave me hope for the first time in 20 years for a better diabetes management!

Step 1: Ordering all the necessary supplies
I order components for following loop : Freestyle libre > Blukon > Iphone > Nightscout > rig > Medtronic pump

  1. Explorer Block (+- €75 + shipping costs) : This component quickly gets out of stock and took around a month for shipping
  2. Intel Edison breakout board kit (+- €80): Difficult to find a flashed Edison version, so had to order an unflashed Edison as part of a breakout kit. I had first found a flashed version (Intel EDISON edi2.lpon.Al.S compute modules , €134) , but after a week delivery was cancelled.
  3. Lipo battery (Adafruit 328 Battery, Lithium Ion Polymer, 3.7V, 2500mAh, 2″ x 2.55″ x 0.30″ Size ): Since I had not much knowledge about which battery was right, I had to look up what all the terminology meant
  4. 2 USB cables: I thought any micro cables would do, but apparently some cables only provide power transfer and not data so I could not use every cable
  5. Freestyle libre sensor
  6. Blukon (€135 + shipping costs): This has to ship from America and takes around 2 months to arrive in Belgium. I also had to pay around €35 shipping taxes
  7. Compatible pump: I was very lucky to have a 722 medtronic pump lying around. I had looked for an extra pump, but this quickly costed around €3000 to find this on the black market

General conclusion: ordering these parts took in total 2 months (finding the right components, shipping time, …) and costed me in total around €500.

Step 2: Creating a CGM system
Even though the OPEN Aps documentation has documentation about generating a CGM with the freestyle libre and blukon, no stable version was available for this in combination with an iphone (only worked good for android). At the time, a testflight version of the IOsXdrip could be requested by sending an email to the developer of this app. Since I had sent an email but did not get any reply, I started developing my own app in react native. After a month of trial and error, I resent an email to the iosXdrip-developer and received a testflight. At that time , I was so far in developing my own application, that I used the code from iosxdrip as a reference, but continued my own development.

I struggled with following things:

  1. Writing the right bluetooth commands for blukon in hex
  2. Calibration algoritm
  3. Keeping bluetooth working in the background
  4. Send push notifications with react native
  5. Offline bg handling

Every obstacle will be explained more in detail below.

Step 2.1: Writing the right bluetooth commands
In react-native , you can write and receive messages from a bluetooth device with the following library : BLE Manager
Detecting devices is easy. You quickly get a whole list.
Knowing which device was the blukon device, was not so obvious in the beginning since I had no idea what the name of the device would be. After pushing the ‘blukon-reset-button’ for a few times and rescanning the environment, I learned the bluetooth device name starts with BLU.
After scanning, connecting, requiring the services and starting a notification, You have to know the exact ‘hex’ commands to sent to the device to get the right answers back. For this I used the iosXdrip as a reference and tried command after command to see the result. A few days and commands later, I finally was able to get my first bg value. However the result was not quite what I expected. After adding a Freestyle libre multiplier (1/8.5 , reference iosxdrip ) , I had a result of around 300 000. (knowing that glucose has a range from 0 – 500) . Later I discovered in another iosxdrip-file, that I had to divide this by 1000, which already made more sense. After lot of testing and comparing with real blood glucose values (by a finger prik) , I understood the need for a good calibration algoritm. (See step 2.2)

Step 2.2: Calibration algoritm
Although the iosxdrip-app offered a calibration mechanism and I tried it with different options, I was not able to get any good values out of it. It always gave me a function with a slope of 1 (y = 1. x + residu). I developed a smart learning linear regression function that automatically calculates the function coefficients based on the calibration values. The more calibrations you give, the better the function.

Step 2.3: Bluetooth in background
When running my app at night, I discovered that it disconnected the blukon reader, when it got in the background. In order for my bluetooth to keep working, I added 2 variables to the info.plist in xcode


And added an handleAppState-function

handleAppStateChange (nextAppState) {
    console.log('changing appState', nextAppState)
    if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
      console.log('App has come to the foreground!')
      BleManager.getConnectedPeripherals([]).then((peripheralsArray) => {
        console.log('Connected peripherals: ' + peripheralsArray.length)
    this.setState({appState: nextAppState})

Step 2.4: Push notifications
Another disadvantage of running an app in the background , is that it does not show any UI-changes (including sounds and alarms) . For this I had to enable push notifications with the react native push notification library. For this you need to update the app certificate in the apple developers portal to enable push notifications and allow it in the capabilities in XCode.
See the library documentatio and Facebook documentation on how to do this

Step 2.5: Offline handling
Since the app cannot always be connected to the internet, I had to adapt my react-native actions to always add bg-values to the store, but retry to push it to the nightscout databank as soon as internet is back up.

Step 3: Bulding the rig
Building the rig went quite fast. However, flashing the edison, was harder. In the middle of the flashing process on mac, it crashed and no longer showed my Edison on my computer. After a lot of research, I discovered that it was impossible to recover it on a mac, so I had to install ubuntu on an external usb as a new OS. This website has great steps on how to do this. On a mac, you cannot use ‘universal-usb-installer-easy-as-1-2-3/’ so you have to convert the downloaded ubunto.iso file to an img on your desktop (See this website for detailed instructions or follow the steps below)

hdiutil convert -format UDRW -o Desktop/Ubuntu.img Desktop/ubuntu.iso

then install it via terminal. Replace the ‘#’ in the codewith the disk number (which you can find with ‘diskutil list’ and reconnecting-disconnecting your device in order to see the difference in the list.

diskutil unmountDisk /dev/disk#
sudo dd if=Desktop/Ubuntu.img of=/dev/rdisk# bs=1m
diskutil eject /dev/disk#

AFter this you can restart you computer with ‘option’ and select the right drive. Ubuntu will now start and you can continu the rest of the steps. For this you need to be connected to the internet cable so you can download certain packages on your ubuntu. (In the manual, it says you need to install those packages on the usb stick along side with your OS, this however is not as easy as just downloading them from the browser when ubuntu is open)

Published inIOT

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *