• I'm still struggling to get MCP9701 temp sensor to work efficiently. I believe my calculations are off or possibly the leads on the sensor are too long causing interference and unreliable readings. My goal is to get my temp readings stable and return either the temp in degrees C or degrees F which will be chosen by setting a 'c' or 'f' in the functions arguments.

    Also, I am attempting to stabilize the readings by using a for loop to return the average temp. I recently changed my code around to include a switch statement to return the temp in degrees C or degrees F which is where I think I did something wrong.

    code:

    function getResTempValue(x, tempType) {
      var temp=0;
      var avgTemp=0;
      var tfixed=0;
    
      for (var i=0;i<x;i++)
      {
        var vOut = E.getAnalogVRef() * analogRead(A0); // if you attached VOUT to Ao
        var vZero = 0.4;
        var tCoeff = 19.5 / 1000;
        var tempinc = (vOut - vZero) / tCoeff;
        var tempinf = tempinc * (9 / 5) + 32;
    
        switch(tempType) {
            case 'c':
                temp = tempinc;
                break;
            case 'f':
                temp = tempinf;
                break;
            default:
                temp = tempinc;
                 //code block
        }
      }
    
      temp = temp / x;
      tfixed = temp.toFixed(2);
      return tfixed;
    }
    
    setInterval(function (e) {
      var t = getResTempValue(10, 'f');
      var toChar = "";
      var a = resTemptDisplay.address;
      var clr = resTemptDisplay.displayTable.Clear; //Display clear command
      var dpc = resTemptDisplay.displayTable.dp.cmd; //Decimal point command
      var dplo = resTemptDisplay.displayTable.dp.location; //Decimal point location map
    
      var i;
    
      I2C1.writeTo(a, clr); //Clear display
    
      I2C1.writeTo(a, t);
      console.log(t);
    }, 2000);
    
About

Avatar for d0773d @d0773d started