• As I said in my previous post. I managed to fix it by changing line 8 in which I write 1 to instead write 0, this seems to clear the previous measurement or something in the TMP117 and then the next reading works flawless.

    I adaparted the Espruino Data Collection example to store the temp measurement of the TMP117 and the magnetometer of the puck.js board every 30seconds in memory and then export it out via bluetooth using a site to connect and download the logs.

    var i2c = new I2C();
    i2c.setup({ scl : D31, sda: D30 });
    const TMP117_Address = '0x48';
    const Temp_Reg = '0x00';
    var log = new Float32Array(2000); // our logged data
    var magLog = new Float32Array(2000); // our logged data
    var logIndex = 0; // index of last logged data item
    var magLogIndex = 0; // index of last logged data item
    var timePeriod = 30*1000; // every 30 secs
    var lastReadingTime; // time of last reading
    
    // Store data into RAM
    function storeMyData(data) {
      logIndex++;
      if (logIndex>=log.length) logIndex=0;
      log[logIndex] = data;
      
      let mag = Puck.mag();
      magLogIndex++;
      if (magLogIndex>=magLog.length) magLogIndex=0;
      magLog[magLogIndex] = data;
    }
    
    // Get Data and store it in RAM
    function getData() {
      i2c.writeTo(TMP117_Address, Temp_Reg);
      let a = i2c.writeTo(TMP117_Address, 0);
    
      setTimeout(() => {
        let b = i2c.readFrom(TMP117_Address, 2);
        let datac = ((b[0] << 8) | b[1]);
        let temp = datac*0.0078125;
        console.log(temp);
        storeMyData(temp);
        lastReadingTime = Date.now();
      }, 500);
    }
    
    // Dump our data in a human-readable format
    function exportData() {
      for (var i=1;i<=log.length;i++) {
        var time = new Date(lastReadingTime - (log.length-i)*timePeriod);
        var data = log[(i+logIndex)%log.length];
        console.log(Math.floor(time/1000)+" "+data);
      }
    
      for (var y=1;y<=magLog.length;y++) {
        var time2 = new Date(lastReadingTime - (magLog.length-y)*timePeriod);
        var data2 = magLog[(y+magLogIndex)%magLog.length];
        console.log(Math.floor(time2/1000)+" "+data2);
      }
    }
    
    function startLight () {
      digitalWrite(LED2,1);
      setTimeout(() => {
        digitalWrite(LED2,0);
      }, 1000);
    }
    
    function stopLight () {
      digitalWrite(LED1,1);
      setTimeout(() => {
        digitalWrite(LED1,0);
      }, 1000);
    }
    
    var recording = true;
    var interval = setInterval(getData, timePeriod);
    
    setWatch(function() {
      console.log("Pressed");
      if (recording) { 
        recording = false;
        clearInterval(interval);
        stopLight();
      } else {
        recording = true;
        interval = setInterval(getData, timePeriod);
        startLight();
      }
    }, BTN, {edge:"rising", debounce:50, repeat:true});
    
    */
    
    
    
    
    
    

    sorry for variable names :/
    I also added a start green led and stop red led if you press the button to start and stop recording temps

About

Avatar for user101989 @user101989 started