• Thank you for your reply :)
    After reading and thinking I tried rewriting all of my read and write calls, though I am still quite confused over exactly what the "writeRegister" function actually does.

    What I am guessing so far, is that the _sensorID is set via "getSensor", which is called at some point, though as far as I can see it's not called in the code nor in the examples from Adafruit.
    From then on it's automagically inserted in the write function called by writeRegister8?

    I am assuming that

    uint8_t buffer[2] = {reg, value}
    

    creates a new "Uint8Array" of length 2, and adds the reg on position 0 and the value on position 1?

    Then from what I can read

    i2c_dev.write(buffer,2)
    

    in js would be akin to

    this.i2c.writeTo(0x1D, [reg, val])
    

    Is that correct? Not certain what to do with the 2 though.

    I tried changing my read/write calls to look like the following

    this.i2c.writeTo(this.MMA8451_ADDR, [this.MMA8451_REG_CTRL_REG2, 0x02]);
    

    I am still quite confused about how to do this then:

    i2c_dev->write_then_read(buffer, 1, buffer, 6);

    I attempted to write it like this

    let buffer = new Uint8Array([this.MMA8451_REG_OUT_X_MSB, 0, 0, 0, 0, 0]);
        this.i2c.writeTo(this.MMA8451_ADDR, [buffer, 1]);
        let val2 = this.i2c.readFrom(this.MMA8451_ADDR, 6);
    

    But I'm pretty sure that's wrong, I am getting changing values at least, but they seem random xD
    I just had the chip laying on my desk and ran "logIt" a few times in row, and got these values.

    x_g 7.97021484375 y_g 6.5048828125 z_g 7.001953125
    val2 new Uint8Array([255, 15, 208, 41, 224, 17])

    x_g 7.97607421875 y_g 4.25146484375 z_g 2
    val2 new Uint8Array([255, 61, 136, 12, 64, 3])

    x_g 7.97607421875 y_g 7.7509765625 z_g 6
    val2 new Uint8Array([255, 60, 248, 11, 192, 3])

    x_g 7.97607421875 y_g 4.0009765625 z_g 3.5
    val2 new Uint8Array([255, 63, 128, 11, 112, 3])

    x_g 7.97607421875 y_g 4.7509765625 z_g 3.00048828125
    val2 new Uint8Array([255, 62, 152, 11, 96, 4])

    x_g 7.97607421875 y_g 1.00146484375 z_g 4.5
    val2 new Uint8Array([255, 63, 32, 12, 144, 3])

    x_g 7.97607421875 y_g 5.5009765625 z_g 4.75
    val2 new Uint8Array([255, 62, 176, 9, 152, 3])

    x_g 7.97607421875 y_g 6.2509765625 z_g 0.5
    val2 new Uint8Array([255, 63, 200, 11, 16, 3])

    x_g 7.9765625 y_g 6.7509765625 z_g 0
    val2 new Uint8Array([255, 64, 216, 11, 0, 3])

    x_g 7.97607421875 y_g 7.2509765625 z_g 7.00048828125
    val2 new Uint8Array([255, 61, 232, 8, 224, 4])

    x_g 7.97607421875 y_g 4.5009765625 z_g 7.00048828125
    val2 new Uint8Array([255, 62, 144, 9, 224, 4])

    x_g 7.97607421875 y_g 0.5009765625 z_g 1.75048828125
    val2 new Uint8Array([255, 63, 16, 9, 56, 4])

    x_g 7.97607421875 y_g 5.00048828125 z_g 6.75048828125
    val2 new Uint8Array([255, 62, 160, 7, 216, 4])

    x_g 7.97607421875 y_g 0.0009765625 z_g 2.50048828125
    val2 new Uint8Array([255, 63, 0, 8, 80, 5])

    x_g 7.97607421875 y_g 3.5009765625 z_g 0.75048828125
    val2 new Uint8Array([255, 63, 112, 9, 24, 4])

    As you can see, despite laying on my desk, X is 7.976 all throughout while Y and Z are fluctuating, so I'm pretty sure I'm still doing something wrong, but I feel as though I'm closer at least :)

About

Avatar for TheLogan @TheLogan started