... | ... | @@ -102,7 +102,7 @@ Enable temperature compensation, setting `0x80` in addition to the existing `0x1 |
|
|
/usr/sbin/i2cset -y 2 0x1e 0x20 0x98
|
|
|
```
|
|
|
|
|
|
Now read the values for each axis (x, y, z respectively):
|
|
|
Now read the values for each axis (x, y, z respectively) from the 16-bit registers, `OUT_X_[LH]_M`, `OUT_Y_[LH]_M` and `OUT_Z_[LH]_M`:
|
|
|
```
|
|
|
/usr/sbin/i2cget -y 2 0x1e 0x28 w
|
|
|
/usr/sbin/i2cget -y 2 0x1e 0x2a w
|
... | ... | @@ -113,3 +113,40 @@ Set the operating mode to power-down again: |
|
|
```
|
|
|
/usr/sbin/i2cset -y 2 0x1e 0x22 3
|
|
|
```
|
|
|
|
|
|
**Accelerometer and Gyroscope:**
|
|
|
|
|
|
These are not visible to user space programs via `/dev/i2c-2` if the `st_gyro_i2c` module is enabled. With it removed, the `WHO_AM_I_G` register can be read:
|
|
|
```
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x0f
|
|
|
```
|
|
|
The output from this should be `0x68`.
|
|
|
|
|
|
The accelerometer can be enabled by setting certain combinations of the top three bits in the `CTRL_REG6_XL` register. Setting the lowest of these three bits causes values to be supplied at a rate of 10 Hz:
|
|
|
```
|
|
|
/usr/sbin/i2cset -y 2 0x6a 0x20 0x20
|
|
|
```
|
|
|
|
|
|
Reading the status from the `STATUS_REG` register indicates whether data is available:
|
|
|
```
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x27
|
|
|
```
|
|
|
This may return values with bit 2 set if temperature data is available, and bit 0 set if accelerometer data is available.
|
|
|
|
|
|
If new temperature data is available, it can be read from the 16-bit `OUT_TEMP_[LH]` register:
|
|
|
```
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x15 w
|
|
|
```
|
|
|
|
|
|
If new accelerometer data is available, it can be read from the 16-bit `OUT_X_XL`, `OUT_Y_XL` and `OUT_Z_XL` registers:
|
|
|
```
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x28 w
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x2a w
|
|
|
/usr/sbin/i2cget -y 2 0x6a 0x2c w
|
|
|
```
|
|
|
|
|
|
Reset the `CTRL_REG6_XL` register to its original value to disable the accelerometer:
|
|
|
```
|
|
|
/usr/sbin/i2cset -y 2 0x6a 0x20 0x0
|
|
|
```
|
|
|
The bits in the status register will remain set until any remaining temperature or accelerometer data is read. |
|
|
\ No newline at end of file |