• BLE Module & Mooshimeter

    Monday, March 10, 2014

    3/10/2014— Jon McKay

    For the past few weeks, I’ve been head-down in technical development on our Bluetooth Low Energy module driver. We’re using the BlueGiga BLE113 chip for our bluetooth communication and it receives commands over the UART bus from Tessel.

    The Status of Bluetooth Hardware

    Our Bluetooth Module has undergone a several revisions since our first attempt:

    You’ll notice that there are several through-holes on the bottom of the final revision.

    As in many of our modules, we wanted to expose some extra functionality for more hardware-savvy users without getting in the way of folks who don’t need it. We’ve exposed an I2C port, two GPIOs, and an ADC on the module itself. The GPIOs are important for making the module use less power (discussed below).

    We made a difficult decision regarding the assignment of the third GPIO pin on the module port. We were running into an issue where if the reset button on the Tessel was pressed while the BLE module was plugged in, it would pull the UART transmit line low, causing the BLE113 UART parser to freeze when it parsed what it perceived as an invalid array of zeros.

    It wouldn’t unfreeze until the module was physically reset. After contacting BlueGiga support (who are exceptionally responsive, by the way), we came to the conclusion that the problem wouldn’t be solved until BlueGiga’s software engineer got around to fixing it.

    Making the success of your hardware dependent on the schedule of another company’s engineer is rarely a good idea. We had little choice but to assign the third GPIO pin directly to the BLE113 reset line so that we could automatically reset the module in software between code deployments. The downside is that third GPIO was originally assigned to the wake-pin, which allowed the module to go to sleep and save energy when the Tessel wasn’t communicating with it.

    In order to preserve that functionality, we exposed the wake-pin on the bank of extra through holes so that those who need to make BLE as lower power as possible can still access that functionality.

    Testing with Mooshimeter

    Our good friends over at Mooshim Engineering were kind enough to lend us an early version of their new Mooshimeter, a bluetooth-enabled multimeter. It was a perfect chance to test out our bluetooth module and its driver. Integrating with the Mooshimeter was incredibly easy. After connecting to the device, I simply had to tell it to turn on its analog-to-digital converter and I could start receiving asynchronous notifications with voltage values. Check out the JavaScript code below to start printing out voltage values in the terminal (gist):

    var tessel = require('tessel');
    var blePort = tessel.port('a');
    var bleDriver = require('../');
    bluetooth = bleDriver.use(blePort, function(err) {
      if (err) {
        return console.log("Failed to connect");
      else {
        // Connect to moosh
        connectToMoosh(function(moosh) {
          // Tell the meter to start reading, pass back char to read
          setMeterSettings(moosh, function(meterSample) {
            // Start reading that char
    function startReadingMeter(meterSample) {
        meterSample.on('notification', function(value) {
          var voltage = 0;
          for (var i = 0; i < 3; i++) {
            voltage += value[3+i] << (i*8);
          voltage = (0x1000000 - voltage)  * (1.51292917e-04);
          console.log("Voltage", voltage);
    function setMeterSettings(mooshimeter, callback) {
      if (mooshimeter) {
        // Find the characteristic with meter settings
        mooshimeter.discoverCharacteristics(['ffa2', 'ffa6'], function(err, characteristics) {
          var meterSample = characteristics[0];
          var meterSettings = characteristics[1];
          // Update meter settings struct to start reading...
          meterSettings.write(new Buffer([3, 2, 0, 0, 0, 0, 0, 0, 23]), function(err, valueWritten) {
            callback && callback(meterSample);
    function connectToMoosh(callback) {
      bluetooth.filterDiscover(mooshFilter, function(err, moosh) {
        bluetooth.stopScanning(function(err) {
          moosh.connect(function(err) {
            callback && callback(moosh);
    function mooshFilter(peripheral, callback) {
      for (var i = 0; i < peripheral.advertisingData.length; i++) {
        var packet = peripheral.advertisingData[i];
        if (packet.type = 'Incomplete List of 16-bit Service Class UUIDs'
            && packet.data[0] == '0xffa0') {
          return callback(true);
      return  callback(false);


    See it work on Vine!

    I’m really excited to build out the Mooshimeter example to be able to read out both channels on the multimeter.

    Almost There

    The Bluetooth Driver is about 60% done at this point. I still need to add security functionality (pairing, encryption, etc.), hardware functionality to be able to use the through-holes at the bottom, and the ability to update the firmware of the BlueGiga module itself over UART. Then I’ll be polishing up a comprehensive test suite so that we can continuously integrate any new changes to the driver. It’s a lot of work for one module, but totally worth it.


    #jon mckay #tessel #technical machine #ble #bluetooth #bluegiga #ble113 #uart #i2c #mooshimeter #mooshim engineering #javascript

August 2018

January 2018

July 2017

February 2017

November 2016

October 2016

September 2016

August 2016

July 2016

June 2016

April 2016

March 2016

February 2016

November 2015

September 2015

August 2015

July 2015

June 2015

May 2015

March 2015

February 2015

January 2015

December 2014

November 2014

October 2014

September 2014

August 2014

July 2014

June 2014

May 2014

April 2014

March 2014

February 2014

January 2014

December 2013

November 2013

October 2013

September 2013

August 2013

July 2013