Saturday, December 13, 2014

Arduino RGB strip

Knight Rider ...

keep track of misc arduino snippets here.

Get yourself some RGB LED light strip like this one.
These are WS2812B type of chip are in a 5050 package including controller to control every single "pixel" i.e. the RGB LED on the strip and set each color individually.

I always wanted one of those :)
Shipping was from Hong-Kong to Germany a pretty reasonable amount of time (less then three weeks).

So what to do? you start with some examples you'll find on the web.
Good starting point is this page. As this page explains there's basically two major arduino libs for controlling this kind of strip the Neopixel one from Adafruit and FastLed.

From there I took another example code found here:

This gives you some "knight rider" effect.

I broaden the moving lights a bit and added some code to control the speed via a simple poti.

#include "FastLED.h"
//#include <OneSheeld.h>

// How many leds are in the strip?
#define NUM_LEDS 60
// Data pin that led data will be written out over
#define DATA_PIN 6
// This is an array of leds.  One item for each led in your strip.

const int poti = A1;
const int button8 = 8;

// This function sets up the ledsand tells the controller about them
void setup() {

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);


int duration;
void loop() {
  int potiVal = analogRead(poti);
  float voltage = potiVal * (20.0 / 1023.0);
  int duration = (int)voltage;

  byte hue = 8; // some red

  larsonScanner(NUM_LEDS, hue, 255, duration);


void larsonScanner(byte ledcount, byte hue, byte sat, byte duration) {
  static unsigned long previousMillis = millis();
  static int i; // Schrittzaehler
  static int led = 0;
  static boolean reverse = false;
  byte dim;

  if(i > 8) {
    i = 0;

    if (reverse) led--;
    else led++;

    // Anfang erreicht
    if (led < 0) {
      led = 0;
      reverse =! reverse;

    // Ende erreicht
    if (led >= ledcount) {
      led = ledcount-1;
      reverse =! reverse;

  if (millis()-previousMillis > duration) {
    previousMillis = millis();
    memset(leds, 0, ledcount*3); // LED Array zuruecksetzen
    dim = i*4;

    // Aktuelle Led-4
    if (led-5>=0 && !reverse) {
      leds[led-5] = CHSV(hue, sat, 32-dim); // FadeDown
    else if (led-5>=0 && reverse) {
      leds[led-5] = CHSV(hue, sat, dim); // FadeUp

    // Aktuelle Led-3
    if (led-4>=0 && !reverse) {
      leds[led-4] = CHSV(hue, sat, 64-dim); // FadeDown
    else if (led-4>=0 && reverse) {
      leds[led-4] = CHSV(hue, sat, 32+dim); // FadeUp

    // Aktuelle Led-2
    if (led-3>=0 && !reverse) {
      leds[led-3] = CHSV(hue, sat, 128-dim); // FadeDown
    else if (led-3>=0 && reverse) {
      leds[led-3] = CHSV(hue, sat, 64+dim); // FadeUp

    // Aktuelle Led-1
    if (led-2>=0 && !reverse) {
      leds[led-2] = CHSV(hue, sat, 255-dim); // FadeDown
    else if (led-2>=0 && reverse) {
      leds[led-2] = CHSV(hue, sat, 127+dim); // FadeUp

    // Aktuelle Led
    leds[led-1] = CHSV(hue, sat, 255);
    leds[led] = CHSV(hue, sat, 255);
    leds[led+1] = CHSV(hue, sat, 255);

    // Aktuelle Led+1
    if (led+2<ledcount && !reverse) {
      leds[led+2] = CHSV(hue, sat, 127+dim); // FadeUp
    else if (led+2<ledcount && reverse) {
      leds[led+2] = CHSV(hue, sat, 255-dim); // FadeDown

    // Aktuelle Led+2
    if (led+3<ledcount && !reverse) {
      leds[led+3] = CHSV(hue, sat, 64+dim); // FadeUp
    else if (led+3<ledcount && reverse) {
      leds[led+3] = CHSV(hue, sat, 128-dim); // FadeDown

    // Aktuelle Led+3
    if (led+4<ledcount && !reverse) {
      leds[led+4] = CHSV(hue, sat, 32+dim); // FadeUp
    else if (led+4<ledcount && reverse) {
      leds[led+4] = CHSV(hue, sat, 64-dim); // FadeDown

    // Aktuelle Led+4
    if (led+5<ledcount && !reverse) {
      leds[led+5] = CHSV(hue, sat, dim); // FadeUp
    else if (led+5<ledcount && reverse) {
      leds[led+5] = CHSV(hue, sat, 32-dim); // FadeDown


The potentiometer is connected to analog 1 and the digital in of the light strip in dio6.

Sunday, November 30, 2014

strava node.js api

How to get shoe mileage on the command line

make sure you have node.js and node package manager (npm) installed.
$ sudo apt-get install node.js npm

then follow this quickstart instructions  from here:

get strava developer api access from here
access your application info and settings here:
the api doc is at:

now you should be able to run the example program from the quickstart guide.

you directory structure should look something like this:

user@host:~/Programming/node.js/strava$ tree -L 2
├── data
│   └── strava_config
├── node_modules
│   └── strava-v3
└── shoes.js

3 directories, 2 files

now edit the shoes.js file and put in this code:
user@host:~/Programming/node.js/strava$ cat shoes.js 

var strava = require('strava-v3');

strava.athlete.get({},function(err,payload) {
    if(!err) {          
for (var i=0; i<; i++) {
   console.log([i].name + " - " +[i].distance/1000 + " km");

    else {

if you run it you should get a listing of your active shoes from strava together with the mileage (here in km)

$ node shoes.js 
Salomon Fellraiser - 481.693 km
Inov-8 Roclite 315 - 383.47 km
Brooks T6 Racer - 401.136 km
Inov-8 Trailroc 255 - 656.62 km
Saucony Fastwitch 5 ( blue ) - 463.049 km
Barefoot (No Shoes) - 5.219 km
Aldi "barfuss" ?? blau - 136.115 km
Saucony Peregrine 3.0 - 479.282 km
Hoka One One Mafata 2 - 1119.308 km
New Balance Minimum Trail 00 - 403.544 km
Inov-8 Trailrc 245 - 338.791 km
Vibram FF EL-X - 46.919 km

that's it for now.

Monday, May 27, 2013

Garmin Fenix

... oops I did it again

Right, after my 910XT misadventure I finally decided to give the fenix a try. There's a lot of information about the watch already out there in form of reviews and the Garmin forum so I'm not sure if I can come up with an awful lot of new information here.
So I just post a few things as I get going with the fenix.

The first thing I did was to update to the latest watch and gps chipset firmware. After that I discovered that the watch still has a very bad bug that reminds my about the 910xt course navigation issue. While in navigation mode the track redraw did not work! What a bummer!
The suggestion is, in the Setup->Track Menu, to write tracks only as FIT. This make sense as this is a binary format and file size is much smaller than gpx. However I still consider this as a serious bug for this type of watch (remember the old Forerunner 305 is better here than the fenix and any eTrex or alike is better as well).

But worse than that was the fact I used it for an 85k ultra-trail with track navigation enabled and just about a few minutes into the race the watch hang up completely :(

How nice's that? So I try fiddling with the watch but could not even manage to turn off/on again. After a while I noticed some reset screen, pressing a few buttons showed the "locating satellites" screen. I didn't touch the watch for the next two hours or so but there were no satellites found.

I then managed to reset (power/light button >30sec) turn the watch off and on then do another reset from the setup menu and after that satellites were found even while moving along within 1 or 2 minutes. After that I was able to track another 10 hours of running (given the two hours searching for a fix this makes a total runtime from full battery of about 12 hours).

It should be noted that the current drawn by the gps receiver while getting a fix is quite high compare to normal operation.

Still I have kept the watch so far ;) The main advantage for me as compared to the Ambit for example is that you can just mount the watch and copy your files from the fenix to you computer using standard unix commands. And the other way round you can just copy any gpx file that you created elsewhere to the watch and later use it for track navigation.

Compare the the 910xt the elevation profile (from the watch) looks far better now. Getting gps fix is really good for me.

Regarding FIT file format, this is fine and nowadays no problem to handle. Gpsbabel now includes fit support as well and you can get the FIT SDK here.

In order to convert a fit file to gpx or garmins training center format you can do the following (note you need GPSBabel Version 1.4.4 or later):
$ gpsbabel -i garmin_fit -f -o gpx -F /tmp/2013-05-24_12-27-43.gpx
$ gpsbabel -i garmin_fit -f -o gtrnctr -F /tmp/2013-05-24_12-27-43.tcx

For now I want to point out that you can easily use the linux garmin plugin to upload file to your favorite online training portal (I nowadays use regularly).

My config ~/.config/garminplugin/garminplugin.xml looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<GarminPlugin logfile="/tmp/garminplugin.log" level="DEBUG">
        <Device enabled="false">
            <Name>Home Directory /home/andy</Name>
        <Device enabled="true">
            <Name>Garmin Fenix</Name>
        <ForerunnerTools enabled="false" />
        <BackupWorkouts enabled="true" path="~/Dropbox/Workouts/[YEAR]/[MONTH]/" />

Note: I have not yet setup automount, so you need to have the watch connected and mounted before this works.

Online Tool to repair corrupted Garmin fit files (e.g.reserved bits not zero):


finally ... managed to write the script to download latest fenix update (also read the comments!):

Monday, April 29, 2013

Which batteries for an Ultra-Marathon

 Which batteries for an Ultra-Marathon

... just some remarks on equipment

I recently had the chance to run the JUNUT 230k. A non-stop Ultra-Trail run on the "Premium Wanderweg" Jurasteig.

Total Distance was about 230k (237km measured by my Forerunner 305) time limit was 52h. The race starts at 10am in the morning and I was hoping to reach the finish line within the next two days (<=48h).
Speaking two days equals two nights out there running on sometimes really rough terrain so it was not really easy to decide on what to put in the running pack and into three drop-bags.

I could write much more on equipment and the race by itself but for now I stick to the topic ...
Besides my old Forerunner 305, which was charged via an external battery pack during the run, I took along a Garmin eTrex merely as a backup. My head lamp is a Petzl MYO RXP which, most of the time was at level 5 (I have programmed settings 8, 5, and 3 ... (I guess)). What I don't like about the MYO RXP is that after you have set one lightning mode you cannot switch modes without the lamp turning off :( But besides that this one is excellent and probably one of the best if you look at the price-value tag.

I had one more electronic device which was my  LG-E610, this is for emergency calls and taking some snapshots, so no need to worry about battery life during 48 hours.

So I had to make sure the eTrex30 and the Petzl will run long enough for this run. Sure the usual approach is to buy standard cells and take spare batteries in the pack during the run and keep some in the drop-bags. Or use rechargeable cells and keep (usually) even more replacement batteries around.
This time I thought I give Lithium non-rechargeable standard AA cells a try. Sure they come at a little higher cost than alkaline but in turn they have higher capacity and are very light.

After the run I can really recommend on the Energizer Ultimate Lithium which have a specified capacity of 3000mAh. Using three of them in the MYO RXP at an average lightning mode allowed for operating the lamp for full two nights without any noticeable performance loss (same intensity of light).
The eTrex30 was also running on two Energizer Ultimate Lithium and was fully operational after the 48h. I have to admit however that I had no need to change zoom-level very often or otherwise turn on the backlight (navigation was mainly done via the Forerunner 305 which is much more comfortable, while wearing the watch on the wrist).


Can finished 237k within 48:05:54 and Lithium batteries are good ;)

Monday, November 12, 2012

GPS Tracking

Misc information about GPS tracking devices and solutions.

What I'm looking for is a solution to track ultra runners during races lasting up to 30 hours or more.
Requirements on tracking device (the thing the runner will carry along, this could as well be a smartphone app):
  • Very Long Battery Life >30h (while almost continuously send GPS data)
  • Optional: replaceable batteries or at least ability to charge device while on the run. Or external battery connector ...
  • Send position data via GPRS connection to any computer on the internet
  • Configurable time interval for sending data (continuously vs. 10-20min. intervals)
  • Sleep mode (power-off GPS/GSM while not sending data)
  • Optional: Multiple Geo-fences (e.g. Alert when running through aid station)
  • ...
In addition a web portal is required to visualize the runners along a given course.

Currently I think only two types of hardware tracker would make sense:
  • GPS (or in the future other satellite system) / GSM tracker:
    • gets location via satellite and transmit position data via mobile phone network (GPRS)
    • advantage is relative low cost for data transmission
    • disadvantage are roaming costs if used across different countries, mobile network coverage sometimes not available.
  • GPS / Satellite communication tracker"
    • this is what e.g. SPOT tracker do. You receive GPS position and transmit via satellite communication network  
    • disadvantage relative high cost almost always you need to subscribe for monthly or yearly provider plan and pay in advance.
    • advantage is depending on area and satellite communication provider usually good coverage.

This page is work in progress!!

List of Tracking Devices:

Tracking Portal: