← Harley TuranJune 2022

Continuous Glucose Monitoring on the Apple Watch

Hi! 👋 I'm Harley, and I'm a type 1 diabetic.

Type 1 diabetes (diabetes mellitus type 1, often shortened to T1D) is a chronic auto-immune disease with no conclusive known cause. The disease causes the body's immune system to attack and destroy the insulin-creating cells in your pancreas (the islets of Langerhans).

Now, that's not great, because it turns out insulin is fairly important for the day-to-day functioning of the human body. It's used by the body to allow muscles, fat, and the liver to absorb glucose out of the bloodstream. Without it, glucose remains in your bloodstream until your blood turns into strawberry Kool-Aid and you die.

Type 1 diabetics like myself make up between 5 and 10% of all diabetics (around 0.015% of the world's population), and the disease is managed by effectively becoming a walking, talking pancreas — we constantly measure our blood glucose levels, calculate the number of grams of carbohydrate in any food or drink we consume, identify the glycemic index of different parts of a meal, and make thousands of calculations per day regarding our activity, future plans, stress levels, caffeine levels, body temperature, injection site scar tissue, amount of sleep, and current insulin resistance (among dozens of other variables).

When a type 1 diabetic consumes any food, they will use a ratio of the number of grams of carbohydrate in the food and the number of units of fast-acting insulin required and inject to attempt to offset the amount by which their blood glucose will rise. If you inject too little, your blood glucose levels rise, resulting in hyperglycemia. Inject too much, and your blood glucose levels drop, resulting in hypoglycemia.

The dozens of factors that affect blood glucose and insulin uptake mean that there's no such thing as perfect blood glucose management for a type 1 diabetic; eating and injecting the exact same thing on two subsequent days can have wildly varying results. It's a constant game of push-and-pull between insulin being injected and glucose being consumed. If your blood sugar is low (hypoglycemia), you take fast-acting glucose to bring it up, and if your blood sugar is high (hyperglycemia), you take fast-acting insulin to bring it down. It's a feedback loop that requires constant manual intervention, and you can't afford to not keep the loop running.

Luckily for me, I was diagnosed with T1D at the fairly late age of 16, so I've only had to go to sleep roughly 5,110 times worrying about my blood glucose levels. I'm currently hitting a ~0.9994 wake-up-without-being-surrounded-by-paramedics-after-having-a-diabetic-seizure batting average too, which I'm quite proud of. I've had an accidental insulin overdose (injecting insulin during the confusion of severe hypoglycemia), called emergency services for assistance, and then been classed as a suicide risk by the UK's National Health Service.

I won't touch too much on the mental toll this can have, but it's a lot to think about on a daily basis — not only for myself, but for everyone I hold dear. Diabetic burnout is a real thing. If you're reading this and suffering with T1D, or have someone close to you who suffers from T1D, just know that regardless of all the other current stresses of day-to-day life, you're doing an incredible job keeping going.

So, when a 20% mis-calculation when injecting insulin for an evening meal can be enough to mean that you don't wake up the next morning, and there are hundreds of variables that can affect your blood glucose on any given day, there's only one real way to live your life as normal — monitoring your blood glucose constantly.


The primary way by which type-one diabetics measure their blood glucose readings is by pricking your finger, squeezing out a drop of blood, dropping that blood onto a stick, and waiting for a pocket-sized machine to give you a number — what you might have heard of as a "finger prick" test. This number will be the amount of glucose in your blood at that point in time.

There have been a number of innovations in glucose monitoring over the previous couple of decades, but for me the Abbott FreeStyle Libre changed everything. A coin-sized sensor that gets applied to your arm, the Libre has a small filament which measures the glucose levels in your subcutaneous fat layer. With a simple NFC scan from a pocket reader (and later, a smartphone) you could now test your blood glucose levels without drawing blood and managing the disposal of biohazardous waste. The Libre is available on the NHS for all UK citizens, or is available privately for ~£57 per sensor. Each sensor lasts for two weeks and is non-removable for the duration.

Because of this convenience and lack of disposable resources, the key innovation with the Libre (known as a flash glucose monitor) is the giant increase in the data resolution available. Diabetics can now check their blood glucose dozens of times per hour if they want, rather than the usual six times per day with fingerpick tests. This increased resolution gives us far, far more insight into how our bodies react to insulin, and lets us have detailed insight into the trends as our glucose levels drop and spike throughout the day.

Think about this — with six data points of resolution, you have no clue as to the direction your blood glucose is travelling. If you're off to bed, take a finger-prick test, and see 6.0, that could mean that your blood glucose levels are perfect, that your glucose levels are dropping rapidly, or that your glucose levels are rising rapidly. The main innovation of the Libre is being able to easily determine the direction of your blood glucose at any moment in time.

Of course, each of those checks still requires us to unlock the phone, open the LibreView app, navigate through a couple of three-year-old memory leaks, rub the phone against our arm through a layer or two of clothing (best of luck in the Winter here in London), and then view the result. Again, a huge, huge leap forward in convenience, but once you're used to this, it's not convenient enough. Measuring blood glucose is still a reactive process, rather than a proactive one.

What's better than monitoring your blood glucose dozens of times per day?

Monitoring your blood glucose hundreds of times per day.

Continuous Monitoring

The entire purpose of Continuous Glucose Monitoring (CGM) is to move from a reactive to a proactive way of monitoring. As you can guess from the name, CGM is the process of constantly monitoring and gauging the levels of blood glucose. In the same way that moving from manually checking BG levels to checking with the Libre gave us BG direction, moving from the Libre to continuous blood glucose monitoring gives us BG insight.

There are many common CGM systems out there —

Dexcom G6 (~£1900 per year) Dexcom is the go-to name in CGM, and has been available in some form for over two decades. The latest version — the G6 — takes the form of a sensor, inserted under the skin, and a transmitter adhered above the skin. Each sensor/transmitter pair lasts for 10 days.

GlucoMen Day (~£1900 per year) Similar to the Dexcom but with a stranger name, the GlucoMen Day sensors last for 14 days and come as a single needle-free sensor application.

FreeStyle Libre 3 (~£1560 per year, once available) The latest version of the Libre actually now includes CGM functionality, with the NFC arm sensor also including Bluetooth Low Energy functionality allowing it to communicate directly with a smartphone. It's only just being approved by regulators and is currently unavailable in the UK (privately or publicly via the NHS).

All of these systems are great, but expensive and proprietary. The companies responsible for them are limited by regulators as to what they can do, and technological progress is slow — the apps can be buggy, the visualizations are not ideal, and they build for the most common use cases.

What we'll be doing today is taking our inexpensive Libre NFC flash glucose monitor (which is available to all UK-based type-one diabetics for free via the NHS) and sticking a Bluetooth LE transmitter on top of it, turning it into a customizable and open continuous glucose monitor. With this, we have inexpensive per-minute glucose readings going to any device of our choosing over Bluetooth LE.

Using the Libre as a CGM

To start with, we'll need a device to convert our Libre from a flash glucose monitor to a continuous glucose monitor. Luckily, there are a few to choose from, and we'll be going with the one with the best name — the MiaoMiao. It's a small Bluetooth LE / NFC device that performs a simple task — every five minutes, it does an NFC scan on the Libre, and forwards the sensor data over Bluetooth LE to a device. Due to the simple nature and lack of processing, it’s small, lightweight, waterproof, sits atop the Libre, and the charge lasts longer than a Libre does (~14 days).

Due to the way that the Libre measures blood glucose levels (through a subcutaneous filament measuring second-order levels of glucose in the fat layer, not the blood itself), it's not a perfect CGM — there’s still a slight lag of up to 10 minutes between measured and actual blood glucose readings. But once you start getting continuous high resolution data, it’s more about the slope of the curve, rather than the intercept at any given time. If you can see the direction that your glucose is headed in, you can start to adjust.

The great thing about this setup with the Libre and MiaoMiao is that it's now just your glucose data, flowing over Bluetooth LE, free of any proprietary app or API. We can do whatever we want with this data, including building apps, creating novel visualizations, and sending it to family members.

For example, here's a quick web-based visualization I made, showing my blood glucose levels for twenty-one days, rendered as a series of stacked violin plots using the visx library —

You can do what you like with this high-resolution data, and I've barely scratched the surface of what's possible. Imagine taking this dataset, pairing it with timestamps and values of insulin-on-board, and feeding it into a machine-learning model to reduce the dimensionality of those 42 factors that affect blood glucose levels.

We now have an NFC chip in our arm that can read blood glucose levels, we have a Bluetooth chip stuck to the top of it, performing continuous readings and sending them to a smartphone, and we have a smartphone that can plot our readings and use notifications to alert us on critical abnormalities.

Is this enough? Let me check my wrist.

Speaking watchOS

If there’s one device that’s stuck to your body more than a phone, it’s a watch.

Currently, most of the CGM apps from the available providers use the Apple Watch as a notification device for of their main app — somewhere to send alarms and notifications rather than somewhere to proactively check glucose levels. This is odd, as WatchOS has contained all the necessary functionality required to communicate with Bluetooth devices directly since watchOS 4 in 2017. With watchOS 8, we now even have the ability to do these things in the background.

Adding all of the pieces together, this means we can now build a fully-independent Apple Watch app to continuously read blood glucose without the need for any other device. Be it when swimming, out in the ocean, going for a run, headed out to the shops, or any other time you might be without a phone nearby, we’re now able to shrink our digital pancreas down even further — to the size of a watch on our wrist and a coin on our arm.

Our watchOS app will work by finding the nearest MiaoMiao transmitter via Bluetooth, setting up a regular background request (using scheduleBackgroundRefresh), and using this background request to connect to the found transmitter and reading all values. Once we have these values, we can store them locally on the watch and update any complications, along with firing notifications for rapid glucose changes.


As the primary use of this WatchKit app is glanceable data (the ability to determine the current blood glucose level and where it's headed), complications will make up the primary interface for our app.

To get current blood glucose readings showing up on an Apple Watch face, most apps today make use of the calendar, placing blood glucose readings as calendar events and then encouraging the use of one of the calendar complications to provide glanceable data. Obviously this is not ideal, as we’re limited to complications designed for calendar events, and the syncing mechanisms are unreliable.

For our complications, let's start with a couple of example complications for showing the current blood glucose level —

• A "circular open gauge text" complication for the Modular watch face, showing a circular gauge with a dot indicating the current blood glucose level, some text showing the reading in mmol/L, and a small arrow indicating if blood glucose is trending up, down, or sideways.

• A "graphic corner gauge text" complication for the Chronograph watch face, showing similar data, but also some text indicating when the reading took place.

Apple Watch supports a growing number of complications; you can find the full list in the Complications section of the Human Interface Guidelines. This article by Warren Burton has a great overview about creating regular and custom complication.

Setting up a complication on an Apple Watch app is a fairly simple process, requiring a couple of function calls and some configuration. It can all take place within a subclass of CLKComplicationDataSource.

We start by describing the complications that our app supports using CLKComplicationDescriptor and the getComplicationDescriptors handler —

class ComplicationController: NSObject, CLKComplicationDataSource {
func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
let descriptors = [
CLKComplicationDescriptor(identifier: "complication", displayName: "Glucose", supportedFamilies: [CLKComplicationFamily.graphicCircular])
// ...additional complications

Once we've registered our graphicCircular complication support, we can then create the complications themselves within getCurrentTimelineEntry / getTimelineEntries. As we're just showing a latest value for our complications, we don't have to worry too much about timelines, and can just provide the current date for the latest entry —

func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
let complicationTemplate = createGraphicCircleTemplate(forDate: Date())
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: complicationTemplate)
private func createGraphicCircleTemplate(forDate date: Date) -> CLKComplicationTemplate {
// Fetch the reading for the given date
let latestReading = GlucoseDataStore.shared.glucoseDataForDate(date)
// Convert our reading from mg/dL to mmol/L by diving by 18
var value = 0.0
if let latestReading = latestReading {
value = latestReading.value / 18.0
// Calculate how full our guage complication should be.
// We'll set minimum to 2.2 mmol/L and maximum to 12.0 mmol/L
let min = 2.2;
let max = 12.0;
var fraction = ((value - min) / (max - min))
// Clamp the value between 0.0 and 1.0
if (fraction > 1.0) {
fraction = 1.0
} else if (fraction < 0.0) {
fraction = 0.0
// Create and return our guage and set fill color based on value
let guage = CLKSimpleGaugeProvider(style: .ring, gaugeColor: GlucoseDataStore.shared.colorForValue(value), fillFraction: Float(fraction))
return CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText(gaugeProvider: guage, bottomTextProvider: CLKSimpleTextProvider(text: GlucoseDataStore.shared.getLatestSlope()), centerTextProvider: CLKSimpleTextProvider(text: String(format: "%.1f", value)))

Here we create a CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText (phew!) with the gauge value based on the current glucose value within a configurable maximum / minimum range.

Our Circular Open Gauge complication provides the current blood glucose reading and trend (as of +/- 15 mins, depending on when the complication is refreshed), but it doesn't contain other useful information, such as when the reading occurred, and what our previous values were. To display this information, we're going to need more room.

A CLKComplicationTemplateGraphicCornerGaugeText would allow us to see the current glucose reading, the trend, and some further information, such as when the reading occurred.

// Create our corner gauge
let guage = CLKSimpleGaugeProvider(style: .ring, gaugeColor: GlucoseDataStore.shared.colorForValue(value), fillFraction: Float(fraction))
// Show the time since our latest reading next to the gauge
let timeFormatter = RelativeDateTimeFormatter()
let formattedDate = timeFormatter.localizedString(for: latestReading!.timeStamp, relativeTo: Date())
let leadingText = CLKSimpleTextProvider(text: formattedDate)
// Show our latest glucose reading below the gauge
let valueText = CLKSimpleTextProvider(text: String(format: "%@ %@", GlucoseDataStore.shared.getLatestSlope(), valueString))
return CLKComplicationTemplateGraphicCornerGaugeText(gaugeProvider: guage, leadingTextProvider: leadingText, trailingTextProvider: nil, outerTextProvider: valueText)

With some further exploration and implementation we can build a full blood glucose watch face, featuring additional complications for our Bluetooth transmitter's battery, along with the number of days left before our Libre sensor needs replacing. Alongside this, we can build full watchOS apps too!

I haven't had time to venture too far down this road, but here's a quick example showing a list of the latest readings retrieved from the transmitter, along with the two complications we just made —

Future →

Believe it or not, in this post we've actually just built the wildest sci-fi dreams of type 1 diabetics from a decade ago —

Go us! And go the amazing scientists at Abott and beyond who have helped us reach this point. I can now check my wrist before bed, and have confidence that I’ll still be here in the morning.

What we've built here is a tighter safety net. When we talk about diabetes as a tightrope, it's important to remember that every trapeze artist has fallen. Having technology that catches us when we fall is vital.

All this begs the question — where will we be in ten years' time?

Lila Moss at the 2022 Met Gala — The first person to walk the red carpet at the Met Gala with a bionic pancreas. Dressed by Riccardo Tisci for Burberry, makeup by Charlotte Tilbury, accessorized by Abbott and Omnipod.

We haven't talked about it much today, but insulin pumps are the other side of the monitoring story. The pancreas not only monitors blood glucose, but provides insulin and glucagon to even out glucose levels in the body. Devices like the Omnipod are filled with insulin and are attached to the body with a cannula to provide a steady stream of insulin, and when paired with a CGM can provide an entire digital pancreas. When CGMs can detect raised glucose levels and automatically tell an insulin pump to provide insulin, we call this a closed-loop system.

With this, we now have the technology to build a computer-controlled pancreas and stick it to our bodies. We have the ability to continuously measure the body's blood glucose levels, calculate the slope and rate of change, and automatically inject the correct dosage of fast-acting insulin to offset any variations.

The next logical step will be to take this technology and productize it. Miniaturize it, and make it available and affordable for all. That's what Beta Bionics, amongst others, are focusing on. Their iLet® system literally bills itself as "a fully automated bionic pancreas".

Other companies, such as Senseonics have an implantable CGM, which contains a fluorescent chemical that lights up when exposed to glucose which is then read by a sensor mounted on the arm. It requires surgical removal every three months, with an estimated annual cost (including surgery) of over $3,000. Google was working on (and then cancelled) a contact lens that measured glucose levels in the tears and then communicated those levels with a small LED in the lens itself.

Rumors have persisted for years about a blood glucose sensor built-in to the Apple Watch itself, too. It's an incredibly complex feat to have non-invasive blood glucose monitoring that is accurate enough to trust with your life. This has never been done before, but with 1.6 million US citizens alone suffering from T1D, Apple has the desire and capability to be the first to market with a solution. A $400 watch with these capabilities will be a literal life-saver.

Approaching from the other end of the "how to fix a pancreas" spectrum, we have CRISPR, stem cell research, and islet transplants. Go read ‌Targeting the cytoskeleton to direct pancreatic differentiation of human pluripotent stem cells for your daily dose of near future scientific wonderment.

So the future is bright! Be it in biological or technological advancement, it's foreseeable (even likely) that within the decade I'll be cycling around with a single device — a digital pancreas — strapped to my waist, monitoring my glucose levels and injecting my bloodstream with insulin and glucagon without a care in the world.

We often think of a cure for a disease being a complete reversal of the effects that disease has on us — transplanting cells or organs, performing surgery, taking medication to reverse the effects. In this case, there's another cure — using technology as a means to forget our body's failings.

If I can live a day of my life and not think about diabetes, then I'm cured.

So let's build.


The Unreasonable Math of Type 1 Diabetes by Graham Jenson

This piece by Graham is truly wonderful, and a big inspiration for writing about my experience living with T1D. I can't recommend it highly enough. If you read one other piece regarding T1D, read this, from the viewpoint of a father of an 18-month-old diabetic son.


An incredible library containing Swift code and algorithms for closed-loop systems. See these algorithms for insulin slope predictions.


Fantastic port of xDrip to Swift, including algorithms for communicating with the MiaoMiao via CoreBluetooth and decoding Libre data, along with calibrating sensor data over time.

My work here builds on many open-source projects, to which I owe a huge debt of gratitude. I'll be polishing up libraries for visualizing blood glucose levels on the web and iOS in the near future, and will publish them as open-source. Follow me on Twitter here for future updates!