How I designed a “DIY” closed loop artificial pancreas

This post was written months ago for Prescribe Design, and will also be posted/made available there as a collection of their stories by and about patients who design, but I am also posting here for anyone new to #DIYPS and/or wondering about how #OpenAPS came into existence.

About the author: Dana Lewis is the creator of #DIYPS, the Do-It-Yourself Pancreas System, and a founder of the #OpenAPS movement. (Learn more about the open source artificial pancreas movement at OpenAPS.org.)  Dana can be found online at @DanaMLewis, #DIYPS, and #OpenAPS on Twitter, and also on LinkedIn.

Diabetes is an invisible illness that’s not often noticeable, and may be considered to be “easy” compared to other diseases. After all, how hard can it be to track everything you eat, check your blood glucose levels, and give yourself insulin throughout the day?

What most people don’t realize is that managing diabetes is an extremely complex task; numerous variables influence your blood glucose levels throughout the day, from food to activity to sleep to your hormones. Some of these things are easier to measure than others, and some are easier to influence than others, as I’ve learned over the past 13 years of living with type 1 diabetes.

Dana Lewis finishing the Leavenworth half marathonDiabetes technology certainly helps – and those of us with access to insulin pumps and continuous glucose monitors are thankful that we have this technology to better help us manage our disease. But this technology is still not a cure. After I run a marathon, my blood sugar is likely to run low overnight for the next few nights. And the devices I use to help me manage still have major flaws.

For example, my continuous glucose monitor (CGM) gives me a reading of my blood glucose every 5 minutes – but I have to pay attention to it in order to see what is going on (pulling the device from my pocket and pressing a button to see my numbers). And what happens when I go to sleep? I am sleeping, rather than paying attention to my blood sugar.

Sure, you can set alarms, and if your blood glucose (BG) goes above or below your personal threshold, an alarm will sound. That’s great, unless you’re a sound sleeper like me who doesn’t always hear these sounds in my sleep – and unfortunately there’s no way on the device to make the alarms louder.

For years, I worried every night when I went to sleep that I would have a low blood sugar, not hear the alarm, and not wake up in the morning. And since I moved across the country for work, and lived by myself, it could potentially be hours before someone realized I didn’t show up for work, and days before someone decided to check on me inside my apartment.

I was worried about “going low” overnight, and I kept asking the device manufacturers for louder alarms. The manufacturers usually responded, “the alarms are loud enough, most people wake up to them!” This was frustrating, because clearly I’m not one of those people.

I realized that if only I could get my CGM data off my device in real-time, I could make a louder alarm by using my phone or my laptop instead of having to rely on the existing medical device volume settings. It would be as easy as using a basic service like IFTTT or an app like “Pushover” that allows you to  customize alerts on an iPhone.

However, for the longest time, I couldn’t get my data off of my device. (In fact, for years I had NO access to my own medical device data, because the FDA-approved software only ran on Windows computers, and I had a Mac.) But in November 2013, I by chance found someone who tweeted about how had managed to get his son’s data off the CGM in real-time, and he was willing to share his code with me. And this changed everything.

Taking a photo of a CGM screen and printing it out is not very efficient for reviewing BG data.(At the time, my continuous glucose monitor only had FDA-approved software that could be used on a Windows computer. Since I had a Mac, when my endocrinologist asked for diabetes data, I took a picture with my iPhone and pasted the images into Excel, and printed it out for him. Data access is an ongoing struggle.)

My design “ah-ha” became a series of “wow, what if” statements. At every stage, it was very easy to see what I wanted to do next and how to iterate, despite the fact that I am not a designer and I am not a traditional engineer. I had no idea that within a year I would progress from making those louder alarms to building a full hybrid closed loop artificial pancreas (one that would auto-adjust the levels on my insulin pump overnight).

Once I had my CGM data, I originally wanted to be able to send my data to Scott (my then-boyfriend and now husband, who lived 20 miles away at the time) to see, but I didn’t want him to get alarms any time I was merely one point above or below my target threshold. What was important for him to know was if I wasn’t responding to alarms. We set up the system so that Scott could see whether or not  I was taking action on a low reading, which I signaled by pressing a button. If the system alerted to Scott that I was not responding to a low reading, he could call and check on me, drive 20 miles to see me, or call 911 if necessary. (Luckily, he never needed to call 911 or come over, but within a week of building the first version of the system, he called me when my blood sugar was below 60 and I hadn’t woken up yet to the alarms.)

DIYPS prototype with Pebble
DIYPS prototype with Pebble

I realized next that if I was already pushing a button on the web interface (pictured), I might as well add three buttons and show him what action I was taking (more insulin, less insulin, or eating carbohydrates) in case I accidentally did the wrong thing in my sleep. I also customized the system so that I could log exactly how much insulin I was taking or how much I was eating.

Because I was entering every action I took (insulin given, any food eaten), we realized that this data could fuel real-time predictions and give precise estimates of where my blood sugar would be 30, 60, or 90 minutes in the future. As a result, I could see where my blood glucose level would be if I didn’t take action, and make sure I didn’t overcorrect when I did decide to take action. This was helpful during the day, too. The CGM has alarm thresholds that notify you if you cross the line; but #DIYPS will predict ahead of time that I am likely to go out of range, and will recommend action to help prevent me from crossing the threshold.

The system worked great and generated many alarms that woke me up at night. (Ironically, we generated so many alarms that Scott would periodically change the sound of the alarm without telling me, because my body would get used to ignoring the same sound over time!) The next step was deciding to get a smart watch (in my case, a Pebble) so I could see my data on my watch, and reduce the amount of time I spent pulling my CGM receiver out of my pocket and pressing the button to turn the screen on. With a watch, it was also easier to see real-time push alerts that the system would send me to tell me to take action. As a result, I was able to begin to spend less time throughout the day worrying about my blood sugar, and more time living my life while the system ran in the background, updating every few minutes and alerting me as to when I needed to pay attention when something changed.

We called this system the “Do It Yourself Pancreas System”, or #DIYPS, and we developed it completely in our “free time” on nights and weekends.

People often ask what my health care provider thinks. He didn’t appear very interested in hearing about this system when I first mentioned it, but he was glad to hear I was having positive outcomes with it.

More significantly, I had a lot of other people with diabetes interested in it and wanting to know how they could get it.

As a patient, I can only design tools and technology for myself; but because it would be seen by the FDA as a class III medical device (and making dosing recommendations from a CGM rather than a blood glucose meter, which the CGM is not approved for), I can not distribute it to other people to use as it would have to first be reviewed and regulated by the FDA.

With this in mind, Scott and I were both also working with the Nightscout project (another community-developed DIY tool that helps you share or more easily view your diabetes data). We were able to incorporate some of the key features we had built in #DIYPS, like the visualization predicting where the blood glucose would be based on carbohydrates and insulin activity.

We also kept iterating on #DIYPS and the algorithms I use to predict when my blood sugar is going to end up high or low. By the time we made it to November of 2014, we realized that we had a well-tested system that did an excellent job giving precise recommendations of adjusting insulin levels. If only we had a way to talk to my insulin pump, we theorized that we could turn it into a fully closed loop artificial pancreas – meaning that instead of only allowing my insulin pump to give me a pre-determined amount of insulin throughout the night, a closed loop system would instead take into account my blood sugar and make the automatic needed adjustments to give me more or less insulin as needed to keep me in range.

Components of an #OpenAPS implementation: pump; CGM; Raspberry Pi with battery and a radio communication deviceWith the help of Ben West, another developer we met while working on Nightscout, who has spent years working on tools to communicate with diabetes devices, we were able to take a carelink USB stick and use it to communicate with my insulin pump. Plugged into a raspberry pi (a small, pocket sized computer), the carelink USB stick could pull from our algorithms, read from the pump, write commands (in the form of temporary basal rates for 30 minutes), read back the results, update the algorithm and generate new predictions and action items, and then do the same process over and over again.

And so, with the help of various community members, we had closed the loop with our artificial pancreas. And once I had it turned on, testing, and working, it was hard to convince me to take it off. This was December of 2014. More than a year and a half later, I’m still wearing and using it every day and night.

Dana BGs with OpenAPS

There are definitely challenges to having self-designed a device. There are usability issues, such as the burden of keeping it powered and extra supplies to haul around. But as a patient, and as the designer, I can constantly iterate and make improvements to algorithms or the device setup itself and make it better as I go, all while having the benefit of this lifesaving technology (and more importantly, having the peace of mind to be able to go to sleep safely at night).

And, I have the ability to communicate and spread the word that this type of DIY technology is possible. I frequently talk with others who are interested in building their own artificial pancreas system as part of the OpenAPS movement. Like #DIYPS, I can’t give away an #OpenAPS implementation or build someone else an artificial pancreas. But through #OpenAPS, the community has collectively published a reference design, documentation and code, and established a community to support those who are choosing to do an n=1 implementation, following the reference design we have shared. As of the beginning of May 2016, there have been a total of 56+ people who have decided to close the loop by building individual OpenAPS implementations, with more in progress. (And today, you can see the latest community count of DIY closed loopers here.) You can read more here about the risks and how it is a personal decision to decide to build your own system; each person has to decide if the work to DIY and the risk is worth the potential reward.

For me, this definitely has been and is worth the time and effort. It’s worth noting that I am glad there are traditionally designed devices going into clinical trials and are in the pipeline to be made available to more people. But the timeline for this is years away (2017-2018), so I am also glad that the technology (including social media to enable our community to connect and design new tools together) is where it is today.

You don’t have to be an engineer, or formally trained, to spot a problem with disease management or quality of life and build a solution that works for you. Who knows – the solution that works for you may also work for other people. We can design the very tools we need to make our lives with diabetes, and other diseases, so much better – and we shouldn’t wait to do so.

The power of visualizing your data, your way

Sometimes, it’s the little things that make a big difference – even little glimpses of data, or little improvements to ways that you can control the way you access and view your data (and generate alarms).

For example, I recently had a conversation with a few people in the #WeAreNotWaiting community about the different watch faces that exist for displaying CGM data; and about how much I like my #DIYPS watch face. A few reasons why:

  • It’s a little more discreet than some watch faces showing BG data, so the average person won’t glance at my watch and see a large number.
  • It pulls from the #DIYPS interface, so I can see what I’m predicted to be, and any current recommendations (such as carbs, temp basal, or bolus needed).
DIYPS watchface showing Dana M. Lewis's OpenAPS data

It’s data-heavy, but I like having all this information without having to pull my CGM out and run calculations in my head; or pull out my phone and pull up a web page to #DIYPS; etc.

One of the many cool things about the #WeAreNotWaiting community is how together we have learned and created so many new ways to visualize our data, on various devices (tablets, phones, smart watches) and various size screens. And so when I hear that someone’s not wanting a smart watch, or isn’t using it for diabetes related things, sometimes I think it’s a matter of them finding the right tools to build their own display that works for them. Several times a week I hear about various people working on new, interesting DIY diabetes projects, and it’s awesome that we have tech to improve the tools we have – and excellent social media channels to communicate about these projects.

Related to that, I wanted to share an update – recently Milos, Jason, and others have done some really amazing work to visualize basal rates in Nightscout. (If you use Nightscout, you can get this in the 0.8.2 release – see here for more details.) This means it also can pull in temporary basal rates that are used in #OpenAPS, so you can get a nice visual showing the adjusted basal rate compared to normal scheduled basal rates – and see why it might be needed – on top of display of BG data and everything else that Nightscout offers.

Showing a fake drop in CGM glucose data that is a compression drop

In this example, it also shows how OpenAPS deals with compression drops, or how it might react to other flukey data. Remember, we designed OpenAPS to only enact 30 minute temporary basal rates in a way that is the safest possible thing to do, even if it loses communication. But if it keeps communication, and the system sees a drop and a return to the normal pattern from before (see visual), it can counteract a low temp with higher temp, or vice versa.

The visualization of temp basals in Nightscout (another example here) is an excellent improvement over how I previously used to check and see what OpenAPS had been doing. I have a watchface (similar to the above #DIYPS one) that shows me what the loop is doing currently, but when I wake up in the morning, I was mostly using a basic screen like the below to see the positive, negative, and net temp basal rates on an hourly basis and comparing that to my CGM graph to get an understanding of what happened.

Less insulin needed and OpenAPS reduced accordingly

Visualizing basal rates in Nightscout is a seemingly minor change, but every time we make a change like this that allows me to contextualize all of my data in one place (on a single glanceable watchface; or on the Nightscout screen); it saves a few seconds or minutes that add up to a lot of time saved every day, week, month, and additional year that I’m dealing with diabetes – a big win.

Does the FDA care more about safety than people with diabetes do?

Today my inbox was suddenly flooded with links to a video with some commentary about artificial pancreas technology at a conference by a representative of the U.S. FDA. The implication many people are getting after watching the video clip is that this FDA representative is implying that people are being unsafe by building their own artificial pancreas. He mentions it is consumer prerogative to build an artificial pancreas – which is correct. The implication of his analogy is that changing your car and killing yourself is similar to a DIY artificial pancreas effort.

The scary takeaway from the video, in my opinion, as well as other public comments in the past, is the implication that the FDA cares more about the potential harms of taking action than the almost certain harms of inaction. And it’s increasingly frustrating that the FDA appears to imply publicly that those of us in the #wearenotwaiting community are doing things unsafely as a result of taking action.

Safety is what drives the #wearenotwaiting movement. In my case, I refuse to sleep another night with the fear that I won’t wake up in the morning because there’s not an FDA-approved system on the market that will wake me up if my life is in danger, let alone a system that can take action and change the situation to be more safe. So I built my own (#DIYPS), because the current FDA-approved CGM devices were not (and still are not) loud enough to wake me up at night, putting me at risk of dying in my sleep. And yes, it ultimately turned into an artificial pancreas – with the same goal of ensuring I wake up every morning, safely (alive). That is my prerogative for sure.

But I fail to see why the FDA, which collectively has no particular knowledge of these systems (especially as they have no jurisdiction, acknowledged on all fronts, over what I do myself – it’s my prerogative), is making public statements implying that these types of systems are categorically unsafe.

As a matter of fact, every DIY system I’ve seen is safer than the FDA-approved standard of care available for people with diabetes. The thousands of people using Nightscout, which is currently a DIY remote view-only monitoring system? Provides more safety and security for people with diabetes, not to mention it is helping achieve better outcomes for people with diabetes than they were able to achieve before with the standard of diabetes care as it exists today. (This was originally for the most part because of restricted access to data, although while that has improved there’s still interoperability issues getting access to real-time data in the same place from the 3+ average devices a person with diabetes uses…unless they have Nightscout or another DIY tool running.) The dozens of people working on their DIY version of an artificial pancreas system (many of whom are collaborating and sharing data in the #OpenAPS community)? These systems are safer than the standard of care, which is to let an insulin pump continue to overdose you if you are dangerously low while you sleep.

(You can see some of my personal data from #DIYPS, before we closed the loop, here and more about outcomes after we closed the loop and had #OpenAPS here. My closed loop artificial pancreas system continues to work excellently nine plus months in, and you can continue to watch my outcomes as I post them to Twitter regularly using the #DIYPS and #OpenAPS hashtags. I’ve also shared the other powerful lessons that DIY tech has helped me learn about diabetes care that helps all people with diabetes, regardless of technology.)

Are there risks to DIY efforts? Yes. But there’s risks to living with diabetes regardless. And as a person with diabetes, I am well aware of the risks that I choose to take. Diabetes is a disease in which you carry around large amounts of a lethal drug in your pocket that you are supposed to inject daily in order to save your life. As a person with diabetes, we are nothing but aware of the multitude of risks of living with this chronic disease 24/7/365.

In fact, even without a DIY artificial pancreas system, I am at risk every day simply from using my FDA-approved insulin pump that does not accurately track how much insulin I am given. (Read more here about how most insulin pumps on the market calculate IOB only from boluses, and often do not provide a record let alone incorporate any temporary adjustments to your basal rates and do not in any case track the impact of suspending your pump completely.)

And as someone who has founded the #OpenAPS movement, with the goal of an open and transparent effort to make safe and effective basic Artificial Pancreas System (APS) technology widely available to more quickly improve and save as many lives as possible and reduce the burden of type 1 diabetes…..we approach it with safety first in mind, and is a big part of why the DIY part is critical and is a part of our number one priority of safety.

Not everyone will choose to go the DIY route. In fact, most people do not and I am told all the time “Oh, I would never do that.” And that’s fine! Everyone can choose what they want for themselves.

But technology has made it increasingly feasible for those of us who want to improve our own safety to do so, because the industry and the FDA are not moving quickly enough to meet our needs.

That, indeed, is our prerogative – to increase our own safety.

#DIYPS and the wedding

“Diabetes wasn’t in the picture during the wedding, and that was exactly how it should be.”

Dana Lewis and Scott Leibrand said "I do!"

 

If you’re not familiar with Scott & me (Dana), and how we ended up building #DIYPS and later #OpenAPS, you might be interested to read this great article in Business Insider. (And I’ve been told it’s guaranteed to make you go “awww” even if you already sort-of know us!)

I love that it also highlights how #DIYPS played into our wedding, which was exactly how I wanted it: I hardly thought about diabetes at all. I didn’t have to cut into the lining of my wedding dress to carry d-supplies. In fact, up until the last minute, I wasn’t sure if I was going to carry the closed loop during the wedding itself, because I had decided not to put pockets in my dress and I wasn’t sure Scott’s suit had big enough pockets to hold everything.

But just like all things in this #DIYPS and #OpenAPS journey, a couple of serendipitous events gave us our solution.

First, we were in Alabama for the week before the wedding, and I was working a few days remotely there. But I like to move while I work, and so I’d move around the house (and go outside) with my laptop while I was on calls. This led to Scott getting no data alerts and no-loop-running alerts, and randomly chasing me down to re-plunk the loop down into range. Finally, he asked if I would consider a fanny pack. I laughed, and told him no way, and that HE should wear a fanny pack. Then I remembered hearing about flip belts and thinking about getting one at one point to try for running. So, we made a quick Amazon purchase (where all great artificial pancreas parts come from ;)).

Scott probably thought he’d get me to wear the flip belt around the house (it is purple, after all), and maybe at the wedding, but when it arrived two days before the wedding and I was busy working, he actually put it on, placed all the loop parts inside, and then decided to try putting his tux coat on over it.

It didn’t show.

And this is how *Scott* ended up wearing the belt and the AP parts during the wedding (he’s wearing it above and you can’t see it!). I obviously was stilling wearing my pump and my CGM sensor under my dress where it wasn’t showing. We also gave my second CGM receiver to Tim ( Scott’s brother and best-man-extraordinaire), who also wore Scott’s watch for much of the day and helped give me updates on my BGs when Scott & the loop were out of range prior to our “first look”.

As a result of having #DIYPS/#OpenAPS, my BGs had been picture perfect the night before the wedding, and were within range all afternoon leading up to the wedding. (They were fine during and after the wedding, too, so much so that it never occurred to me to take more pictures of my graph, which shows how perfect it was to have diabetes not on my mind!)

This may have been (one of) the first wedding(s) with an artificial pancreas in it, but we bet it won’t be the last – one of our friends in the Seattle area who is now up and running on #OpenAPS is also getting married next month, and he may wear his loop during his wedding, too!

We like this trend.

What we’ve been up to – mostly offline #OpenAPS

It’s probably time for an update around here – especially since we’re nearing the “deadline” we set for closing the loop – August 1, 2015!

August 1 is our wedding date, which is part of the reason it’s been quiet around here as we are off busy preparing for that.

The other reason it’s been quiet (unless you follow me on Twitter and see some of the #DIYPS examples there) is because we closed the loop back in December (read more about it here), and we haven’t made any significant updates to the #DIYPS system.

It’s all working well.

Showing a relatively flat CGM graph despite a 75 gram carbohydrate meal, thanks to OpenAPS.

What we’ve been focusing on most of the year is supporting the #OpenAPS community. In particular, we’re trying to help more people learn what they need to understand so that they can build their own loops. There’s a handful who have made or are making excellent progress, and hopefully we’ll have some OpenAPS data to share soon.

Most recently, spotty hotel internet in Portugal helped prompt us to finish the offline version of #OpenAPS, which I’ve been testing. (And will use the honeymoon, wherever that ends up being, as an opportunity for more testing!) #DIYPS has always required internet connectivity to get the recommendations from the cloud (which is where it stores the data I give it about boluses and carbs). The reliance on connectivity is always something to troubleshoot if the system appears to not be working, and also makes it burdensome to carry around all the time and make sure it has connectivity.

Getting offline looping of CGM data to OpenAPS.

Offline OpenAPS will likely solve a big part of the frustrations I experience with daytime use of the system. I already saw a big improvement in being able to use offline OpenAPS in Portugal – both at the conference and in the hotel, as well as walking the streets of London during a layover. It’s nice to drop the system (the same Raspberry Pi, battery, and carelink stick from DIYPS) in my bag and not have to constantly check to make sure the wifi hotspot is connected. The only difference in the setup is that one of my CGMs is plugged directly into the Raspberry Pi.

Showing my OpenAPS rig against the plane window to illustrate offline steam of BGs to OpenAPS is working

We still need to do more testing on our offline implementation of OpenAPS, but it’s going well and I’m excited that what we’ve learned from this progress will help us with better tools to enable the broader OpenAPS community since #WeAreNotWaiting!

Context – give me my data (on my device)

Today I saw that Medtronic announced a partnership with IBM. You can read about it on Twitter, where I first saw it, or elsewhere online. There’s lots of news articles and PR about it, too, which I haven’t read yet in great detail.

My initial reaction:

Pointing out that I can't get temp basal histories on my insulin pump

Additional context:

When I reduce my insulin (either by “suspending” the pump’s activity altogether, or by reducing my basal rate with a “temp” or temporary basal rate), there’s no record of it visible on my insulin pump.

None, at all.

Suspended for 15 minutes while I’m in the shower? No record of it if I accidentally resume insulin activity before checking to see when I suspended it.

Same for if I go running and activate a reduce basal rate (again, a “temp”) of 0.3u/hour instead of my usual 1.3/hour. That’s 1u less of insulin than I normally get. If I cancel it, or if that hour ends without me noticing it?

No record at all.

Which means if my blood glucose skyrockets an hour later, it will take me much longer to catch up with insulin if I don’t realize that I’m -1u (negative one unit) below what my body is used to.

Suspending your pump for 3 hours to go swimming? Same deal. Your body has less insulin than it’s used to, but you have to manually and mentally keep track of it.

The reverse is true as well – if you are sick and your body is more resistant to insulin than usual, and you use a higher basal rate than your usual as a way to additionally correct for a high BG?

No record of the additional insulin you’re putting into your body above your baseline basal profile.

THIS IS DANGEROUS.

And yet this is the FDA approved medical device that everyone is happy that I’m using? Even with critical flaws that endanger my life every day?

And the world has a problem with patients “hacking” or otherwise finding ways to access this critical data since we can’t get it from our approved devices?

This is backwards.

Medtronic and other pump brands track how much “insulin on board” (aka IOB) you have…but this number is wrong, because it doesn’t calculate the lack of insulin if you adjust your basal rates (examples above).

This is something I’ve been doing with #DIYPS to compensate for the inaccessibility of data from my FDA-approved medical device. Instead, I have to calculate for myself the “net” IOB number that takes into account any ‘negative’ corrections from suspending or negative or positive temp basal rates. These make a huge difference in my diabetes care.

We’ve learned from talking to people about #DIYPS for a year and a half that many people don’t use temporary basal rates, even though they’re very effective to ward off future lows and highs.

Why?

For one thing, it’s because there’s no record in their pumps. It’s too hard, and too much guesswork when there’s no record.

I don’t understand why the pump companies seem to ignore this. (If someone has a pump that tracks net IOB and/or shows a history of temporary basal rates and suspension, let me know. I’m familiar mainly with Medtronic’s pumps.)

This is not ok.

So while I think there’s a lot of potential for Medtronic to do more things with diabetes data (like this or this) through this partnership with IBM’s Watson? In the meantime, I’d like them to start with something much more simple – and with guaranteed impact.

Give me, the patient, my data that I need – directly on my medical device – so I can safely take care of myself and better manage my diabetes.

(Note – I realize FDA approval cycles on pumps take a long time, and this is unlikely to get fixed in current pumps. But future pumps? This should be fixed across the industry. And in the meantime? Companies can and should make it much easier to access data from the pumps via their approved uploader methods and make it easier to read the data. Right now, it’s not even easy to see the data off your pump. Let’s change this.)