Wednesday, January 13, 2016

New year, new device

Finally got most of the kinks worked out of the Pebble as CGMS project.  Above is the device with it's charging stand.  Completely removed the phone component.  Added all the calibration functionality to my pebble.  Some screen shots from the emulator:

For calibration values, you can choose 80-190 in 10 mg/dl steps.  I also added a 15 minute snooze for alarms.  Entering anything is a two step process to avoid issues with accidentally pushing the buttons.  This will probably see more work, but for now, you click an action then scroll back to the top and choose Enter.  Finally broke my watch code up into libraries, much happier with it now, and it's easier to maintain.  Maybe I'll let my iOS developer license lapse now.  I really dislike xCode, I spend more time proving to it that I'm an authorized developer, than I do coding.

For the circuit, I realized I was better off with the Wixel, since it handles running it's radio and a 115k Serial connection.  Almost no room for a program on the Wixel, but I only had to cram in a function to blast out 2 packets to the pebble every 5 minutes.

A picture of the packed circuit board:

I'm very happy with this.  I no longer have to keep track of the phone.  Also both the boards I'm using are pretty awesome at their jobs.  The Bluetooth board easily covers the house, and pairing is automatic, handled by firmware.  No more disconnects from blocking the device.  The Wixel is also much better at pulling in signals than my CC2500 devices.

I did the PCB on a CNC router this time.  Just barely worked, luckily this is a simple circuit.  I should be able to do better on the next PCB I route.

One downside for now, is I can only get the Classic Pebble and Pebble Steel to pair.  There is something different with the Pebble Time and what it expects for Pairing.  There are quite a few parameters for the RN41 so I have a few other options to explore.  On the upside, while the Classic is fairly ugly, it has nearly a 5 day battery life.

Saturday, December 19, 2015

Pebble Battles

I was hoping to get allot of programming done on my Pebble yesterday.  Not so.

I left off Thursday with a working app, started up Friday morning to this.  It's telling me that pebble.h doesn't exist.  Sort of a fundamental problem.  So I scour the internets to see what's going on, nothing.  Send an email to support, then consider my options.

The last time CouldPebble was down I developed on my Mac, so back to that.  Fumble around for a while, it's been almost a year.  Load app on my watch, mistakenly putting it on the one I'm wearing, and not the development model...  App doesn't work.  Try to load onto my original pebble, just get this message "Couldn't install app".  Dead.  Nothing.  Try app in emulator, works fine.

After an hour or two of this, I notice that pebble is on a new SDK release.  Start fiddling around with the command line:
->pebble sdk list

Tells me I'm on 3.8.1.   Hmm, lets try 3.7.
->pebble sdk install 3.7
->pebble activate 3.7

I like the way you can easily switch and install SDK's, beats the hell out of Java and hunting around for the correct version.
Then build, install and success!  Most of my day is gone, but the watches are back to working.
As of today, CloudPebble is still wasted.  I really liked this tool, and the mbed site as well, good for casual use I suppose.  Looks like I'm officially done with CloudPebble for development.

Thursday, December 17, 2015

Working Prototype

Bread boarded and working.
Now to get this on a PCB, and figure out what kind of battery I'm going to need.

Final build:
- BLE Nano
- Sparkfun Bluetooth Mate Gold
- Teensy 3.1
- A couple of discrete components so I can control the Bluetooth Mate

The Nano, like the RFDuino, can't run at 115k with the radio on, so I have to have the Teensy around to coordinate everything.
Cool thing with the nano, is I have it in Central Mode.  My CGMS devices pair directly with this if the phone isn't available.

So it's:
Sensor->CGMS->iPhone-> Watch


Sensor->CGMS->"The new device"->Watch

Also this device will pair and/or wait to pair for as long as it has power.  No issues with something shutting down the "process" like the iPhone does if the BLE connection has been idle for more than a few minutes.

Thursday, December 10, 2015

More on Pebble

Connecting an Arduino to a Pebble.

I'm using a sparkfun, bluetooth mate, GOLD.  I don't believe the Silver will work.  A big issue with this process is what type of bluetooth dongle you have, I'm sure they all work differently.

The guy here:, has some basic working(for him) code.  What's left out, is the initial pairing.  With the Mate, you are better off not trying to control it programatically.  After many hours, it just doesn't seem consistent and tends to be unresponsive.  It is meant to be configured over serial from a lengthy command set.  Most of the settings don't appear to "take" until you reboot the device, and just power cycling may blow them away.  Also, some important settings don't persist.  The big one that comes to mind is baudrate, so assume you are going to be at 115200.

Before you do anything with the arduino, configure the Mate, you aren't done until the Mate stops flashing red and the green light stays on, indicating you are paired.  From that point forward, the mate should automatically pair with the pebble until the end of time (although it may take as long as a minute, or never)...

The commands you should send to the Mate:
SF,1         //factory reset
SP,9999   //takes care of the pairing code
SM,6        //pairing
SY,0000   //power
SW,0640  //sniff mode
R,1            //reset so settings are saved/active and pebble should ask to connect

Once the light hits green, pairing with the watch will take place, the first time the watch will ask, any time after that it will be silent.  The watch will send you a version request.  You need to send two packets in reply, screw this up and the watch will just ignore you.

I send:
//          //phone version
{0x00, 0x02, 0x00, 0x30, 0xff, 0x08};

Followed 100ms later with:
//                                  0x11 = 17 = Phone Version endpoint
//                                             phone version
//                                                        remote capabilities  Telephony.SMS.Android
//                                                                                              //session capabilities............
{0x00, 0x0d, 0x00, 0x11, 0x02, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32};

You shouldn't send the above again, unless you "forget" the bluetooth device from your watch.

Once that's complete you can ping the watch:
//                    endpoint
//                    2001=ping
{0x00, 0x05, 0x07, 0xd1, 0x00, 0xde, 0xad, 0xbe, 0xef};

Send a notification:
//this says BG 115  
//                                                                       B      G                   1        1         5
 {0x00, 0x1A, 0x0B, 0xB8 , 0x01 , 0x02, 0x42, 0x47, 0x03 , 0x31 , 0x31 , 0x35, 0x11, 0xFF, 0xFF , 0xFF , 0xFF , 0xFF, 0xFF, 0xFF, 0xFF , 0xFF , 0xFF, 0xFF, 0xFF , 0xFF, 0xFF , 0xFF , 0xFF, 0xFF};

Note: the above packet has a header and body.  The header is 2 bytes and says "BG".  The body is 3 bytes and says "115".  The 0x11, signifies 17 bytes until the end of the message.

Or, and this is the big one, send an application message.
For this one you need the UUID of the app, which you can see in Cloud Pebble.

With that, I can send an integer value of 120 to the first element(tuple?) in my applications dictionary.
//app messages to uuid, glucoseKey
//001b 0030 0100 7f7a38901a1c43a3adf121449e4f352d 040100 0000 03:01:00:78
//msg  app    push UUID................................................... key                     len      120
//         msg                                                                                                int (0x03)
//                                                                                               dict element (0x01)

I may have to update this one.

Can't use the RFDuino.  Number of serial ports is one issue, the bigger one though is you can't run the Radio and Serial at 115200, 9600 works, but 115200 will cause the app to hang.

Turning one off and the other on, also doesn't work, doing a Serial.end / Serial.begin appears to glitch the serial line to the mate and causes it to disconnect.

It looks like this project will be continuing with a Teensy.  One serial for debug, the second for the Mate, SPI for the CC2500, maybe a third serial to run an RFDuino if I want BLE.

See github ( for a working sample.

Friday, December 4, 2015

Direct control of Pebble with Arduino

Slow week, and I was cleaning up the bench.  Stumbled on one of my Sparkfun Bluetooth Mates.
I used these with the metawatch a few years ago.  I was never able to work out the pairing to get these to connect to the Pebble.  Well, I know a bit more, and I'm probably even more persistent these days...

I need to work out how to send an application message, then I can go phoneless.  I might have to use the Wixel again, could keep my parts count down.  This will net me a larger carry, but no phone requirement for extended periods.  Still need to get calibrations in somewhere, though.

This guy (here) was close.  But he's leaving out the initial pairing step.  The packets have changed since this was published also.  Allot of strange details, probably bluetooth device dependent.  I'll post more when I can sort through all the details, but I can reliably pair with the watch and send a notification to it.

Monday, October 5, 2015

The final CC2500 Device

All this work on watches, and discussions about how small this device could be, got me motivated this weekend to make another (last) device.  This took the whole weekend.  Fiddling with eagle, realized I could do it without jumpers, and I left out the serial interface for programming.  Leaving out those traces makes a huge difference, no issues with trying to sneak by the CC2500 antenna.  Program the chip before installing...

Screenshot from eagle:

From the left:  Rfduino, CC2500, and a Polulu 5v to 3.3v converter.  Used a 40 maH lipo which fits on the top right.  I realized after the fact that I could make life easier on myself, and have dedicated pads for the lipo, that aren't so close too each other.  As it is, the lipo is directly soldered to the pin-header socket.

Completed device, in 3d printed ABS case.

It's almost bic lighter size.

A shot of the board, Dexcom for scale :)

And in it's charger base.

Saturday, September 19, 2015

Time for Pebble Time and Smart Straps

More goes on in the comments around here than the blog itself.  I've been thinking about smart straps for a while, but it was a question from someone that really got me going.  I've been hung up on the current limitation, but then I realized I can do this with just the RFDuino.  I still use the device I carry in my pocket, I only have to reflash it for "Gazelle" which allows RFDuino to RFDuino communication.  The watch now becomes the master device.  I'll still need an iPhone app, that will handle calibration, and push the Slope and Intercept values to the watch.  The phone will still receive glucose, but it will retrieve those values from the watch.

But, once I'm happy with the calibration, I won't need to have the phone around.  I like that.

And another idea, only a theory at this point, in the future I could use the Redbear BLE Nano, in central mode paired with the G5 transmitter (not sure I want this until I have to take it though).  This would make the bitter pill of living without Raw data, and forced calibrations, and 2 hour warm-ups easier to swallow.

Continuing on the BLE Nano topic, this device will imitate a BLE Smart Heart Rate Chest Strap.  Which means, if anyone has a decent looking wearable that has bluetooth smart HRM funcionality, you can make it a "CGMS".  Not allot out there, I was hoping the VivoSmart would do that, but it uses Ant+.  Amazing, that small wearable has both Ant+ and BLE in it.

Still trying to get Central mode communication working with the Vivo or the Pebble.  I can do it between the Nano and an RFDuino, which means Gap/Gatt is working.  Or at least that I know how to code it.  Using Mbed on the Nano, not Arduino.  The web based environment isn't half bad...  Need a way to automate the Hex file upload and the serial monitor.  I like the way it centralizes things, Pebbles development website does a great job at all of this.

Interesting thing with the pebble, it appears to use both Bluetooth and BLE.  When un-paired, it doesn't advertise, like a BLE device should.  I can't get a handle on it with a sniffer.  Kind of a show stopper, hence the new hardware approach.  I welcome comments if anyone knows how Pebble does it's BLE.

Still trying to sniff traffic between the Vivo and the iPhone.  More on that I'm sure.  The goal of today's blog is to make the Phone optional, ie. only for calibration.  I want to communicate with a wearable directly, like I used to with the MetaWatch (moment of silence).

Scheming about making a wearable, maybe carving up the Fuel and using the good parts.  Spending an inordinate amount of time with the 3D printer making it work with Ninja Flex.  Printing Octopi, obligatory photo: