• Just a code snipped:

    var addr = 0x76; //chip addr
    read = function(reg, len) {
      i2c.writeTo(addr, reg);
      return i2c.readFrom(addr, len);
    };
    write = function(reg, data) {
      i2c.writeTo(addr, [reg, data]);
    };
    
    var register = 0x12
    var length = 8
    var data = new Uint8Array(length);
    data.set(read(register, length));
    var a1 =  (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
    

    I didn't try/check your code in detail, but I'd suggest to define data (or b) as Uint8Array.

  • Looks like I2C.readFrom already returns an Uint8Array, so I think you are doing a double allocation.
    Not sure, but I think your memory usage might be smaller with just:

    var data = read(register, length);
    

    Or not, or might not even be measurable, if that allocation is just in a small function, and the GC frees up memory...

About

Avatar for maze1980 @maze1980 started