TMP102 module

Posted on
  • I created this module today. It allows Espruino board to interface with a TMP102 temperature sensor. It is accurate down to 0.0625 of a degree.

    I2C1.setup({scl:B6,sda:B7});
    var TMP102 = require("tmp102").connect(I2C1);
    console.log(TMP102.getTemperature());
    
     
    function TMP102(_i2c) {
        this.i2c = _i2c;
        this.address = 0x48;   
    }
    
    TMP102.prototype.getTemperature = function() {
        var self = this;  
        var d = self.i2c.readFrom(self.address, 2);
        var temp = (((d[0] << 8) | d[1]) >> 4)*0.0625; 
        return temp;
    };
    
    
    exports.connect = function (_i2c) {
        return new TMP102(_i2c);
    };
    

    https://www.sparkfun.com/products/11931

  • Great! Thanks! Would you like me to put it in with the Espruino modules, or would you like to do it? instructions here

  • Here a little example. I clean and reduce a little bit the code. Some var definitions are not needed.

    /* Copyright (c) 2014 ToDo */
    /*
    Quick description ToDO
    */
    
    var C = {
      ADDRESS : 0x48    // description
    };
    
    /**
     * Description
    */
    function TMP102(_i2c) {
        this.i2c = _i2c;
    }
    
    /**
     * Description
    */
    TMP102.prototype.getTemperature = function() {
        var d = this.i2c.readFrom(C.ADDRESS, 2);
        return (((d[0] << 8) | d[1]) >> 4)*0.0625; 
    };
    
    /**
     * export
    */
    exports.connect = function (_i2c) {
        return new TMP102(_i2c);
    };
    
  • I will attempt to add this at the weekend.

  • Thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

TMP102 module

Posted by Avatar for user7143 @user7143

Actions