Tilt Hydrometer Brew Display with Pixl.js

Tilt Hydrometer Display

The Tilt Hydrometer is a nice easy way to get real-time information about the specific gravity and temperature of beer that you're brewing.

Usually it connects to a phone or Raspberry Pi, but if you want a simple always-on display for it then you can use this example (or use it as a base for other projects!).

Simply upload this to Pixl.js and after a few seconds it'll display the Tilt Hydrometer's current reading Temperature and Gravity reading.

The code will work on any Bluetooth LE capable Espruino board - if you're not using a Pixl you can add your own display with the Graphics instance as the g variable, or you can just replace displayInfo.

Source Code

function displayInfo(reading) {
  g.clear();
  if (!reading) {
    g.drawString("No Tilt found");
  } else {
    g.drawString("Temperature",0,0);
    g.drawString("Gravity",0,30);
    g.setFontVector(20);
    g.setFontAlign(0,-1);
    g.drawString(reading.tempC.toFixed(1),64,6);
    g.drawString(reading.gravity,64,36);
    g.setFontAlign(-1,-1);
    g.setFontBitmap();
  }
  g.flip();
}

var failures = 0;

function takeReading() {
  // scan for 5 seconds max
  NRF.setScan(function(device) {
    d = new DataView(device.manufacturerData);
    if (d.getUint8(4)!=0xbb) console.log("Not a tilt"); // not a Tilt
    var tempF = d.getUint16(18);
    var tempC = ( tempF - 32) * 5 / 9;
    var gravity = d.getUint16(20) / 1000.0;
    readings= { tempC:tempC, F:tempF,gravity:gravity, d:device.manufacturerData  };
    failures=0;
    NRF.setScan();
    if (notFoundTimeout) clearTimeout(notFoundTimeout);
    notFoundTimeout = undefined;
    displayInfo(readings);
  }, { filters: [{ manufacturerData: { 0x004C: {} } }]});
  // stop scanning after 5 seconds
  var notFoundTimeout = setTimeout(function() {
    NRF.setScan();
    notFoundTimeout = undefined;
    failures++;
    if (failures>5) displayInfo();
  }, 5000);
};


// Scan every minute
setInterval(function() {
  takeReading();
}, 60*1000);
// Scan once at boot/upload
takeReading();

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.