NRF51-DK and Ubuntu 14.04 in five minutes (Getting started with Nordic NRF51822 Bluetooth Low Energy Development Kit)

nrf51-2
Glorious new nails + NRF51-DK, which is Arduino-Due-shield-compatible.

Short Story

  1. Go to https://developer.mbed.org/platforms/, add the NRF51-DK platform, open the compiler, import the “mbed_blinky” example, hit compile, and download the *.hex file
  2. Plug-in the NRF51-DK with a microUSB cable and turn the switch to “on”.
  3. Copy or drag-and-drop the .hex file to the “JLink” drive, which should auto-mount and appear under “devices” in your file manager
  4. Voila! Light should now be blinking.

Background

Recently after a bit of head-scratching, I found out that it’s very easy to program ARMs on Ubuntu 14.04, or at least the ARM chip on the system-on-a-chip NRF51822, an integrated circuit made by Nordic Semi that has both a bluetooth low-energy module [1] and a 32-bit ARM® Cortex™ M0 CPU with 256kB flash + 16kB RAM.

I’m exploring this chip because the atmega328p chip by itself is around $2.5 in quantity, and this chip has both an ARM microcontroller (mcu) and ble built-in for $2.5.

[1] (2.4Ghz transceiver, so actually supports NRF24L01+ protocol as well, for which you can find transceiver breakouts on ebay for $2)

nrf24l01+
nrf24l01+ breakout

I bought the NRF51-DK recently on semiconductorstore.com for $70 plus shipping. This is the main page: https://www.nordicsemi.com/eng/Products/nRF51-DK .

Yea, not much of a “get started here” anywhere on the page. The PDF tells you to download NRFgo studio and is obviously on windows.

So here’s my getting started guide. Note: I followed https://evothings.com/getting-started-with-mbed-arms-new-iot-platform-and-the-nordic_semiconductor-nrf51-dk/ for the most part.

Overview

  1. We will use the mbed compiler to turn our code from “DigitalOutput(LED1)”-esque code into .hex files for our chip, the NRF51-DK.
    mbed is a browser-based compiler, so you hit “compile” and get a file to download. I believe it’s developed directly by ARM.
    mbed has a Microsoft XP look, which is quite strange-looking inside the browser, but it works.
  2. We will “program” our chip by copying the .hex file to the “JLink” drive that shows up in our windows manager, similar to how a USB drive or other external drive shows up.

mbed

  1. Create an mbed account
  2. Go to “Platforms” and search for NRF51-DK, then click “Add to my compiler.”
  3. Click on “open mbed compiler”Screenshot from 2015-08-26 13:26:00
  4. The mbed compiler takes a while (minutes) to load. Grab a cup of coffee.
  5. Click “import” then search for “mbed_blinky” by the Author “team mbed”.  Click on it and hit enter, and the program will be imported
    Screenshot from 2015-08-26 13:30:18
  6. Open the program and click on “main.cpp” in the root folder. No changes are needed. The url should be something like: https://developer.mbed.org/compiler/#nav:/mbed_blinky/main.cpp;
    Screenshot from 2015-08-26 13:30:50
    T
    he code is:

    #include "mbed.h"
    
    DigitalOut myled(LED1);
    
    int main() {
        while(1) {
            myled = 1;
            wait(0.2);
            myled = 0;
            wait(0.2);
        }
    }
    
  7. Hit “compile” and save the file that you are prompted to download.
    Screenshot from 2015-08-26 14:15:43
  8. All done with this step! Optional: Change the wait time to 0.2 seconds and download another .hex file.

J-Link Programming

For me, I just plugged in the dev board using a micro-usb cable, turned the switch on the board to “on”,  and it showed up (ubuntu 14.04) and auto-mounted and showed up under “Devices” in nautilus file manager.

I’m not certain if I installed drivers along the way, but if so it must have been something sudo apt-get installable, because I don’t remember it.

Screenshot from 2015-08-26 14:12:15
output of dmesg | tail after plugging in device
  1. Drag and drop the .hex file to the JLink drive (or otherwise copy it over). Warning: drag-and-drop in nautilus pastes the .hex file over, and it’s not preserved after the chip programs itself, so use ctrl-c ctrl-v (or otherwise copy instead of cut) if you want to keep it!
  2. The JLink “drive” will disappear and after a few seconds reappear. This is it programming itself and rebooting itself.

    Screenshot from 2015-08-26 14:11:53
    Drag-and-drop
  3. Your LED1 should now be blinking! Yay!
    You can double-check that there’s no “fail.txt” in the JLink drive.

    Screenshot from 2015-08-26 14:13:48
    No “fail.txt”1 Yay

That’s it! Whoo!

Congratulations, you’ve now programmed the NRF51-DK on Ubuntu 14.04 to do the “hello world” blink example!

Exploring the Harvard Personal Genome Project Dataset with Untap

Recently, my co-worker Abram Connelly scraped the phenotypes in the Harvard Personal Genome Project and made it available in a small SQLite database, publicly available for anyone to download. He made a small webapp around the database where people can play around with the data directly in their browser.

Webapp (first page has link to gzip of the database): curoverse.link/22d61dd43786c65cd175b04ad6954af0+3119/html/index.html 

dataset

The dataset consists of people who have completed the enrollment process and were free to upload their own data for public release and also answer the surveys online (but not necessarily people who have donated samples, had the samples sequence, or had the samples released publicly).

To put it concretely, there are around 4000 people enrolled, and around 200 people with whole genome sequences that were  sequenced, interpreted, and returned by Harvard PGP as of August 2015 (though keep your ears open for upcoming news). (Participants may have whole genomes sequenced independently and then elect to upload and donate the data to the Harvard PGP).

webapp

Returning to the webapp, there are a few default tabs, where you can do things like explore what year PGP participants were born, where you can see that our population is mostly young folks…

“Summary” Pre-Packaged View of Allergies of Participants

…or with two clicks see what allergies are most common in PGP participants. Note that this is a quick scrape of the Tapestry database and no clean-up has been done, so you’ll notice allergies being listed twice with different spellings.

SQL Queries for Participants with “Oak” Allergies

On the “queries” tab, you can query the sql database and see the results in neat table form in your browser.

Additionally, there are some pre-packaged but interactive visualizations, where you can edit the text and have the graph update to reflect your changes / newly requested data.

For instance, here’s a display of the participant gender ratio at different ages which I modify to display information about the allergies at different age buckets

before, displaying gender of participants

and after, displaying penicillin and house dust allergies

Obligatory cat statistics

Although one could hope that this graph shows that PGP participants are not more likely to develop allergies to cats as they grow older, we have a lot more younger participants and this is absolute and not percent frequency, so we might have to say the data points to the opposite. Sad!

(Disclaimer: Just for fun, no real thought put into this analysis :] )

Conclusion

Ever wanted a public genotype + phenotype dataset? The Harvard PGP has you covered!

We have phenotype surveys galore (including a recently released one that includes blood type and eye color), with responses available in CSV form. The questions on the survey forms are available on github for now.

I hope you all enjoy! Untap is on github

https://github.com/abeconnelly/untap

and Abram welcomes feature requests / issue reporting. We hope this is beneficial to the GA4GH working groups specifically and other researchers in general.

Enabling Multi-touch Gestures on Lenovo Thinkpad 2nd gen x1 with Ubuntu 14.04

I recently set-up multi-touch on my lenovo x1 2nd gen and got it to work (pinch and zoom, one-finger drag) on Chrome and Chromium, although not the (sadly less-featured right now) Firefox.

My  post on askubuntu.com follows.

Touchegg  (sudo apt-get install touchegg)  works for me — however apparently not on Firefox or Chrome, only on Chromium, do the multi-touch gestures work for me (out-of-the-box).

On Chromium, I can one-finger drag (on-screen touch, not touchpad), two finger scroll (touchpad), pinch and zoom (on-screen touch).

See: Firefox bug, http://askubuntu.com/a/664898/67349

To fix chrome, I had to follow both answers at Chrome + Touchscreen + Unity (14.04)

First,

  • Navigate to chrome://flags/#touch-events and
  • set Enable touch events Mac, Windows, Linux, Chrome OS to enabled.
  • I also set “Enable pinch scale. Windows, Linux, Chrome OS” to enabled (instead of default).

Second, I needed to start google chrome and tell it which device.

$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ ELAN Touchscreen                          id=9    [slave  pointer  (2)]
$ google chrome --touch-devices=2

My Setup

  • ubuntu 14.04
  • lenovo 2nd gen x1.
  • Chromium: Version 43.0.2357.130 Ubuntu 14.04 (64-bit)
  • Chrome: Version 43.0.2357.134 (64-bit)
  • Firefox: 40.0

My ~/.config/touchegg/touchegg.conf if it’s useful: http://pastebin.com/qGexA1gB

Rainbow!~ heart cookies (pt1)

I really like rainbow things. This has entailed baking an increasing amount of rainbow things. Here’s a brief blog, pt1, about rainbow heart cookies. pt2 is about challah, and pt3 about asian chiffon cake.

Update 9/4/15: Added pictures from webcam, which detail missing parts of the process

1) Rainbow Heart Cookies

Following these instructions ‘Eugenie Kitchen Rainbow Heart Cookies”: https://www.youtube.com/watch?v=I2yW_VONWco

The ideal

eugeniekitchencom

Ours didn’t turn out as pretty, but then again we didn’t use a ruler.

final cookie! missing a few colors, so it goes
final cookie! missing a few colors, so it goes

Full gallery: https://goo.gl/photos/yvgARo9pxZYsZwD26

2) Rainbow Challah

To be continued in the next post, pt 2!

 

WordPress Blogroll Links Import Fix & Google Spreadsheet to OPML Generator

In order to bulk import a list of titles & URLs for my friend’s blogs into wordpress, I created a google spreadsheet and then used an open-source opml-generator to turn the spreadsheet into OPML and import it into WordPress.

The hosted version at http://opml-generator.appspot.com/ was not working for me as of Aug. 2015, so I fixed it and ran it locally. Here are the fixes I made.

To Run

I had to install the google app engine python SDK, https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

Also, I had to install django-utils and python 2.7

$ sudo pip install django-utils
$ sudo apt-get install python2.7-dev

Then, simply use the appserver included with the google app engine python SDK, give it this project’s directory

$ /path/to/google_appengine/dev_appserver.py /path/to/opml-generator

The happy output should look like

INFO     2015-08-17 03:30:37,516 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO     2015-08-17 03:30:38,341 sdk_update_checker.py:257] The SDK is up to date.
INFO     2015-08-17 03:30:38,373 api_server.py:205] Starting API server at: http://localhost:40380
INFO     2015-08-17 03:30:38,375 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2015-08-17 03:30:38,376 admin_server.py:118] Starting admin server at: http://localhost:8000

and go to http://localhost:8080/

Enter the URL, the title, and the “opml” url should automatically populate.

Changes

Then I had to make a few changes to make app.yaml recognize the django-utils was needed, that I was using python 2.7,

$ vi app.yaml
threadsafe: no
runtime: python27

libraries:
- name: django
  version: "1.5"

I created the URL via “Share” > “Share with Others” > “Anyone can view” and it looked like

https://docs.google.com/spreadsheets/d/1GXkKX74boMLia2lIVwgN0E

It appears that the original code works with old google docs urls, which look like:

https://spreadsheets2.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Ah0xU81penP1dGlQbGZ6Si03M0ZOQTd2ZzRfUmdUTmc&output=html

Thus, I modified base.html to find the document key appropriately.

//var ssKey = ssUrl.split('key=')[1];
var ssKey = ssUrl.split('/d/')[1]; console.log(ssKey); 
//ssKey = ssKey.split('&')[0]; 
ssKey = ssKey.split('/pubhtml')[0];

Note: I also threw out some printouts to console.log to figure all this out. They can be found by using Chrome or Firefox, Ctrl-Shift-C, and going ot the “Console” tab.

Screenshot from 2015-08-16 23:50:09

I also edited the output URL which, for localhost, did not include the port.

//var opmlUrl = 'http://' + window.location.hostname + '/opml?sskey=' + ssKey + '&wsid=od6'; 
var opmlUrl = 'http://' + window.location.hostname + ':8080/opml?sskey=' + ssKey + '&wsid=od6';

Output OPML Format

In the end, I looked at the output OPML and think I should probably have just made the file by hand / with vim macros… it would have been easy enough. But I got to take a peek at Google App Engine, so that was nice.

Here’s what the OPML looks like, if you’re interested in creating it more manually instead of installing google app engine etc. etc. to run this code:

<?xml version="1.0" encoding="utf-8" ?>
<opml version="1.1">
 <head>
  <title>MITERS</title>
 </head>
 <body>
   <outline text="MITERS">
    <outline title="MITERS | MIT Electronics Research Society" xmlUrl="http://miters.mit.edu/blog/feed/"/>
    <outline title="nk | Nick Kirkby" xmlUrl="http://nkirkby.scripts.mit.edu/nk/feed/"/>
  </outline>
 </body>
</opml>

Or in screenshot form

Screenshot from 2015-08-16 23:31:43

WordPress Import Blogroll Fix

The error: when you try to import the OPML file into WordPress, it says “All done!” but when you check the blogroll manager, no links were actually imported.

Screenshot from 2015-08-16 23:34:13

The fix: Super simple. Just change all the instances of xmlUrl in the OPML file into htmlUrl .

Screenshot from 2015-08-17 18:27:12

Tada! The links now import properly 🙂