TS-7250-V3 ST ISM330 Gyroscope

From embeddedTS Manuals

The gyroscope is accessed through IIO as ism330dlc_accel with channels:

  • anglvel_x
  • anglvel_y
  • anglvel_z
  • timestamp

For example:

root@tsimx6ul:~# iio_attr -c ism330dlc_gyro anglvel_x
dev 'ism330dlc_gyro', channel 'anglvel_x' (input), attr 'raw', value '2359'
dev 'ism330dlc_gyro', channel 'anglvel_x' (input), attr 'scale', value '0.000153'
dev 'ism330dlc_gyro', channel 'anglvel_x' (input), attr 'scale_available', value '0.000153 0.000305 0.000611 0.001222'
root@tsimx6ul:~# iio_attr -c ism330dlc_gyro anglvel_y
dev 'ism330dlc_gyro', channel 'anglvel_y' (input), attr 'raw', value '-1667'
dev 'ism330dlc_gyro', channel 'anglvel_y' (input), attr 'scale', value '0.000153'
dev 'ism330dlc_gyro', channel 'anglvel_y' (input), attr 'scale_available', value '0.000153 0.000305 0.000611 0.001222'
root@tsimx6ul:~# iio_attr -c ism330dlc_gyro anglvel_z
dev 'ism330dlc_gyro', channel 'anglvel_z' (input), attr 'raw', value '2761'
dev 'ism330dlc_gyro', channel 'anglvel_z' (input), attr 'scale', value '0.000153'
dev 'ism330dlc_gyro', channel 'anglvel_z' (input), attr 'scale_available', value '0.000153 0.000305 0.000611 0.001222'

This shows a snapshot of the x, y, z values. To get the real world value, multiply the scale * the raw value. In this case:

  • X: 0.360927 dps
  • Y: -0.255051 dps
  • Z: 0.422433 dps

The default scale is ±250, but ±250/±500/±1000/±2000 can be selected by setting the scale:

dev 'ism330dlc_gyro', channel 'anglvel_z' (input), attr 'scale', value '0.000153'
dev 'ism330dlc_gyro', channel 'anglvel_z' (input), attr 'scale_available', value '0.000153 0.000305 0.000611 0.001222'

To set ±1000, you would write the third available scale:

iio_attr -c ism330dlc_gyro anglvel_z scale 0.000611

The scale values are not independent on this device, and setting x/y/z will set the scale for all 3.

This driver also supports pulling continuous samples using the buffer interface. These can be accessed using iio_readdev:

iio_readdev ism330dlc_gyro -T 0 -s 128 > samples.bin

The format of this file is specified with iio_attr:

root@tsimx6ul:~# iio_attr -c ism330dlc_accel
dev 'ism330dlc_gyro', channel 'anglvel_x' (input, index: 0, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'ism330dlc_gyro', channel 'anglvel_y' (input, index: 1, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'ism330dlc_gyro', channel 'anglvel_z' (input, index: 2, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'ism330dlc_gyro', channel 'timestamp' (input, index: 3, format: le:S64/64>>0), found 0 channel-specific attributes

The samples are padded to the nearest 8-bytes, so this means the binary format is:

Bits Description
15:0 anglvel_x, little endian, signed
15:0 anglvel_y, little endian, signed
15:0 anglvel_z, little endian, signed
63:0 timestamp, little endian, signed
15:0 Padding

The unix utility hexdump supports formatting options which can parse these fields into their raw values:

root@tsimx6ul:~# hexdump samples.bin --format '1/2 "X:%d " 1/2 "Y:%d " 1/2 "Z:%d " 1/8 "TS:%d" 1/2 "" "\n"' | head -n 40
X:-58 Y:-199 Z:24 TS:419695978925948679
X:-67 Y:-196 Z:29 TS:419701023781322503
X:-64 Y:-197 Z:28 TS:419705968690298631
X:-58 Y:-203 Z:29 TS:419711008204553991