Difference between revisions of "IKS01A2 MEMS expansion board"

[quality revision] [quality revision]
m (Hardware / software interface)
m
 

1 Article purpose[edit]

The purpose of this article is to explain how to integrate the IKS01A2 expansion board with STM32MP157C-DK2, managed by Linux on Cortex®-A7.

The IKS01A2 board is an expansion board composed by that includes several motion MEMS like HTS221 and LSM6DSL.

This article explains provides step-by-step instructions to:

  • how to configure Linux software to support IKS01A2 expansion board,
  • how to activate/use several motion MEMS such as HTS221 and LSM6DSL.

2 Prerequisites[edit]

2.1 Hardware prerequisites[edit]

  • STM32MP157C-DK2
STM32MP157C-DK2

For more information about this the STM32 discovery board and how to start with it up, jump to this section Getting_started/STM32MP1_boards/STM32MP157C-DK2

  • IKS01A2 expansion board
IKS01A2
IKS01A2 expansion board

2.2 Software prerequisites[edit]

The STM32MP157C-DK2 board must be populated downloaded with appropriate software to be able to customize it to in order to support IKS01A2 expansion board. To know how to proceed please For proceeding, follow the step-by-step description starting with instructions provided at STM32MP157C-DK2 Let's start article.

3 Software customization to support IKS01A2 expansion board[edit]

The STM32MP157C-DK2 Linux software must be configured to activate the IKS01A2 board connected on top of the STM32MP157C-DK2 board.

Configuration is done by The configuration consists in modifying the STM32MP157C-DK2 Linux kernel and by managing some new device tree elements.

3.1 Kernel configuration[edit]

By default, the motion MEMS drivers , present on IKS01A2 expansion board , are enabled in STM32MP1 kernel configuration: hts221, pressure(lp22hb) and lsm6dsl. The device tree must be updated to declare and activate them.

To check whether associated drivers are enabled inside the kernel, follow type the commands given provided here below :

Board $>  cat /proc/config.gz | gunzip | grep HTS221
CONFIG_HTS221=y
CONFIG_HTS221_I2C=y
CONFIG_HTS221_SPI=y
Board $>  cat /proc/config.gz | gunzip | grep ST_PRESS
CONFIG_IIO_ST_PRESS=m
CONFIG_IIO_ST_PRESS_I2C=m
CONFIG_IIO_ST_PRESS_SPI=m
Board $>  cat /proc/config.gz | gunzip |  grep ST_LSM6DS
CONFIG_IIO_ST_LSM6DSX=m
CONFIG_IIO_ST_LSM6DSX_I2C=m
CONFIG_IIO_ST_LSM6DSX_SPI=m
Info.png If those the above configurations are not enabled on your kernel configuration, please follow the indications given in Modify, rebuild and reload the Linux® kernel

3.2 Kernel device tree configuration[edit]

3.2.1 Hardware / software interface[edit]

Motion MEMS The HTS221 and LSM6DSL , motion MEMS present on IKS01A2 expansion board are used involved in the following use case explained in this article.
According to IKS01A2 user manual[1], both motion MEMS are controlled by I2C I2C bus.

In the schematics of IKS01A2 [2] and STM32MP157C-DK2[3] , presented below, are identified the pins which are connected togetherthat are interconnected are highlighted.

  • IKS01A2 schematic (Arduino connector) [2]
    • Pins 10 and 9 of CN5 are used for I2C I2C Bus (SDA and SCL) (I2C1 and I2C2 bus instances are mixed via the jumper JP7 and JP8 jumpers)
    • Pins 6 and 5 of CN9 are used to manage interruptions on LSM6DSL motion MEMS (indicated for information: not used on kernel configuration).
Screenshot iks01a2
IKS01A2 schematics extract
  • STM32MP157C-DK2 schematic (Arduino connector) [3]
    • Pins 10 and 9 of CN5 are used for I2C I2C Bus (I2C5_SDA and I2C5_SCL)
    • Pins 6 and 5 of CN14 are used to manage interruptions on LSM6DSL motion MEMS (indicated for information: not used on kernel configuration)
Screenshot stm32mp157c-dk2
stm32mp157c-dk2 schematics extract


Warning.png I2C5 bus instance MUST be enabled on by software in order to access to the motion MEMS present on IKS01A2

3.2.2 Kernel device tree configuration[edit]

As seen indicated in previous chaptersection, the IKS01A2 expansion board is controlled via IC2 I2C bus. On STM32MP157C-DK2, the associated I2C I2C bus is I2C5.

The I2C5 bus must be activated into STM32MP157C-DK2 device tree and a node must be added for each hardware to support must be added supported (see entry on device tree entries like hts221, below, on the following as shown in the device tree content example below).


For that, add following content into stm32mp157c-dk2.dts file:

 &i2c5 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c5_pins_a>;
	pinctrl-1 = <&i2c5_pins_sleep_a>;
	i2c-scl-rising-time-ns = <124>;
	i2c-scl-falling-time-ns = <3>;
	/delete-property/dmas;
	/delete-property/dma-names;

	status = "okay";

	hts221@5f {
		compatible = "st,hts221";
		reg = <0x5f>;
	};
	lsm6dsl@6b {
		compatible = "st,lsm6dsl";
		reg = <0x6b>;
	};
 };
Info.png To generate a new device tree, please follow the indications given in Modify, rebuild and reload the Linux® kernel

3.3 Activate the new configuration in the STM32MP157C-DK2 board[edit]

  • Add the two generated files on in the board file system of board, more accurately precisely in the bootfs partition (/boot directory)
Board $> ls -1 /boot/stm32*dk2*
                                                                                              
/boot/stm32mp157c-dk2-a7-examples.dtb
/boot/stm32mp157c-dk2-iks01a2.dtb
/boot/stm32mp157c-dk2-m4-examples.dtb
/boot/stm32mp157c-dk2.dtb
  • Add a new entry in extlinux.conf file , here located in /boot/mmc0_stm32mp157c-dk2_extlinux/. If no directory the mmc0_<something> directory is not available, add the new entry in /boot/extlinux/extlinux.conf.
 1  # Generic Distro Configuration file generated by OpenEmbedded
 2  menu title Select the boot mode
 3  MENU BACKGROUND ../splash.bmp
 4  TIMEOUT 20
 5  DEFAULT stm32mp157c-dk2-iks01a2
 6  LABEL stm32mp157c-dk2-sdcard
 7          KERNEL /uImage
 8          FDT /stm32mp157c-dk2.dtb
 9          APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
10  LABEL stm32mp157c-dk2-a7-examples-sdcard
11          KERNEL /uImage
12          FDT /stm32mp157c-dk2-a7-examples.dtb
13          APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
14  LABEL stm32mp157c-dk2-m4-examples-sdcard
15          KERNEL /uImage
16          FDT /stm32mp157c-dk2-m4-examples.dtb
17          APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
18  LABEL stm32mp157c-dk2-iks01a2
19         KERNEL /uImage
20         FDT /stm32mp157c-dk2-iks01a2.dtb
21         APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200


Warning.png Do not forget to synchronize the file system before rebooting the board
Board $> sync


  • Reboot the board

3.4 Verify the new configuration on board[edit]

  • Verify if i2c5 is enabled:
Board $>  cat /proc/device-tree/soc/i2c\@40015000/status 
okay
  • Verify if the motion MEMS drivers are declared on in the device tree node:
Board $> ls -l /proc/device-tree/soc/i2c\@40015000/
total 0
-r--r--r-- 1 root root  4 Dec 19 11:01 #address-cells
-r--r--r-- 1 root root  4 Dec 19 11:01 #size-cells
-r--r--r-- 1 root root  8 Dec 19 11:01 clocks
-r--r--r-- 1 root root 15 Dec 19 11:01 compatible
-r--r--r-- 1 root root  6 Dec 19 11:01 dma-names
-r--r--r-- 1 root root 32 Dec 19 11:01 dmas
drwxr-xr-x 2 root root  0 Dec 19 10:54 hts221@5f
-r--r--r-- 1 root root  4 Dec 19 11:01 i2c-scl-falling-time-ns
-r--r--r-- 1 root root  4 Dec 19 11:01 i2c-scl-rising-time-ns
-r--r--r-- 1 root root 19 Dec 19 11:01 interrupt-names
-r--r--r-- 1 root root 44 Dec 19 11:01 interrupts-extended
drwxr-xr-x 2 root root  0 Dec 19 10:54 lsm6dsl@6b
-r--r--r-- 1 root root  4 Dec 19 11:01 name
-r--r--r-- 1 root root  4 Dec 19 11:01 pinctrl-0
-r--r--r-- 1 root root  4 Dec 19 11:01 pinctrl-1
-r--r--r-- 1 root root 14 Dec 19 11:01 pinctrl-names
-r--r--r-- 1 root root  4 Dec 19 11:01 power-domains
-r--r--r-- 1 root root  8 Dec 19 11:01 reg
-r--r--r-- 1 root root  8 Dec 19 11:01 resets
-r--r--r-- 1 root root 12 Dec 19 11:01 st,syscfg-fmp
-r--r--r-- 1 root root  5 Dec 19 11:01 status
  • Verify if the motion MEMS drivers are correctly probed and if the system provides access to the associated hardware:
Board $>  grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
/sys/bus/iio/devices/iio:device0/uevent:OF_NAME=adc
/sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adc
/sys/bus/iio/devices/iio:device2/uevent:OF_NAME=hts221
/sys/bus/iio/devices/iio:device3/uevent:OF_NAME=temp
/sys/bus/iio/devices/iio:device4/uevent:OF_NAME=lsm6dsl
/sys/bus/iio/devices/iio:device5/uevent:OF_NAME=lsm6dsl
Info.png If the results are different then , check that
  1. the expansion board is correctly connected
  2. all steps, described above, were correctly done.

4 Read motion MEMS via bash script[edit]

The goal of this section are is to read the informations provided by the Linux kernel interface and to process it on with a bash script.


4.1 List of sensors entrysensor entries[edit]

The IKS01A2 expansion board provides several MEMS like HTS221, LSM6DSL, LPS22HB.
Hardware The list of hardware MEMS , detected by Linux via the IIO framework, can be listed by verifying the entries on verified in the sysfs.

Board $>   grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
/sys/bus/iio/devices/iio:device0/uevent:OF_NAME=adc
/sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adc
/sys/bus/iio/devices/iio:device2/uevent:OF_NAME=hts221
/sys/bus/iio/devices/iio:device3/uevent:OF_NAME=temp
/sys/bus/iio/devices/iio:device4/uevent:OF_NAME=lsm6dsl
/sys/bus/iio/devices/iio:device5/uevent:OF_NAME=lsm6dsl

This list of entries permits to know which entries are associated to a MEMS driverprovides the association between entries and MEMS drivers. In the rest of the article, this list is kept used a as reference list of entries.

4.2 HTS221: Temperature/Humidity[edit]

The HTS221 is a capacitive digital sensor for relative humidity and temperature.

In this example, hts221 entries are entry is /sys/bus/iio/devices/iio:device2/, please adapt to your setup if it's not the case by changing the entry on the scripts described/explained in following chapters. In case the user has a different setup, the entry should be adapted accordingly in the scripts provided hereafter.

4.2.1 Temperature[edit]

  • Read IIO entries associated to the temperature for HTS221 driver
Board $>  cat /sys/bus/iio/devices/iio\:device2/in_temp_raw
Board $>  cat /sys/bus/iio/devices/iio\:device2/in_temp_offset
Board $>  cat /sys/bus/iio/devices/iio\:device2/in_temp_scale
  • Calculate real temperature according with the following formula
Temperature = ( Raw value + Offset value) * Scale value)
  • Calculate temperature by shell script : static IIO entries

Content of hts221_read_temperature_on_device2.sh:

#!/bin/sh
raw=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_temp_
raw`
raw`
offset=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_temp_
offset`
offset`
scale=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_temp_
scale`
scale`
printf "Value read: raw        
 %0f
 %0f\n" $raw
printf "Value read: offset     
 %0f
 %0f\n" $offset
printf "Value read: scale      
 %0f
 %0f\n" $scale

temperature=
`echo
`echo "scale=2;$raw*$scale + $offset*$scale" | 
bc`
bc`

echo "Temperature $temperature"
printf "
Temperature %
Temperature %.01f\n" $temperature


  • Calculate temperature by shell script: auto detection of IIO entries

Content of hts221_read_temperature_with_entry_detection.sh:

#!/bin/sh
DRIVER_NAME=hts221
for d in 
`ls
`ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/
name 
name ;
    then
        raw=
`cat
`cat $d/in_temp_
raw`
raw`
        offset=
`cat
`cat $d/in_temp_
offset`
offset`
        scale=
`cat
`cat $d/in_temp_
scale`
scale`

        printf "Value read: raw        
 %0f
 %0f\n" $raw
        printf "Value read: offset     
 %0f
 %0f\n" $offset
        printf "Value read: scale      
 %0f
 %0f\n" $scale

        temperature=
`echo
`echo "scale=2;$raw*$scale + $offset*$scale" | 
bc`
bc`

        echo "Temperature $temperature"
        printf "
Temperature %
Temperature %.01f\n" $temperature

        break;
    fi
done

  • Test on board
Board $>  ./hts221_read_temperature_on_device2.sh
Value read: raw         563.000000
Value read: offset      1036.674817
Value read: scale       0.019172
Temperature 30.668765624
Temperature 30.7

4.2.2 Humidity[edit]

  • Read IIO entries associated to humidity for HTS221 driver
Board $> cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_raw
Board $> cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_offset
Board $> cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_scale
  • Calculate real humidity according with the following formula
Humidity = ( Raw value + Offset value) * Scale value)
  • Calculate humidity by shell script: static IIO entries

Content of hts221_read_humidity_on_device2.sh:

#!/bin/sh
raw=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_
raw`
raw`
offset=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_
offset`
offset`
scale=
`cat
`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_
scale`
scale`
printf "Value read: raw        
 %0f
 %0f\n" $raw
printf "Value read: offset     
 %0f
 %0f\n" $offset
printf "Value read: scale      
 %0f
 %0f\n" $scale

humidity=
`echo
`echo "scale=2;$raw*$scale + $offset*$scale" | 
bc`
bc`

echo "Humidity $humidity"
printf "
Humidity %
Humidity %.01f\n" $humidity


  • Calculate humidity by shell script: auto detection of IIO entries

Content of hts221_read_humidity_with_entry_detection.sh:

#!/bin/sh
DRIVER_NAME=hts221
for d in 
`ls
`ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/
name 
name ;
    then
        raw=
`cat
`cat $d/in_humidityrelative_
raw`
raw`
        offset=
`cat
`cat $d/in_humidityrelative_
offset`
offset`
        scale=
`cat
`cat $d/in_humidityrelative_
scale`
scale`

        printf "Value read: raw        
 %0f
 %0f\n" $raw
        printf "Value read: offset     
 %0f
 %0f\n" $offset
        printf "Value read: scale      
 %0f
 %0f\n" $scale

        humidity=
`echo
`echo "scale=2;$raw*$scale + $offset*$scale" | 
bc`
bc`

        echo "Humidity $humidity"
        printf "
Humidity %
Humidity %.01f\n" $humidity

        break;
    fi
done

  • Test on board
Board $> ./hts221_read_humidity_on_device2.sh
Value read: raw         2669.000000
Value read: offset      -10661.500000
Value read: scale       -0.003000
Humidity 23.977500000
Humidity 24.0

4.3 LSM6DSL: accelerometer/gyroscope[edit]

The LSM6DSL is an inertial measurement unit (IMU) with ultra-low power and high accuracy, for smartphones and battery operating operated IoT, gaming, wearable wearables and consumer electronics, ultra-low power and high accuracy.

In this example, lsm6dsl entries are /sys/bus/iio/devices/iio:device4/ and /sys/bus/iio/devices/iio:device4/.
Device4 The device4 entry is dedicated to accelerometer and the device5 one to gyroscope.

4.3.1 Accelerometer[edit]

  • Read IIO entries associated to accelerometer for LSM6DSL driver
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_x_raw
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_x_scale
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_y_raw
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_z_raw
Board $> cat /sys/bus/iio/devices/iio\:device4/in_accel_z_scale
  • Calculate accelerometer values according with the following formula
X = Raw value * scale value * (256.0 / 9.81)
Y = Raw value * scale value * (256.0 / 9.81)
Z = Raw value * scale value * (256.0 / 9.81)
  • Calculate accelerometer value by shell script: static IIO entries

Content of lsm6dsl_accel_read_on_device4.sh:

#!/bin/sh
xraw=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_
raw`
raw`
xscale=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_
scale`
scale`

yraw=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_
raw`
raw`
yscale=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_
scale`
scale`

zraw=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_
raw`
raw`
zscale=
`cat
`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_
scale`
scale`

printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw $xscale
printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw $yscale
printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw $zscale

factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
xval=
`echo
`echo "scale=2;$xraw*$xscale*$factor" | 
bc`
bc`
yval=
`echo
`echo "scale=2;$yraw*$yscale*$factor" | 
bc`
bc`
zval=
`echo
`echo "scale=2;$zraw*$zscale*$factor" | 
bc`
bc`

printf "Accelerometer value: [
 %
 %.02f,
 %
 %.02f,
 %
 %.02f ]\n" $xval $yval $zval

  • Calculate accelerometer value by shell script: auto detection of IIO entries

Content of lsm6dsl_accel_read_with_entry_detection.sh:

#!/bin/sh
DRIVER_NAME=lsm6dsl_accel       
for d in 
`ls
`ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/
name 
name ;
    then
        xraw=
`cat
`cat $d/in_accel_x_
raw`
raw`
        xscale=
`cat
`cat $d/in_accel_x_
scale`
scale`

        yraw=
`cat
`cat $d/in_accel_y_
raw`
raw`
        yscale=
`cat
`cat $d/in_accel_y_
scale`
scale`

        zraw=
`cat
`cat $d/in_accel_z_
raw`
raw`
        zscale=
`cat
`cat $d/in_accel_z_
scale`
scale`

        printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw $xscale
        printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw $yscale
        printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw $zscale

        factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
        xval=
`echo
`echo "scale=2;$xraw*$xscale*$factor" | 
bc`
bc`
        yval=
`echo
`echo "scale=2;$yraw*$yscale*$factor" | 
bc`
bc`
        zval=
`echo
`echo "scale=2;$zraw*$zscale*$factor" | 
bc`
bc`

        printf "Accelerometer value: [
 %
 %.02f,
 %
 %.02f,
 %
 %.02f ]\n" $xval $yval $zval
 
        break;
    fi
done

  • Test on board
Board $> ./lsm6dsl_accel_read_on_device4.sh
Value read: X (raw/scale)  104 / 0.000598 
Value read: Y (raw/scale)  -16378 / 0.000598 
Value read: Z (raw/scale)  -1117 / 0.000598 
Accelerometer value: [ 1.62, -255.53, -17.43 ]

4.3.2 Gyroscope[edit]

  • Read IIO entries associated to gyroscope for LSM6DSL driver
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_raw
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_scale
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_raw
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_raw
Board $> cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale
  • Calculate gyroscope values according following formula
X = Raw value * scale value * (256.0 / 9.81)
Y = Raw value * scale value * (256.0 / 9.81)
Z = Raw value * scale value * (256.0 / 9.81)
  • Calculate gyroscope value by shell script: static IIO entries

Content of lsm6dsl_gyro_read_on_device5.sh:

#!/bin/sh
xraw=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_
raw`
raw`
xscale=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_
scale`
scale`

yraw=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_
raw`
raw`
yscale=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_
scale`
scale`

zraw=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_
raw`
raw`
zscale=
`cat
`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_
scale`
scale`

printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw $xscale
printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw $yscale
printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw $zscale

factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
xval=
`echo
`echo "scale=2;$xraw*$xscale*$factor" | 
bc`
bc`
yval=
`echo
`echo "scale=2;$yraw*$yscale*$factor" | 
bc`
bc`
zval=
`echo
`echo "scale=2;$zraw*$zscale*$factor" | 
bc`
bc`

printf "Gyroscope value: [
 %
 %.02f,
 %
 %.02f,
 %
 %.02f ]\n" $xval $yval $zval

  • Calculate gyroscope value by shell script: auto detection of IIO entries

Content of lsm6dsl_gyro_read_with_entry_detection.sh:

#!/bin/sh
DRIVER_NAME=lsm6dsl_gyro       
for d in 
`ls
`ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/
name 
name ;
    then
        xraw=
`cat
`cat $d/in_anglvel_x_
raw`
raw`
        xscale=
`cat
`cat $d/in_anglvel_x_
scale`
scale`

        yraw=
`cat
`cat $d/in_anglvel_y_
raw`
raw`
        yscale=
`cat
`cat $d/in_anglvel_y_
scale`
scale`

        zraw=
`cat
`cat $d/in_anglvel_z_
raw`
raw`
        zscale=
`cat
`cat $d/in_anglvel_z_
scale`
scale`

        printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw $xscale
        printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw $yscale
        printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw $zscale

        factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
        xval=
`echo
`echo "scale=2;$xraw*$xscale*$factor" | 
bc`
bc`
        yval=
`echo
`echo "scale=2;$yraw*$yscale*$factor" | 
bc`
bc`
        zval=
`echo
`echo "scale=2;$zraw*$zscale*$factor" | 
bc`
bc`

        printf "Gyroscope value: [
 %
 %.02f,
 %
 %.02f,
 %
 %.02f ]\n" $xval $yval $zval

        break;
    fi
done

  • Test on board
Board $> ./lsm6dsl_gyro_read_on_device5.sh
Value read: X (raw/scale)  -2293 / 0.000153 
Value read: Y (raw/scale)  150 / 0.000153 
Value read: Z (raw/scale)  -111 / 0.000153 
Gyroscope value: [ -9.15, 0.60, -0.44 ]

4.4 BASH: script with all the measurements[edit]

  • Content of iks01a2.sh
#!/bin/sh
echo