Sync’ing blood glucose data over Bluetooth to HealthKit

The code for this project is on my GitHub (here).

While newer blood glucose monitors (BGM) have Bluetooth capability (BLE), they are often designed only to sync data to their own clouds. Many applications call for mixing glucose measurements with data like weight, activity, carb consumption from other apps to enable consumers themselves, coaching, or care teams to use the information directly.

This code pulls glucose measurements from a BLE-enabled BGM and stores in:

  • HealthKit. Many apps and EHRs have HealthKit integration and can use HK as a channel to import glucose data.
  • Open format. Developer can integrate into other database systems.
 HealthKit result

The code was developed using a Contour Next One BGM since it was found in a study published by the Diabetes Technology Society to be the most accurate of the set of 18 BGMs tested and one of the few to meet the FDA accuracy standard for glucometers.

The Bluetooth Forum developed a standard “GATT” profile for BGMs. Details can be found here.

Reads from the BGM are performed via its “Record Access Control Point (RACP)” characteristic. The code writes to RACP requesting data from the Bluetooth Glucose Measurement read more

Custom Bluetooth Low Energy board with 2.4GHz antenna hack and Nordic nRF51822…

Custom Bluetooth Low Energy board with 2.4GHz antenna hack and Nordic nRF51822…

I wanted to experiment with Bluetooth Low Energy:

  • Can you hack together in your garage an antenna and RF section that will work at 2.4GHz?
  • If it works, who good/bad will it be?
  • What is hand soldering QFN packages like? Many BLE devices are only available in CSP or QFN48.

If you want to make IoT and Wearable devices that can be controlled from your phone/tablet/whatever, ZigBee is a neat mesh networking technology; but it’s not in any phones. Bluetooth (and more recently) Bluetooth Low Energy is in all of them. It’s easy to write a BLE control app write yourself using the Cocoa frameworks or download one like the excellent LightBlue for iPhone:

Using JTAG and Eclipse on MacOS

Using JTAG and Eclipse on MacOS

Though many eval boards come with an embedded JTAG-USB interface, I still like to use a separate purpose-built JTAG debug box.

If you pick the right one:

  • It can be used with many boards and SoCs. Once set up, one debug toolchain works for many projects.
  • You can use it to debug MCUs on bread-boarded projects. You will need to make a hacked

read more

STM MEMs pressure sensor, gyroscope and accelerometer hook up to ARM MBED

STM MEMs pressure sensor, gyroscope and accelerometer hook up to ARM MBED

I used a header board for an STM MEMS evaluation kit in order to take a look at some common MEMS sensors:

  • LPS301: Pressure and temperature sensor
  • LG3D20: Gyroscope
  • LSM303DLHC: Accelerometer and magnetometer

The header was an STEVAL-MKI124V1 which is designed to work with an STM motherboard evaluation system. I took a shortcut and used it with an ARM MBED board featuring an NXP LPC1768 MBED.

Hook-up using I2C was trivial:

Screen Shot 2014-08-10 at 9.37.23 PM

The schematic for the evaluation board is here:


read more

Simplest Cortex-M bring up. Post#1: a no code approach

Powering up a new board design or even skiing off-piste with an eval board without vendor-suppled code? This post shows a way to look for first signs of life without depending on working debug toolchain or working target software.

I use a Segger JTAG probe that I covered in a previous post.

Some recent eval boards like the one for Nordic Micro’s nRF51822 ship with an on-board USB debug connection that has a USB-JTAG decoder chip on board. This board uses the same Segger driver as their JTAG box embedded in the decoder, so the below approach should also work.

Segger JLINK application driver has a series of useful commands for examining directly addresses in memory:

  • mem          Read memory. Syntax: mem , (hex)
  • mem8        Read 8-bit items. Syntax: mem8 , (hex)
  • mem16      Read 16-bit items. Syntax: mem16 , (hex)
  • mem32      Read 32-bit items. Syntax: mem32 , (hex)

Since many MCUs have a factory-programmed ID register, you can use JTAG to read this value and check for signs of life.

To start with, I target a STM32F100C8. This MCU has a register at 1FFFF7E0 hex containing a 16-bit value with the flash size of the MCU. This is covered in the STM32F100 programming manual on page 668.

Launch the Segger JLinkExe application (I am using Mac OSX version). The terminal welcome screen should look something like the below. I removed my Segger serial number. I use the mem16 command to get the 16bit value starting at 1FFFF7E0 hex:

STM32F100 segger

(My entries in red). Notice how the JTAG box finds the STM device automatically over SWD.

The resulting value 40 hex corresponds to 64 decimal i.e. 64KB flash on-board. So, device and board are alive and breathing.

On the Nordic nRF51822, there is an ID register called CONFIGID at 1000005C hex. Bits 0-15 contain a hardware config code. The decoder ring for the value you get back is buried in Nordic’s white paper “Migrating to the latest nRF51822 chip version nWP-018” which currently is here

Nordic segger

The 4C00 hex code from my device shows I have a QF AB build code B0 version of nRF51822 which corresponds to the QFN packaged 128KB flash variant.

 

 

Using MBED SPI to drive Analog Devices AD9850 frequency synthesizer

Using MBED SPI to drive Analog Devices AD9850 frequency synthesizer

I was looking for a way to test the frequency response of a new oscilloscope.

Analog Devices has a nice IC that can produce a digitally synthesized sine wave of frequency between 0 and about 70 MHz. AD9850 link is here.

The quickest way to throw together a prototype was using an MBED platform. My code is here

What made things even easier was the availability of ready-to-go evaluation boards from China on Ebay for less than $5. This is the one I used.

This design is limited to about 40MHz if you want a clean signal without aliasing.

Frequency and phase are set by a 40-bit command that has:

  • 32-bit frequency setting
  • 5-bit phase setting
  • 1-bit power up/down
  • 2-bits factory debug access

MBED_SPI packet

Output frequency is given by: fOUT = (frq × CLKIN)/(2^32)

where frq is the 32-bit frequency and CLKIN is the frequency of the on-board crystal (125MHz in this case) So, for example 0x147AE148 is 10MHz.

Frequency resolution has a step size of 29KHz with the 125MHz clock.

You can also change phase in increments of 180°, 90°, 45°, 22.5°, 11.25° or any combination thereof using read more