Difference between revisions of "IKS01A2 MEMS expansion board"

[quality revision] [quality revision]
m (Hardware / software interface)
m (Kernel device tree configuration)
 

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/STM32MP157CSTM32MP157x-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 :

  cat /proc/config.gz | gunzip | grep HTS221
CONFIG_HTS221=y
CONFIG_HTS221_I2C=y
CONFIG_HTS221_SPI=y
  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
  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 white.png Information
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 white.png Warning
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 white.png Information
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)
 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 stm32mp157c-dk2_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/mmc0_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
OpenSTLinux
 7         KERNEL /uImage
 8        
FDT
 FDTDIR /
stm32mp157c-dk2.dtb

 9         INITRD /uInitrd
10         APPEND root=
/dev/mmcblk0p6
PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
11 LABEL stm32mp157c-dk2-a7-examples
-sdcard

12         KERNEL /uImage
13         FDT /stm32mp157c-dk2-a7-examples.dtb
14         INITRD /uInitrd
15         APPEND root=
/dev/mmcblk0p6
PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
16 LABEL stm32mp157c-dk2-m4-examples
-sdcard

17         KERNEL /uImage
18         FDT /stm32mp157c-dk2-m4-examples.dtb
19         INITRD /uInitrd
20         APPEND root=
/dev/mmcblk0p6
PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
21  LABEL stm32mp157c-dk2-iks01a2
22         KERNEL /uImage
23         FDT /stm32mp157c-dk2-iks01a2.dtb
24         APPEND root=
/dev/mmcblk0p6
PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200


Warning white.png Warning
Do not forget to synchronize the file system before rebooting the board
sync


  • Reboot the board

3.4 Verify the new configuration on board[edit]

  • Verify if i2c5 is enabled:
  cat /proc/device-tree/soc/i2c\@40015000/status 
okay
  • Verify if the motion MEMS drivers are declared on in the device tree node:
 ls -l /proc/device-tree/soc/i2c\@40015000/
total 0
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 #address-cells
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 #size-cells
-r--r--r-- 1 root root  84 DecFeb 19 11:01 clocks
-r--r--r-- 1 root root 15 Dec 19 11:01 compatible7 15:56 clock-frequency
-r--r--r-- 1 root root  68 DecFeb 19 117 15:0156 dma-namesclocks
-r--r--r-- 1 root root 3217 DecFeb 19 117 15:0156 dmascompatible
drwxr-xr-x 2 root root  0 DecFeb 19 107 15:5451 hts221@5f
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 i2c-scl-falling-time-ns
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 i2c-scl-rising-time-ns
-r--r--r-- 1 root root 1912 DecFeb 19 117 15:0156 interrupt-names
-r--r--r-- 1 root root 4428 DecFeb 19 117 15:0156 interrupts-extended
drwxr-xr-x 2 root root  0 DecFeb 19 107 15:5451 lsm6dsl@6b
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 name
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 pinctrl-0
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 pinctrl-1
-r--r--r-- 1 root root 14 DecFeb 19 117 15:0156 pinctrl-names
-r--r--r-- 1 root root  4 DecFeb 19 117 15:0156 power-domains
-r--r--r-- 1 root root  8 DecFeb 19 117 15:0156 reg
-r--r--r-- 1 root root  8 DecFeb 19 117 15:0156 resets
-r--r--r-- 1 root root 12 DecFeb 19 117 15:0156 st,syscfg-fmp
-r--r--r-- 1 root root  5 DecFeb 19 117 15:0156 status
-r--r--r-- 1 root root  0 Feb  7 15:56 wakeup-source

  • Verify if the motion MEMS drivers are correctly probed and if the system provides access to the associated hardware:
  grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
/sys/bus/iio/devices/iio:device0/uevent:OF_NAME=adchts221
/sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adclsm6dsl
/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 white.png Information
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.

   grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
/sys/bus/iio/devices/iio:device0/uevent:OF_NAME=adchts221
/sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adclsm6dsl
/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 chaptersdevice0/. 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
  cat /sys/bus/iio/devices/iio\:device2device0/in_temp_raw
  cat /sys/bus/iio/devices/iio\:device2device0/in_temp_offset
  cat /sys/bus/iio/devices/iio\:device2device0/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_device2device0.sh:

#!/bin/sh
raw=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_temp_
raw`
raw`
offset=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_temp_
offset`
offset`
scale=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/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
  ./hts221_read_temperature_on_device2device0.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
 cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_raw
 cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_offset
 cat /sys/bus/iio/devices/iio\:device2device0/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_device2device0.sh:

#!/bin/sh
raw=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_humidityrelative_
raw`
raw`
offset=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_humidityrelative_
offset`
offset`
scale=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/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
 ./hts221_read_humidity_on_device2device0.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:device4device1/ and /sys/bus/iio/devices/iio:device4device2/.
Device4 The device2 entry is dedicated to accelerometer and device5 the device1 one to gyroscope.

4.3.1 Accelerometer[edit]

  • Read IIO entries associated to accelerometer for LSM6DSL driver
 cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_rawscale
 cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scaleraw
 cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw
 cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_scale
 cat /sys/bus/iio/devices/iio\:device4/in_accel_z_raw
 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_device4device2.sh:

#!/bin/sh

xraw
rscale=
`cat
`cat /sys/bus/iio/devices/iio\:
device4
device2/in_accel_
x_raw` xscale=`cat
scale`
xraw=`cat /sys/bus/iio/devices/iio\:
device4
device2/in_accel_x_
scale`
raw`

yraw=
`cat
`cat /sys/bus/iio/devices/iio\:
device4
device2/in_accel_y_
raw` yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale` zraw=`cat
raw`
zraw=`cat /sys/bus/iio/devices/iio\:
device4
device2/in_accel_z_
raw`
raw`

zscale=`cat


/sys/bus/iio/devices/iio\:device4/in_accel_z_scale`
printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw 
$xscale
$rscale
printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw 
$yscale
$rscale
printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw 
$zscale
$rscale

factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
xval=
`echo
`echo "scale=2;$xraw*
$xscale
$rscale*$factor" | 
bc`
bc`
yval=
`echo
`echo "scale=2;$yraw*
$yscale
$rscale*$factor" | 
bc`
bc`
zval=
`echo
`echo "scale=2;$zraw*
$zscale
$rscale*$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
rscale=
`cat
`cat $d/in_accel_x_
raw`
scale`
        
xscale
xraw=
`cat
`cat $d/in_accel_x_
scale`
raw`
        
yraw=
`cat
`cat $d/in_accel_y_
raw`
raw`
        
yscale=`cat $d/in_accel_y_scale` zraw=`cat
zraw=`cat $d/in_accel_z_
raw`
raw`

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

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

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

  • Test on board
 ./lsm6dsl_accel_read_on_device4device2.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
 cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_rawscale
 cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scaleraw
 cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw
 cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_scale
 cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_raw
 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_device5device1.sh:

#!/bin/sh

xraw
rscale=
`cat
`cat /sys/bus/iio/devices/iio\:
device5
device1/in_anglvel_
x_raw` xscale=`cat
scale`
xraw=`cat /sys/bus/iio/devices/iio\:
device5
device1/in_anglvel_x_
scale`
raw`

yraw=
`cat
`cat /sys/bus/iio/devices/iio\:
device5
device1/in_anglvel_y_
raw` yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale` zraw=`cat
raw`
zraw=`cat /sys/bus/iio/devices/iio\:
device5
device1/in_anglvel_z_
raw`
raw`

zscale=`cat


/sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`
printf "Value read: X (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $xraw 
$xscale
$rscale
printf "Value read: Y (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $yraw 
$yscale
$rscale
printf "Value read: Z (raw/scale) 
 %d
 %d /
 %
 %.06f \n" $zraw 
$zscale
$rscale

factor=
`echo
`echo "scale=2;256.0 / 9.81" | 
bc`
bc`
xval=
`echo
`echo "scale=2;$xraw*
$xscale
$rscale*$factor" | 
bc`
bc`
yval=
`echo
`echo "scale=2;$yraw*
$yscale
$rscale*$factor" | 
bc`
bc`
zval=
`echo
`echo "scale=2;$zraw*
$zscale
$rscale*$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
rscale=
`cat
`cat $d/in_anglvel_
x_raw`
scale`
        
xscale
xraw=
`cat
`cat $d/in_anglvel_x_
scale`
raw`
        
yraw=
`cat
`cat $d/in_anglvel_y_
raw`
raw`
        
yscale=`cat $d/in_anglvel_y_scale` zraw=`cat
zraw=`cat $d/in_anglvel_z_
raw`
raw`

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

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

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

        break;
    fi
done

  • Test on board
 ./lsm6dsl_gyro_read_on_device5device1.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 "============================="
echo "===       HTS221          ==="
echo "===    (temperature)      ==="
echo "============================="
raw=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_temp_
raw`
raw`
offset=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/in_temp_
offset`
offset`
scale=
`cat
`cat /sys/bus/iio/devices/iio\:
device2
device0/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