Ruuvitag

Ruuvitag

The Ruuvitag is a Bluetooth LE beacon with an environment sensor and accelerometer built in.

Full details on flashing Ruuvitag can be found at https://ruu.vi/setup

Binaries can be found in:

Using

Ruuvitag can be used like any other Espruino Bluetooth LE device, with full access to the NRF class for BLE Functionality.

However to use the built-in sensors you will need to use the Ruuvitag library. For instance to get data, use:

var Ruuvitag = require("Ruuvitag");
Ruuvitag.setEnvOn(true);
Ruuvitag.setAccelOn(true);
console.log(Ruuvitag.getEnvData());
// prints { "temp": 23.70573815741, "pressure": 1017.27733597036, "humidity": 42.0771484375 }
console.log(Ruuvitag.getAccelData());
// prints { "x": 3.90625, "y": -7.8125, "z": 984.375 }

You can also call a function whenever acceleration data is received:

var Ruuvitag = require("Ruuvitag");
Ruuvitag.setAccelOn(true, function(xyz) {
  console.log(xyz);
});

By default Espruino uses the low power accelerometer mode, however the peripherals can be accessed directly:

  • Ruuvitag.env is an instance of the BME280 environment sensor library
  • Ruuvitag.accel is an instance of the LIS2DH12 accelerometer library

Saving Code

Normally, uploading code to Espruino will put everything in RAM and it will be lost when power is removed. You can type save() on the left-hand side of the IDE to save to Flash memory though.

When you do that, the sensors will require initialising at power on (so may not work if you 'just' save your code). You'll need to create an onInit function like this, where you turn the sensors' power on at boot time:

var Ruuvitag = require("Ruuvitag");

function onInit() {
  Ruuvitag.setAccelOn(true, function(xyz) {
    console.log(xyz);
  });
}

Reference

// Set whether the environmental sensor is on or off
exports.setEnvOn = function (on) { ... }

/* Set whether the accelerometer is on or off. A callback can be supplied
  which will be called with an {x,y,z} argument
*/
exports.setAccelOn = function (on, callback) { ... }

// Get the last received environment data { temp: degrees_c, pressure: kPa, humidity: % }
exports.getEnvData = function (on) { ... }

// Get the last received accelerometer data, or undefined
exports.getAccelData = function (on) { ... }

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