Adding ADC channels to the official firmware?

Could someone (if there isn’t such thing already) in the know write and compile a separate version of the official firmware (or/and from raw v2) which reports the values of one or more ADC channels on top of the official channels? This way it would be easy to just solder some wires onto the board for custom sensors without having to go deep into nRF programming. I bet there is a lot of hardware folks out there that would love to just use RuuviTag as a low power wireless ADC beacon with temperature, acceleration etc… I know I would.


Easiest way to get started would be with Espruino.

Yes, I’m aware of the Espruino option. However, I’d like to avoid any programming learning curve since I’d only want to solder a few wires and be ready to go. I already have software for gathering and processing the beacon data.

I think offering the ADC option officially or through the community would be a great addition to the beacon functionality. I’m surprised that no one has done this (or that it’s not easily found). Maybe there are hardware obstacles for adding the ADC lines to the official software that I’m not aware of. I can’t imagine this would take too many lines of code if you know where to put them.

Ok. I figured out how to read RuuviTag’s ADC line with Espruino and advertise it:

function onInit() { // So that the code will be loaded after every boot

var Ruuvitag = require("Ruuvitag");
var NRF52LL = require("NRF52LL");

// Define ADC channel
var saadc = NRF52LL.saadc({
    channels: [{ 
        pin: 4, // pin P0.04/AIN2 = RuuviTag PAD 10
        gain: 1 / 4,
        tacq: 40,
        refvdd: true,


setInterval(function() {
    var adcSample = saadc.sample()[0];
    console.log("ADC: " + adcSample);
    console.log("Temperature: " + temperature);
        0x2a3f: [adcSample],  // random id
        0x1809: [Math.round(Ruuvitag.getEnvData().temp * 100)], 
}, 2000);

} // onInit()

Could someone show me how to advertise/mimic RuuviTag RAW v2 format output with Espruino code? I want to read my special Espruino RuuviTag with RuuviCollector.

I have this running on a Puck to show me the temperature on Grafana.

 // Ble-Puck-Ruvii00.js
// test manufacturer Ruvii
var arr = new Uint8Array(14); // Ruvii
var temp = 0;
var counter = 0;

function onInit() {


  d = new DataView(arr.buffer);

  NRF.setAdvertising({},{manufacturer: 0x0499, manufacturerData: [arr]});

  setWatch(function() {
    digitalPulse(LED2, 1, 0.6);
    temp = E.getTemperature();

  }, BTN, {edge:"rising", repeat:1, debounce:20});

  setInterval(function () {
    //temp = E.getTemperature() + 2.75;//3.5; // for 54:ba
    temp = E.getTemperature() + 1.0;//2.0; // for 2a:60
    //temp = E.getTemperature() + 4.25; // for c0:dc
    //volt = Puck.getBatteryPercentage();

    volt = NRF.getBattery();

    d.setUint8(0,3); // data format 3
    d.setUint8(1,0); // humi

    ts = Math.floor(temp);
    tm = temp - ts;
    d.setUint8(2,ts); // temp sign + 7bit
    d.setUint8(3,tm * 100); // temp (/100)
    d.setUint16(4,counter);  // pressure use as counter
    d.setUint16(6,0);  // acc X
    d.setUint16(8,0);  // acc Y
    d.setUint16(10,0); // acc Z
    d.setUint16(12,volt * 1000); // milli

    NRF.setAdvertising({},{manufacturer: 0x0499, manufacturerData: [arr]});
  }, 5000);


function pri() {
  console.log(' ');
  console.log(NRF.getBattery() * 1000);

  console.log(' ');
  console.log(temp - Math.floor(temp));

onInit(); // rem on save()

1 Like