Sunday, November 15, 2015

The Software Side of the House

With the hardware pinned down it was time to figure out what I was going to do with this thing. The example code for the GPS logger shield get me 90% of the way there. I just decided what GPS NMEA data I wanted to log and how often and sent it to the SD card. You can check out the code at my GitHub repo.

My plan was to log my location every 5 seconds and then post process to figure out all the stats I cared about for my jog. I wanted to know the stats about my pace: average minutes/mile, 1/4 mile split rates. This is incentive for me to jog and try to improve on my time. Maybe a little weird but it works for me.

I looked around to see if anyone had already done anything like this before. As usual I found a lot of things kinda like what I was looking for but no exact matches. So I started with some code written for a Sparkfun tutorial. It had a similar spirit of what I wanted to do - overlay GPS data on a map but not worry about being online. It used a module to parse the GPS NMEA sentences that I logged to the SD card. Thanks to Becky Lewis in the UK for putting together the NMEA parser that was closest to what I wanted. The code I made for myself (before I thought about showing my dirty laundry to the world) iterated until I hand selected the starting point and then the end point of the jog. With the start and end point known, then it calculates my beloved stats. Currently, it has a clunky if a jog else a commute logic section to figure out what kind of GPS track I'm trying to make sense of. I'm thinking of a slicker way to read in bounding box metrics and what map to use with that bounding box. But rather than go down that somewhat clunky sounding road, I might consider using a different module and maybe a web resource to dynamically load map data on a web page?

Going back to the original Sparkfun tutorial post. I see some suggestions in the comment section to try geopy or pymaps. I'll have to go back and check those out.

The Sparkfun tutorial uses matplotlib to plot the GPS data ovelayed on a map that you know the Top Right and Bottom Left Lat/Long. This works well enough but it is not the prettiest of outputs.


For my next rev I would really like to figure out how to plot my progress in a similar way to how Nike+ does it using a heat map style line plot - faster is green slower is red.
All for now. Until the next time ...

DIY Fitness Tracker

So after I laid my dearly departed Fitbit to rest, I thought about what I was going to do to replace it. I managed to quell the knee jerk reaction to run out and buy a new one. I was sorely tempted. But in the end I decided I would try to make my own fitness tracking something. At first I thought I would make a one for one replacement. Something that would track steps taken. But then I started to look into what was available.

If you are into hardware hacks and you don't live in a cave you know about Arduino's - small little micro controllers that can run code and interact with hardware. I had already been playing with Arduino's. I got my feet wet with a temperature sensor and a set of 8 segment displays for a readout. Anyway, I digress. So I figured whatever I ended up making, an Arduino would be the micro. Since I didn't really have a finished end product in mind I thought the shield route would be the most flexible on my route to a working prototype. Shields are collections of prefabbed electronics ready to dropped on top of an Arduino board. They make battery shields, GPS shields, Wifi shields, Bluetooth shields. You get the idea.

My two main supply sources for hardware hacks are Sparkfun and Adafruit. Sparkfun has some interesting stuff but I get a rougher around the edges vibe from them. Adafruit is very polished. Also they have excellent supporting documentation for their products - clear manuals and lots of good example code. For my first cut at a fitness tracker I decided to go with a GPS logger. One of my main forms of exercising is jogging so this seemed like a logical fit for me. I went with the following parts list:
Again I went for the shield style for easy plug and playishness. I only had to solder the headers on and I was good to go. The battery (a 2000mAh) is way overkill. But I didn't have a good feel for what kind of load all the hardware was going to draw. Full disclosure, I'm a mechanical engineer by training (although I do mostly software work now, weird huh?!?). So my EE skills are a little seat of the pants. Anecdotally, my tracker can run many hours without needing a charge. I've not run out of juice yet and I've started taking this thing with me everywhere I drive. More on that later. I typically charge it once a week.

Another hardware decision note: the built in ceramic antenna on the GPS logger shield works great on its own especially if it is pointing up. Since I was a little uncertain how I was going to mount this thing on me when I went jogging, I thought the most reliable thing to do would be to just go ahead and buy the add on Antenna. The cable is quite long but I just shove the whole thing in a fanny pack and sling it over my shoulder bandolier style.
 I threaded the antenna head in the packs strap then used an asparagus elastic (those things come in very handy) to keep it in place. Note the second elastic that holds the battery on the battery shield. I also put a twist tie around the strap to keep the antenna wire neat and tidy.
As it turns out the Arduino fits quite nicely in a standard 1 gang electrical box. I saw mention of this in an Instructable (very neat site if you haven't checked it out. Although their incessant registration requests are super annoying). 

The shield version is much bigger then it needs to be. I was just looking at a new Adafruit product, the feather. It could make the whole thing not much bigger than a pack of gum. Something to consider for Version 2.0.

Next time I will talk software!

Death of a FitBit

I went on a trip. I usually had the Fitbit clipped on my pant waste band. I must have inadvertently popped it off and it landed on the ground. I didn't notice till much later. When I returned home I found poor mister FitBit lying in the gutter.
I'm not sure if someone ran over it or upon seeing one in a fit of rage they stomped it to death. I can imaging a disgruntled low voluntary running behavior gene guy letting the unfairness of it all out on my poor piece of tech. Well so as they say when a door is slammed shut somewhere, a window to buy more tech opens!

Thursday, November 12, 2015

Director's Cut

This is basically the long form of the 5 minute squirt I plan to give at the next DC Hack & Tell. The premise of my core dump is that getting enough motivation to exercise is easy for some people (because they are genetic freaks, no I'm not bitter) and harder for other people. I fall in the harder catagory.

Unfortunately, I'm not making this up. For the more medically inclined take a look at this article from the the Journal of Physiology "Nucleus accumbens neuronal maturation differences in young rats bred for low versus high voluntary running behavior". If you would like it translated in to normal human check out the the New York Times Blog version. My take in a nut shell is that for the genetic freaks they get a nice fat dopamine squirt when they exercise so they have a built in reward system and they get the added bonus of improved physical health.

So what are the recipients of the "low voluntary running behavior" gene to do? Hack your brain! Trick your brain into giving you some dopamine goodies! There are a wealth of articles describing how you might go about doing this. One woman described her restriction that she could only read (one of her passions) while she was on the treadmill. So naturally her routine evolved into linking the act of running on the treadmill with the pleasure of reading: brain fooled! Other suggestions were to listen to your favorite podcasts (I love the Moth!) while you pound the pavement, only watch your favorite Netflix guilty pleasure (The Walking Dead) after you have hit the gym. You get the idea.

For me the answer was data! I'm an engineer. I love crunching numbers. Also the gameification of an activity can lead to the all important dopamine squirt. So to get data out of fitness, I needed a fitness tracker! It sounded perfect. The promise of of an API, metrics, easy web interface. It was a dream come true. OK so it wasn't that great. The API was pretty limited. I could get summary information about every 15 minutes. Really?!? It was pretty good though. I was shocked on those days that I walked to my car, drove to work, sat at my desk all day, and then got home and found out I barely cracked 3000 steps. (The recommended daily step count according to FitBit is 10000). There were many a night that I was pacing back and forth in my bedroom trying to break a threshold for the day. I just want to make it to 7000! (Can you hear the dopamine dripping?)

So things were moving along pretty well. I connected with a cousin and we had a friendly step count competition going on. (I though I was going to murder him when I went to the Big Easy for Christmas and walked everywhere! Turns out he went to Toronto or was it Montreal ?!? and edged me out by ~1000 steps! grrrr!) But then tragedy struck ...

Monday, November 9, 2015

The Hub of Gitness

So I started dropping my python hacks to my first ever GitHub repo! Wo-hoo. OK maybe you aren't as excited as I am. But that's OK. :)

Now I just need to anonomize (apparently that is not a word) things a bit. Not that I think I'm going to get a gps jog stalker after me but for some reason I don't feel like posting the gps track to my front door.


And So It Starts

I'm starting this blog to keep public notes for my various projects that I stumble into from time to time. The impetus for doing so comes from starting to attend the DC Hack & Tell meet ups.

I also have started getting involved with CoderDojo. The local chapter I hang with is CoderDojo NOVA.

I'm sort of in setup mode so this will be short and sweet. I hope to have everything in order for the upcoming Hack & Tell (11/16)! Anyway this is it for the first one.