• The write...read pattern seems right. If you check out the libraries for some of the existing modules you'll see it's done in that way (http://www.espruino.com/I2C#using-i2c then you can usually go to a page a find a link to the module there). For instance in http://www.espruino.com/modules/VL53L0X.­js there are two functions r and w:

    VL53L0X.prototype.r = function(addr,n) {
      this.i2c.writeTo(this.ad, addr);
      return this.i2c.readFrom(this.ad, n);
    };
    VL53L0X.prototype.w = function(addr,d) {
      this.i2c.writeTo(this.ad, addr, d);
    };
    

    What you might be missing is some chips only read properly if you do an I2C write and read without something called a "stop" between. You can force that my changing the address var to an object as in: http://www.espruino.com/Reference#l_I2C_­writeTo

    In your case maybe:

        this.i2c.writeTo({address:this.MMA8451_A­DDR, stop:false}, this.MMA8451_REG_OUT_X_MSB);
        let buffer = this.i2c.readFrom(this.MMA8451_ADDR, 7);
    
About

Avatar for Gordon @Gordon started