• Assuming that's a TI TMP117 (providing a link to the chip and / or the library you try to port sometimes helps, or saves a couple of seconds), the Arduino code simply reads two bytes from register 0.

    At line 17 that delay

      // Delay to allow sufficient conversion time
      delay(10); 
    

    I don't think its necessary for two reasons:

    1. the datasheet doesn't say it's necessary :) (If I read the datasheet correctly, in continuous mode - and that's the default - you can just read the temperature values. Maybe you would have to wait before the first, but see the second point:
    2. Espruino is slow, so usually you can just ignore < 1ms delays. :) But always test it...

    I think @maze1980 is pretty close, this probably works:

    var addr = 0x48; //chip addr
    read = function(reg, len) {
      i2c.writeTo(addr, reg);
      return i2c.readFrom(addr, len);
    };
    write = function(reg, data) {
      i2c.writeTo(addr, [reg, data]);
    };
    
    // read two bytes from register `0`
    var b = read(0, 2));
    // and calculate the temperature:
    var temperature = ((b[0] << 8) | b[1]) * 0.0078125; 
    console.log('temperature:', temperature );
    
About

Avatar for AkosLukacs @AkosLukacs started