• Lol ... so working on that theory, I changed the logIt function to look like this

    logIt() {
        this.i2c.writeTo(this.MMA8451_ADDR, this.MMA8451_REG_OUT_X_MSB);
        let buffer = this.i2c.readFrom(this.MMA8451_ADDR, 7);
    
        let x = buffer[1];
        x <<= 8;
        x |= buffer[2];
        x >>= 2;
        let y = buffer[3];
        y <<= 8;
        y |= buffer[4];
        y >>= 2;
        let z = buffer[5];
        z <<= 8;
        z |= buffer[6];
        z >>= 2;
    
        const divider = 2048;
        let x_g = x / divider;
        let y_g = y / divider;
        let z_g = z / divider;
    
        console.log('x_g', x_g, 'y_g', y_g, 'z_g', z_g);
        console.log('buffer', buffer);
      }
    

    Essentially I'm just ignoring the first byte of data and grabbing 1 extra, and now the data at least seems relatively stable, though I think it's the tilt of the sensor, but for some reason in a range between 0 and 8 o_0, but it really doesn't fit with how I've understood I2C to work.

    From what I understand you send a write, telling what you want from the device, when you call read the first data you get back is the data you requested. I am rather confused ... xD

About

Avatar for TheLogan @TheLogan started