Difference between revisions of "IKS01A2 MEMS expansion board"

[quality revision] [quality revision]
m
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 that includes several motion MEMS like HTS221 and LSM6DSL.

This article provides step-by-step instructions to:

  • configure Linux software to support IKS01A2 expansion board,
  • 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 the STM32 discovery board and how to start it up, jump to this section Getting_started/STM32MP1_boards/STM32MP157x-DK2

  • IKS01A2 expansion board
IKS01A2
IKS01A2 expansion board

2.2 Software prerequisites[edit]

The STM32MP157C-DK2 board must be downloaded with appropriate software in order to support IKS01A2 expansion board. For proceeding, follow the step-by-step instructions provided at STM32MP157C-DK2 Let's start.

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.

The configuration consists in modifying the STM32MP157C-DK2 Linux kernel and 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, type the commands 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 the above configurations are not enabled, 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]

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

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

  • IKS01A2 schematic (Arduino connector) [2]
    • Pins 10 and 9 of CN5 are used for I2C Bus (SDA and SCL) (I2C1 and I2C2 bus instances are mixed via 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 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 by software in order to access the motion MEMS present on IKS01A2

3.2.2 Kernel device tree configuration[edit]

As indicated in previous section, the IKS01A2 expansion board is controlled via I2C bus. On STM32MP157C-DK2, the associated 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 be supported (see entries like hts221, 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 in the board file system, 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 located in /boot/mmc0_stm32mp157c-dk2_extlinux/. If 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-sdcardOpenSTLinux
 7          KERNEL /uImage
 8         FDTDIR FDT /stm32mp157c-dk2.dtb
 9         INITRD /uInitrd
10         APPEND root=/dev/mmcblk0p6PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
1011  LABEL stm32mp157c-dk2-a7-examples-sdcard
1112          KERNEL /uImage
1213          FDT /stm32mp157c-dk2-a7-examples.dtb
1314         INITRD /uInitrd
15         APPEND root=/dev/mmcblk0p6PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
1416  LABEL stm32mp157c-dk2-m4-examples-sdcard
1517          KERNEL /uImage
1618          FDT /stm32mp157c-dk2-m4-examples.dtb
1719         INITRD /uInitrd
20         APPEND root=/dev/mmcblk0p6PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
1821  LABEL stm32mp157c-dk2-iks01a2
1922         KERNEL /uImage
2023         FDT /stm32mp157c-dk2-iks01a2.dtb
2124         APPEND root=/dev/mmcblk0p6PARTUUID=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 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, 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 is to read the informations provided by the Linux kernel interface and to process it with a bash script.


4.1 List of sensor entries[edit]

The IKS01A2 expansion board provides several MEMS like HTS221, LSM6DSL, LPS22HB.
The list of hardware MEMS detected by Linux via the IIO framework can be 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 provides the association between entries and MEMS drivers. In the rest of the article, this list is used a as reference.

4.2 HTS221: Temperature/Humidity[edit]

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

In this example, hts221 entry is /sys/bus/iio/devices/iio:device2device0/. 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 /sys/bus/iio/devices/iio\:device2device0/in_temp_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_scale`
printf "Value read: raw         %0f\n" $raw
printf "Value read: offset      %0f\n" $offset
printf "Value read: scale       %0f\n" $scale

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

echo "Temperature $temperature"
printf "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 -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    then
        raw=`cat $d/in_temp_raw`
        offset=`cat $d/in_temp_offset`
        scale=`cat $d/in_temp_scale`

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

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

        echo "Temperature $temperature"
        printf "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 /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_scale`
printf "Value read: raw         %0f\n" $raw
printf "Value read: offset      %0f\n" $offset
printf "Value read: scale       %0f\n" $scale

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

echo "Humidity $humidity"
printf "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 -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    then
        raw=`cat $d/in_humidityrelative_raw`
        offset=`cat $d/in_humidityrelative_offset`
        scale=`cat $d/in_humidityrelative_scale`

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

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

        echo "Humidity $humidity"
        printf "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 operated IoT, gaming, wearables and consumer electronics.

In this example, lsm6dsl entries are /sys/bus/iio/devices/iio:device4device1/ and /sys/bus/iio/devices/iio:device4device2/.
The device4 device2 entry is dedicated to accelerometer and the device5 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
xrawrscale=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_rawscale`
xscalexraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scaleraw`

yraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`

zraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_z_raw`
zscale=`cat
/sys/bus/iio/devices/iio\:device4/in_accel_z_scale`

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

factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale$rscale*$factor" | 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 -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    then
        xrawrscale=`cat $d/in_accel_x_rawscale`
        xscalexraw=`cat $d/in_accel_x_scaleraw`
         yraw=`cat $d/in_accel_y_raw`
        yscale=`cat $d/in_accel_y_scale`

        zraw=`cat $d/in_accel_z_raw`

       zscale=`cat $d/in_accel_z_scale`

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

        factor=`echo "scale=2;256.0 / 9.81" | bc`
        xval=`echo "scale=2;$xraw*$xscale$rscale*$factor" | bc`
        yval=`echo "scale=2;$yraw*$yscale$rscale*$factor" | bc`
        zval=`echo "scale=2;$zraw*$zscale$rscale*$factor" | 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
xrawrscale=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_rawscale`
xscalexraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scaleraw`

yraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`

zraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_z_raw`
zscale=`cat
/sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`

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

factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale$rscale*$factor" | 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 -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    then
        xrawrscale=`cat $d/in_anglvel_x_rawscale`
        xscalexraw=`cat $d/in_anglvel_x_scaleraw`
         yraw=`cat $d/in_anglvel_y_raw`
        yscale=`cat $d/in_anglvel_y_scale`

        zraw=`cat $d/in_anglvel_z_raw`

       zscale=`cat $d/in_anglvel_z_scale`

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

        factor=`echo "scale=2;256.0 / 9.81" | bc`
        xval=`echo "scale=2;$xraw*$xscale$rscale*$factor" | bc`
        yval=`echo "scale=2;$yraw*$yscale$rscale*$factor" | bc`
        zval=`echo "scale=2;$zraw*$zscale$rscale*$factor" | 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 /sys/bus/iio/devices/iio\:device2device0/in_temp_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_scale`
printf "Value read: raw      %0f\n" $raw
printf "Value read: offset   %0f\n" $offset
printf "Value read: scale    %0f\n" $scale

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

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

echo "============================="
echo "===       HTS221          ==="
echo "===    (humidity)         ==="
echo "============================="
raw=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_scale`
printf "Value read: raw         %0f\n" $raw
printf "Value read: offset      %0f\n" $offset
printf "Value read: scale       %0f\n" $scale

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

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


echo "============================="
echo "===      LSM6DSL          ==="
echo "===    (accelerometer)    ==="
echo "============================="

xrawrscale=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_rawscale`
xscalexraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scaleraw`

yraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`

zraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_z_raw`
zscale=`cat
/sys/bus/iio/devices/iio\:device4/in_accel_z_scale`

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

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

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

echo "============================="
echo "===      LSM6DSL          ==="
echo "===    (gyroscope)        ==="
echo "============================="

xrawxscale=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_rawscale`
xscalexraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scaleraw`

yraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`

zraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_z_raw`
zscale=`cat
/sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`

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

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

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

  • Content of iks01a2_with_auto_detection.sh
#!/bin/sh

for d in `ls -d1 /sys/bus/iio/devices/*device*`;
do
    # for hts221: Temperature + Humidity
    if grep -q hts221 $d/name ;
    then
        echo "============================="
        echo "===       HTS221          ==="
        echo "===    (temperature)      ==="
        echo "============================="
        raw=`cat $d/in_temp_raw`
        offset=`cat $d/in_temp_offset`
        scale=`cat $d/in_temp_scale`

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

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

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

        echo "============================="
        echo "===       HTS221          ==="
        echo "===    (humidity)         ==="
        echo "============================="
        raw=`cat $d/in_humidityrelative_raw`
        offset=`cat $d/in_humidityrelative_offset`
        scale=`cat $d/in_humidityrelative_scale`

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

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

        echo "Humidity $humidity"
        printf "Humidity %.02f\n" $humidity
    fi

    # for lsm6dsl: accelerometer
    if grep -q lsm6dsl_accel $d/name ;
    then
        echo "============================="
        echo "===      LSM6DSL          ==="
        echo "===    (accelerometer)    ==="
        echo "============================="
        xrawrscale=`cat $d/in_accel_x_rawscale`
        xscalexraw=`cat $d/in_accel_x_scaleraw`
         yraw=`cat $d/in_accel_y_raw`
        yscale=`cat $d/in_accel_y_scale`

        zraw=`cat $d/in_accel_z_raw`


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

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

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

    # for lsm6dsl: gyroscope
    if grep -q lsm6dsl_gyro $d/name ;
    then
        echo "============================="
        echo "===      LSM6DSL          ==="
        echo "===    (gyroscope)        ==="
        echo "============================="
        xrawrscale=`cat $d/in_anglvel_x_rawscale`
        xscalexraw=`cat $d/in_anglvel_x_scaleraw`
         yraw=`cat $d/in_anglvel_y_raw`
        yscale=`cat $d/in_anglvel_y_scale`

        zraw=`cat $d/in_anglvel_z_raw`

       zscale=`cat $d/in_anglvel_z_scale`

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

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

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

5 Read motion MEMS via Python script[edit]

The goal of this section is to read the informations provided by Linux kernel interface and process it with a python script.
The python displays the calculated value through a graphic user interface.

5.1 Display a window with Python and weston/wayland[edit]

#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GdkPixbuf
import cairo

import random
import math
import os
from time import sleep, time

# -------------------------------------------------------------------
# -------------------------------------------------------------------
class MainUIWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Sensor usage")
        #self.set_decorated(False)
        self.maximize()
        self.screen_width = self.get_screen().get_width()
        self.screen_height = self.get_screen().get_height()

        self.set_default_size(self.screen_width, self.screen_height)
        print("[DEBUG] screen size: %dx%d" % (self.screen_width, self.screen_height))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.connect('destroy', Gtk.main_quit)

    def destroy(self, widget, data=None):
        Gtk.main_quit()

# -------------------------------------------------------------------
# -------------------------------------------------------------------
# Main
if __name__ == "__main__":
    # add signal to catch CRTL+C
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    win = MainUIWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()

    Gtk.main()

5.2 Read temperature[edit]

Part of code for reading temperature with HTS221 driver:

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_temp_raw", "hts221")
try:
    with open(prefix_path + "in_temp_" + 'raw', 'r') as f:
        raw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'raw', exc)
    raw = 0.0

try:
    with open(prefix_path + "in_temp_" + 'scale', 'r') as f:
        scale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'scale', exc)
    scale = 0.0

try:
    with open(prefix_path + "in_temp_" + 'offset', 'r') as f:
        offset = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'offset', exc)
    offset = 0.0

temp = (offset + raw) * scale

5.3 Read humidity[edit]

Part of code for reading humidity with HTS221 driver:

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_humidityrelative_raw", "hts221")
try:
    with open(prefix_path + "in_humidityrelative_" + 'raw', 'r') as f:
        raw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'raw', exc)
    raw = 0.0

try:
    with open(prefix_path + "in_humidityrelative_" + 'scale', 'r') as f:
        scale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'scale', exc)
    scale = 0.0

try:
    with open(prefix_path + "in_humidityrelative_" + 'offset', 'r') as f:
        offset = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'offset', exc)
    offset = 0.0

humidity = (offset + raw) * scale

5.4 Read accelerometer[edit]

Part of code for reading accelerometer with LSM6DSL driver:

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_accel_x_raw", "lsm6dsl")
try:
    with open(prefix_path + "in_accel_" + 'x_raw', 'r') as f:
        xraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_raw', exc)
    xraw = 0.0

try:
    with open(prefix_path + "in_accel_" + 'x_scale', 'r') as f:
        xscalerscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scale', exc)
    xscalerscale = 0.0
accel_x = int(xraw * xscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
        yraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
    yraw = 0.0

try:
    with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
        yscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
    yscale = 0.0
accel_y = int(yraw * yscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
        zraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
    zraw = 0.0

try:
    with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
        zscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
    zscale = 0.0
accel_z = int(zraw * zscalerscale * 256.0 / 9.81)

5.5 Read gyroscope[edit]

Part of code for reading gyroscope with LSM6DSL driver:

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")
try:
    with open(prefix_path + "in_anglvel_" + 'x_rawscale', 'r') as f:
        xrawrscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_rawscale', exc)
    xrawrscale = 0.0

try:
    with open(prefix_path + "in_anglvel_" + 'x_scaleraw', 'r') as f:
        xscalexraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scaleraw', exc)
    xscalexraw = 0.0

gyro_x = int(xraw * xscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
        yraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
    yraw = 0.0

try:
    with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
        yscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
    yscale = 0.0
gyro_y = int(yraw * yscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
        zraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
    zraw = 0.0

try:
    with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
        zscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
    zscale = 0.0
gyro_z = int(zraw * zscalerscale * 256.0 / 9.81)

5.6 Full script with information displayed in a graphic user interface[edit]

#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GdkPixbuf
import cairo

import random
import math
import os
from time import sleep, time

# time between each sensor mesearuement (1s)
TIME_UPATE = 2000


class Sensors():
    def __init__(self):
        ''' '''
        self.sensor_dictionnary = {}

    def found_iio_device_with_name(self, data, name):
        prefix = "/sys/bus/iio/devices/"
        of_name = 'OF_NAME=' + name
        try:
            for filefolder in os.listdir(prefix):
                with open(prefix + '/' + filefolder + '/uevent') as f:
                    for line in f:
                        if line.split('\n')[0] == of_name:
                            ''' return directory which contains "data" '''
                            if os.path.exists(prefix + '/' + filefolder + '/' + data):
                                return (prefix + '/' + filefolder + '/')
        except OSError:
            pass
        except Exception as exc:
            pass
        return None

    def found_all_sensor_path(self):
        self.sensor_dictionnary['temperature'] = self.found_iio_device_with_name("in_temp_raw", "hts221")
        self.sensor_dictionnary['humidity']    = self.found_iio_device_with_name("in_humidityrelative_raw", "hts221")
        self.sensor_dictionnary['accelerometer'] = self.found_iio_device_with_name("in_accel_x_raw", "lsm6dsl")
        self.sensor_dictionnary['gyroscope'] = self.found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")

        print("[DEBUG] temperature   -> ", self.sensor_dictionnary['temperature'], "<")
        print("[DEBUG] humidity      -> ", self.sensor_dictionnary['humidity'], "<")
        print("[DEBUG] accelerometer -> ", self.sensor_dictionnary['accelerometer'], "<")
        print("[DEBUG] gyroscope     -> ", self.sensor_dictionnary['gyroscope'], "<")

    def temperature_read(self):
        prefix_path = self.sensor_dictionnary['temperature']
        try:
            with open(prefix_path + "in_temp_" + 'raw', 'r') as f:
                raw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'raw', exc)
            raw = 0.0
        try:
            with open(prefix_path + "in_temp_" + 'scale', 'r') as f:
                scale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'scale', exc)
            scale = 0.0
        try:
            with open(prefix_path + "in_temp_" + 'offset', 'r') as f:
                offset = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'offset', exc)
            offset = 0.0
        return (offset + raw) * scale

    def humidity_read(self):
        prefix_path = self.sensor_dictionnary['humidity']
        try:
            with open(prefix_path + "in_humidityrelative_" + 'raw', 'r') as f:
                raw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'raw', exc)
            raw = 0.0
        try:
            with open(prefix_path + "in_humidityrelative_" + 'scale', 'r') as f:
                scale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'scale', exc)
            scale = 0.0
        try:
            with open(prefix_path + "in_humidityrelative_" + 'offset', 'r') as f:
                offset = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'offset', exc)
            offset = 0.0
        return (offset + raw) * scale

    def accelerometer_read(self):
        prefix_path = self.sensor_dictionnary['accelerometer']
        try:
            with open(prefix_path + "in_accel_" + 'x_rawscale', 'r') as f:
                xrawrscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_rawscale', exc)
            xrawrscale = 0.0

        try:
            with open(prefix_path + "in_accel_" + 'x_scaleraw', 'r') as f:
                xscalexraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scaleraw', exc)
            xscalexraw = 0.0

        accel_x = int(xraw * xscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
                yraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
            yraw = 0.0

       try:             with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
                yscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
            yscale = 0.0
        accel_y = int(yraw * yscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
                zraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
            zraw = 0.0

       try:             with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
                zscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
            zscale = 0.0
        accel_z = int(zraw * zscalerscale * 256.0 / 9.81)
        return [ accel_x, accel_y, accel_z]

    def gyroscope_read(self):
        prefix_path = self.sensor_dictionnary['gyroscope']
        try:
            with open(prefix_path + "in_anglvel_" + 'x_rawscale', 'r') as f:
                xrawrscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_rawscale', exc)
            xrawrscale = 0.0
        try:
            with open(prefix_path + "in_anglvel_" + 'x_scaleraw', 'r') as f:
                xscalexraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scaleraw', exc)
            xscalexraw = 0.0

        gyro_x = int(xraw * xscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
                yraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
            yraw = 0.0
        try:
            with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
                yscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
            yscale = 0.0
        gyro_y = int(yraw * yscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
                zraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
            zraw = 0.0
        try:
            with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
                zscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
            zscale = 0.0
        gyro_z = int(zraw * zscalerscale * 256.0 / 9.81)
        return [ gyro_x, gyro_y, gyro_z]

# -------------------------------------------------------------------
# -------------------------------------------------------------------
class MainUIWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Sensor usage")
        #self.set_decorated(False)
        self.maximize()
        self.screen_width = self.get_screen().get_width()
        self.screen_height = self.get_screen().get_height()

        self.set_default_size(self.screen_width, self.screen_height)
        print("[DEBUG] screen size: %dx%d" % (self.screen_width, self.screen_height))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.connect('destroy', Gtk.main_quit)

        # search sensor interface
        self.sensors = Sensors()
        self.sensors.found_all_sensor_path()

        sensor_box = Gtk.VBox(homogeneous=False, spacing=0)

        # temperature
        temp_label = Gtk.Label()
        temp_label.set_markup("<span font_desc='LiberationSans 25'>Temperature</span>")
        self.temp_value_label = Gtk.Label()
        self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- °C</span>")
        temp_box = Gtk.HBox(homogeneous=False, spacing=0)
        temp_box.add(temp_label)
        temp_box.add(self.temp_value_label)
        sensor_box.add(temp_box)

        # humidity
        humidity_label = Gtk.Label()
        humidity_label.set_markup("<span font_desc='LiberationSans 25'>Humidity</span>")
        self.humidity_value_label = Gtk.Label()
        self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- %c</span>" % '%')
        humidity_box = Gtk.HBox(homogeneous=False, spacing=0)
        humidity_box.add(humidity_label)
        humidity_box.add(self.humidity_value_label)
        sensor_box.add(humidity_box)

        # Accel
        accel_label = Gtk.Label()
        accel_label.set_markup("<span font_desc='LiberationSans 25'>Accelerometer</span>")
        self.accel_value_label = Gtk.Label()
        self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
        accel_box = Gtk.HBox(homogeneous=False, spacing=0)
        accel_box.add(accel_label)
        accel_box.add(self.accel_value_label)
        sensor_box.add(accel_box)

        # Gyroscope
        gyro_label = Gtk.Label()
        gyro_label.set_markup("<span font_desc='LiberationSans 25'>Gyroscope</span>")
        self.gyro_value_label = Gtk.Label()
        self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
        gyro_box = Gtk.HBox(homogeneous=False, spacing=0)
        gyro_box.add(gyro_label)
        gyro_box.add(self.gyro_value_label)
        sensor_box.add(gyro_box)

        self.add(sensor_box)

        # Add a timer callback to update
        # this takes 2 args: (how often to update in millisec, the method to run)
        self.timer = GObject.GLib.timeout_add(TIME_UPATE, self.update_ui, None)


      self.timer_enable = True


    def destroy(self, widget, data=None):
        Gtk.main_quit()


    def update_ui(self, user_data):
        if False == self.timer_enable:
            return False;
        # temperature
        temp = self.sensors.temperature_read()
        self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>%.02f °C</span>" % temp)
        # humidity
        hum = self.sensors.humidity_read()
        self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>%.02f %c</span>" % (hum, '%'))
        # accel
        accel = self.sensors.accelerometer_read()
        self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'>[ %.02f, %.02f, %.02f]</span>" % (accel[0], accel[1], accel[2]))
        # gyro
        gyro = self.sensors.gyroscope_read()
        self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'>[ %.02f, %.02f, %.02f]</span>" % (gyro[0], gyro[1], gyro[2]))

        # As this is a timeout function, return True so that it
        # continues to get called
        return True


# -------------------------------------------------------------------
# -------------------------------------------------------------------
# Main
if __name__ == "__main__":
    # add signal to catch CRTL+C
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    win = MainUIWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()

    Gtk.main()

  • Screenshot showing the results in the graphic user interface
Result of Python script
Result of Python script

5.7 More screenshot examples with results displayed in a graphic user interface[edit]

Example of interpreted IMU data
Example of interpreted IMU data


Example of raw IMU data
Example of raw IMU data


Example of sensors data presentation
Example of sensors data presentation


6 References[edit]

  1. IKS01A2 User Manual [1]
  2. 2.02.1 IKS01A2 Schematics [2]
  3. 3.03.1 STM32MP157C-DK2 Schematics [3]


==Article purpose==
The purpose of this article is to explain how to integrate the IKS01A2 expansion board with STM32MP157C-DK2, managed by '''Linux on Cortex<sup>&reg;</sup>-A7'''.<br>


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

This article provides step-by-step instructions to:
* configure Linux software to support IKS01A2 expansion board,
* activate/use several motion MEMS such as HTS221 and LSM6DSL.

==Prerequisites==

===Hardware prerequisites===
* STM32MP157C-DK2
 [[File: STM32MP157C-DK2_angle2.jpg|thumb|upright=2|center|link=|STM32MP157C-DK2]]

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

* IKS01A2 expansion board
[[File:en.x-nucleo-iks01a2_image.jpg|thumb|center|upright=2|alt=IKS01A2|IKS01A2 expansion board]]

===Software prerequisites===
The STM32MP157C-DK2 board must be downloaded with appropriate software in order to support IKS01A2 expansion board. For proceeding, follow the step-by-step instructions provided at [[Getting_started/STM32MP1_boards/STM32MP157x-DK2/Let%27s_start|STM32MP157C-DK2 Let's start]].

==Software customization to support  IKS01A2 expansion board ==
The STM32MP157C-DK2 Linux software must be configured to activate the IKS01A2 board connected on top of the STM32MP157C-DK2 board.<br>


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

===Kernel configuration===
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, type the commands 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|If the above configurations are not enabled, follow the indications given in [[Getting_started/STM32MP1_boards/STM32MP157x-DK2/Develop_on_Arm®_Cortex®-A7/Modify,_rebuild_and_reload_the_Linux®_kernel|Modify, rebuild and reload the Linux® kernel]] }}

===Kernel device tree configuration===

====Hardware / software interface====
The HTS221 and LSM6DSL motion MEMS present on IKS01A2 expansion board are involved in the following use case.<br>

According to IKS01A2 user manual<ref  name="User Manual of IKS01A2"> IKS01A2 User Manual [https://www.st.com/resource/en/user_manual/dm00333132.pdf]</ref>, both motion MEMS are controlled by I<sup>2</sup>C bus.

In the schematics of IKS01A2 <ref name="Schematics of IKS01A2"> IKS01A2 Schematics  [https://www.st.com/resource/en/schematic_pack/x-nucleo-iks01a2_schematic.pdf]</ref> and STM32MP157C-DK2<ref  name="Schematics of STM32MP157C-DK2">STM32MP157C-DK2 Schematics  [https://www.st.com/resource/en/schematic_pack/mb1272-dk2-c01_schematic.pdf]</ref> presented below, the pins that are interconnected are highlighted.

* IKS01A2 schematic (Arduino connector) <ref name="Schematics of IKS01A2"/>

** Pins 10 and 9 of CN5 are used for I<sup>2</sup>C Bus (SDA and SCL) (I2C1 and I2C2 bus instances are mixed via 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).

[[File:Arduino_IKS01A2_schematic.png|thumb|center|800px|alt=Screenshot iks01a2|IKS01A2 schematics extract]]

*STM32MP157C-DK2 schematic (Arduino connector) <ref  name="Schematics of STM32MP157C-DK2"/> 

** Pins 10 and 9 of CN5 are used for I<sup>2</sup>C 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)

[[File:Arduino_stm32mp157c-dk2_schematic.png|thumb|center|800px|alt=Screenshot stm32mp157c-dk2|stm32mp157c-dk2 schematics extract]]

{{Warning|I2C5''' bus instance MUST be enabled by software in order to access the motion MEMS present on IKS01A2}}

====Kernel device tree configuration====
As indicated in previous section, the IKS01A2 expansion board is controlled via I<sup>2</sup>C bus. On STM32MP157C-DK2, the associated I<sup>2</sup>C bus is '''I2C5'''.

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

For that, add following content into '''stm32mp157c-dk2.dts''' file:<pre style="overflow-y: visible; max-height: none;">

 &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>;
	};
 };</pre>

{{Info|To generate a new device tree, please follow the indications given in [[Getting_started/STM32MP1_boards/STM32MP157x-DK2/Develop_on_Arm®_Cortex®-A7/Modify,_rebuild_and_reload_the_Linux®_kernel|Modify, rebuild and reload the Linux® kernel]] }}

===Activate the new configuration in the STM32MP157C-DK2 board===

* '''Prerequisites''': The device tree and the Linux kernel must have been regenerated. If not done yet, follow the indications given in [[Getting_started/STM32MP1_boards/STM32MP157x-DK2/Develop_on_Arm®_Cortex®-A7/Modify,_rebuild_and_reload_the_Linux®_kernel|Modify, rebuild and reload the Linux® kernel]] 

* Add the two generated files in the board file system, 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 stm32mp157c-dk2_extlinux.conf file located in '''/boot/mmc0_stm32mp157c-dk2_extlinux/'''. If the mmc0_<something> directory is not available, add the new entry in '''/boot/mmc0_extlinux/extlinux.conf'''.
<syntaxhighlight lang="c" line highlight="5,18-2121-24"  class="noscroll">

 # Generic Distro Configuration file generated by OpenEmbedded
 menu title Select the boot mode
 MENU BACKGROUND ../splash.bmp
 TIMEOUT 20
 DEFAULT stm32mp157c-dk2-iks01a2
 LABEL stm32mp157c-dk2-sdcard
         KERNEL /uImage
         FDT /stm32mp157c-dk2.dtb
         APPEND root=/dev/mmcblk0p6OpenSTLinux
        KERNEL /uImage
        FDTDIR /
        INITRD /uInitrd
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200 LABEL stm32mp157c-dk2-a7-examples-sdcard
         KERNEL /uImage

        KERNEL /uImageFDT /stm32mp157c-dk2-a7-examples.dtb APPEND root=/dev/mmcblk0p6INITRD /uInitrd
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200 LABEL stm32mp157c-dk2-m4-examples-sdcard
         KERNEL /uImage

        KERNEL /uImageFDT /stm32mp157c-dk2-m4-examples.dtb APPEND root=/dev/mmcblk0p6INITRD /uInitrd
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
 LABEL stm32mp157c-dk2-iks01a2
        KERNEL /uImage
        FDT /stm32mp157c-dk2-iks01a2.dtb
        APPEND root=/dev/mmcblk0p6PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200</syntaxhighlight>


{{Warning| Do not forget to synchronize the file system before rebooting the board <br/> {{Board$}} sync }}

* Reboot the board

===Verify the new configuration on board===
* Verify if '''i2c5''' is enabled:
 {{Board$}}  cat /proc/device-tree/soc/i2c\@40015000/status 
 okay
* Verify if the motion MEMS drivers are declared in the device tree node:

 {{Board$}} ls -l /proc/device-tree/soc/i2c\@40015000/<pre style="overflow-y: visible; max-height: none;">total 0
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 #address-cells
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 #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 compatible4 Feb  7 15:56 clock-frequency

-r--r--r-- 1 root root  6 Dec 19 11:01 dma-names8 Feb  7 15:56 clocks

-r--r--r-- 1 root root 32 Dec 19 11:01 dmas17 Feb  7 15:56 compatible

drwxr-xr-x 2 root root  0 Dec 19 10:54Feb  7 15:51 hts221@5f
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 i2c-scl-falling-time-ns
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 i2c-scl-rising-time-ns
-r--r--r-- 1 root root 19 Dec 19 11:0112 Feb  7 15:56 interrupt-names
-r--r--r-- 1 root root 44 Dec 19 11:0128 Feb  7 15:56 interrupts-extended
drwxr-xr-x 2 root root  0 Dec 19 10:54Feb  7 15:51 lsm6dsl@6b
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 name
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 pinctrl-0
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 pinctrl-1
-r--r--r-- 1 root root 14 Dec 19 11:01Feb  7 15:56 pinctrl-names
-r--r--r-- 1 root root  4 Dec 19 11:01Feb  7 15:56 power-domains
-r--r--r-- 1 root root  8 Dec 19 11:01Feb  7 15:56 reg
-r--r--r-- 1 root root  8 Dec 19 11:01Feb  7 15:56 resets
-r--r--r-- 1 root root 12 Dec 19 11:01Feb  7 15:56 st,syscfg-fmp
-r--r--r-- 1 root root  5 Dec 19 11:01 statusFeb  7 15:56 status
-r--r--r-- 1 root root  0 Feb  7 15:56 wakeup-source</pre>


* 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=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
lsm6dsl
{{Info|If the results are different, check that
# the expansion board is correctly connected 
# all steps, described above, were correctly done.}}

==Read motion MEMS via bash script==
The goal of this section is to read the informations provided by the Linux kernel interface and to process it with a bash script.

=== List of sensor entries ===
The IKS01A2 expansion board provides several MEMS like HTS221, LSM6DSL, LPS22HB.<br>

The list of hardware MEMS detected by Linux via the [[IIO overview|IIO framework]] can be verified in the sysfs.

 {{Board$}} 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
lsm6dsl
This list provides the association between entries and MEMS drivers. In the rest of the article, this list is used a as reference.

===HTS221: Temperature/Humidity===
The HTS221 is a capacitive digital sensor for relative humidity and temperature. 

In this example, '''hts221''' entry is '''/sys/bus/iio/devices/iio:device2device0/'''. In case the user has a different setup, the entry should be adapted accordingly in the scripts provided hereafter.

====Temperature====
* Read IIO entries associated to the temperature for '''HTS221''' driver

 {{Board$}}  cat /sys/bus/iio/devices/iio\:device2device0/in_temp_raw
 {{Board$}}  cat /sys/bus/iio/devices/iio\:device2device0/in_temp_offset
 {{Board$}}  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''':<syntaxhighlight lang="bash" class="noscroll">

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

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

echo "Temperature $temperature"
printf "Temperature %.01f\n" $temperature</syntaxhighlight>
<br/>


* Calculate temperature by shell script: '''auto detection''' of IIO entries
Content of '''hts221_read_temperature_with_entry_detection.sh''':<syntaxhighlight lang="bash" class="noscroll">

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

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

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

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

        break;
    fi
done</syntaxhighlight>


* Test on board
 {{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

====Humidity====
* Read IIO entries associated to humidity for HTS221 driver
 {{Board$}} cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_raw
 {{Board$}} cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_offset
 {{Board$}} 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''':<syntaxhighlight lang="bash" class="noscroll">

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

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

echo "Humidity $humidity"
printf "Humidity %.01f\n" $humidity</syntaxhighlight>



* Calculate humidity  by shell script: '''auto detection''' of IIO entries
Content of '''hts221_read_humidity_with_entry_detection.sh''':<syntaxhighlight lang="bash" class="noscroll">

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

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

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

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

        break;
    fi
done</syntaxhighlight>


* Test on board
 {{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

===LSM6DSL: accelerometer/gyroscope===
The LSM6DSL is an inertial measurement unit (IMU) with ultra-low power and high accuracy, for smartphones and battery operated IoT, gaming, wearables and consumer electronics.<br/>
<br/>

In this example, '''lsm6dsl''' entries are '''/sys/bus/iio/devices/iio:device4device1/''' and '''/sys/bus/iio/devices/iio:device4device2/'''.<br/>

The device4device2 entry is dedicated to accelerometer and the device5device1 one to gyroscope.

====Accelerometer====
* Read IIO entries associated to accelerometer for LSM6DSL driver
 {{Board$}} cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_rawscale

 {{Board$}} cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scaleraw

 {{Board$}} cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw
 {{Board$}} cat /sys/bus/iio/devices/iio\:device4device2/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
z_raw
* 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''':<syntaxhighlight lang="bash" class="noscroll">

#!/bin/shxrawrscale=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_raw`
xscalescale`
xraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scale`
raw`yraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw`yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`
zraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_z_raw`zscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_scale`

printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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


* Calculate accelerometer value by shell script: '''auto detection''' of IIO entries
Content of '''lsm6dsl_accel_read_with_entry_detection.sh''':<syntaxhighlight lang="bash" class="noscroll">

#!/bin/sh
DRIVER_NAME=lsm6dsl_accel       
for d in `ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    thenxrawrscale=`cat $d/in_accel_x_raw`
        xscalescale`
        xraw=`cat $d/in_accel_x_scale`
raw`yraw=`cat $d/in_accel_y_raw`yscale=`cat $d/in_accel_y_scale`
zraw=`cat $d/in_accel_z_raw`
zscale=`cat $d/in_accel_z_scale`
 printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

        printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

        printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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

        break;
    fi
done</syntaxhighlight>


* Test on board
 {{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 ]

====Gyroscope====
* Read IIO entries associated to gyroscope for LSM6DSL driver
 {{Board$}} cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_rawscale

 {{Board$}} cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scaleraw

 {{Board$}} cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw
 {{Board$}} cat /sys/bus/iio/devices/iio\:device5device1/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
z_raw
* 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''':<syntaxhighlight lang="bash" class="noscroll">

#!/bin/shxrawrscale=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_raw`
xscalescale`
xraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scale`
raw`yraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw`yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`
zraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_z_raw`zscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`

printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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

* Calculate gyroscope value by shell script: '''auto detection''' of IIO entries
Content of '''lsm6dsl_gyro_read_with_entry_detection.sh''':<syntaxhighlight lang="bash" class="noscroll">

#!/bin/sh
DRIVER_NAME=lsm6dsl_gyro       
for d in `ls -d1 /sys/bus/iio/devices/*device*`;
do
    if grep -q $DRIVER_NAME $d/name ;
    thenxrawrscale=`cat $d/in_anglvel_x_raw`
        xscalescale`
        xraw=`cat $d/in_anglvel_x_scale`
raw`yraw=`cat $d/in_anglvel_y_raw`yscale=`cat $d/in_anglvel_y_scale`
zraw=`cat $d/in_anglvel_z_raw`
zscale=`cat $d/in_anglvel_z_scale`
 printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

        printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

        printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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

        break;
    fi
done</syntaxhighlight>


* Test on board
 {{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 ]

===BASH: script with all the measurements===
* Content of '''iks01a2.sh'''<syntaxhighlight lang="bash" class="noscroll">

#!/bin/sh
echo "============================="
echo "===       HTS221          ==="
echo "===    (temperature)      ==="
echo "============================="
raw=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_temp_scale`
printf "Value read: raw      %0f\n" $raw
printf "Value read: offset   %0f\n" $offset
printf "Value read: scale    %0f\n" $scale

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

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

echo "============================="
echo "===       HTS221          ==="
echo "===    (humidity)         ==="
echo "============================="
raw=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2device0/in_humidityrelative_scale`
printf "Value read: raw         %0f\n" $raw
printf "Value read: offset      %0f\n" $offset
printf "Value read: scale       %0f\n" $scale

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

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

echo "============================="
echo "===      LSM6DSL          ==="
echo "===    (accelerometer)    ==="
echo "============================="
xrawrscale=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_raw`
xscalescale`
xraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_x_scale`
raw`yraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_y_raw`yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`
zraw=`cat /sys/bus/iio/devices/iio\:device4device2/in_accel_z_raw`zscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_scale`

printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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

echo "============================="
echo "===      LSM6DSL          ==="
echo "===    (gyroscope)        ==="
echo "============================="
xrawxscale=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_raw`
xscalescale`
xraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_x_scale`
raw`yraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_y_raw`yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`
zraw=`cat /sys/bus/iio/devices/iio\:device5device1/in_anglvel_z_raw`zscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`

printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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


* Content of '''iks01a2_with_auto_detection.sh'''<syntaxhighlight lang="bash" class="noscroll">

#!/bin/sh

for d in `ls -d1 /sys/bus/iio/devices/*device*`;
do
    # for hts221: Temperature + Humidity
    if grep -q hts221 $d/name ;
    then
        echo "============================="
        echo "===       HTS221          ==="
        echo "===    (temperature)      ==="
        echo "============================="
        raw=`cat $d/in_temp_raw`
        offset=`cat $d/in_temp_offset`
        scale=`cat $d/in_temp_scale`

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

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

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

        echo "============================="
        echo "===       HTS221          ==="
        echo "===    (humidity)         ==="
        echo "============================="
        raw=`cat $d/in_humidityrelative_raw`
        offset=`cat $d/in_humidityrelative_offset`
        scale=`cat $d/in_humidityrelative_scale`

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

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

        echo "Humidity $humidity"
        printf "Humidity %.02f\n" $humidity
    fi

    # for lsm6dsl: accelerometer
    if grep -q lsm6dsl_accel $d/name ;
    then
        echo "============================="
        echo "===      LSM6DSL          ==="
        echo "===    (accelerometer)    ==="
        echo "============================="xrawrscale=`cat $d/in_accel_x_raw`
        xscalescale`
        xraw=`cat $d/in_accel_x_scale`
raw`yraw=`cat $d/in_accel_y_raw`yscale=`cat $d/in_accel_y_scale`
zraw=`cat $d/in_accel_z_raw`
zscale=`cat $d/in_accel_z_scale`
  printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

        printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

        printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

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

    # for lsm6dsl: gyroscope
    if grep -q lsm6dsl_gyro $d/name ;
    then
        echo "============================="
        echo "===      LSM6DSL          ==="
        echo "===    (gyroscope)        ==="
        echo "============================="xrawrscale=`cat $d/in_anglvel_x_raw`
        xscalescale`
        xraw=`cat $d/in_anglvel_x_scale`
raw`yraw=`cat $d/in_anglvel_y_raw`yscale=`cat $d/in_anglvel_y_scale`
zraw=`cat $d/in_anglvel_z_raw`
zscale=`cat $d/in_anglvel_z_scale`
 printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale$rscale

        printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale$rscale

        printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale$rscale


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

        printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
    fi
done</syntaxhighlight>


==Read motion MEMS via Python script==

The goal of this section is to read the informations provided by Linux kernel interface and process it with a python script.<br/>

The python displays the calculated value through a graphic user interface.

===Display a window with Python and weston/wayland===<syntaxhighlight lang="python" class="noscroll">

#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GdkPixbuf
import cairo

import random
import math
import os
from time import sleep, time

# -------------------------------------------------------------------
# -------------------------------------------------------------------
class MainUIWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Sensor usage")
        #self.set_decorated(False)
        self.maximize()
        self.screen_width = self.get_screen().get_width()
        self.screen_height = self.get_screen().get_height()

        self.set_default_size(self.screen_width, self.screen_height)
        print("[DEBUG] screen size: %dx%d" % (self.screen_width, self.screen_height))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.connect('destroy', Gtk.main_quit)

    def destroy(self, widget, data=None):
        Gtk.main_quit()

# -------------------------------------------------------------------
# -------------------------------------------------------------------
# Main
if __name__ == "__main__":
    # add signal to catch CRTL+C
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    win = MainUIWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()

    Gtk.main()</syntaxhighlight>


===Read temperature===
Part of code for reading temperature with HTS221 driver:<syntaxhighlight lang="python" class="noscroll">

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_temp_raw", "hts221")
try:
    with open(prefix_path + "in_temp_" + 'raw', 'r') as f:
        raw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'raw', exc)
    raw = 0.0

try:
    with open(prefix_path + "in_temp_" + 'scale', 'r') as f:
        scale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'scale', exc)
    scale = 0.0

try:
    with open(prefix_path + "in_temp_" + 'offset', 'r') as f:
        offset = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_temp_" + 'offset', exc)
    offset = 0.0

temp = (offset + raw) * scale
</syntaxhighlight>


===Read humidity===
Part of code for reading humidity with HTS221 driver:<syntaxhighlight lang="python" class="noscroll">

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_humidityrelative_raw", "hts221")
try:
    with open(prefix_path + "in_humidityrelative_" + 'raw', 'r') as f:
        raw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'raw', exc)
    raw = 0.0

try:
    with open(prefix_path + "in_humidityrelative_" + 'scale', 'r') as f:
        scale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'scale', exc)
    scale = 0.0

try:
    with open(prefix_path + "in_humidityrelative_" + 'offset', 'r') as f:
        offset = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'offset', exc)
    offset = 0.0

humidity = (offset + raw) * scale
</syntaxhighlight>


===Read accelerometer===
Part of code for reading accelerometer with LSM6DSL driver:<syntaxhighlight lang="python" class="noscroll">

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_accel_x_raw", "lsm6dsl")
try:
    with open(prefix_path + "in_accel_" + 'x_raw', 'r') as f:
        xraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_raw', exc)
    xraw = 0.0

try:
    with open(prefix_path + "in_accel_" + 'x_scale', 'r') as f:xscalerscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scale', exc)xscalerscale = 0.0
accel_x = int(xraw * xscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
        yraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
    yraw = 0.0
try:
    with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
        yscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
    yscale = 0.0
accel_y = int(yraw * yscaleaccel_y = int(yraw * rscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
        zraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
    zraw = 0.0
try:
    with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
        zscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
    zscale = 0.0
accel_z = int(zraw * zscaleaccel_z = int(zraw * rscale * 256.0 / 9.81)</syntaxhighlight>


===Read gyroscope===
Part of code for reading gyroscope with LSM6DSL driver:<syntaxhighlight lang="python" class="noscroll">

def found_iio_device_with_name(data, name):
    prefix = "/sys/bus/iio/devices/"
    of_name = 'OF_NAME=' + name
    try:
        for filefolder in os.listdir(prefix):
            with open(prefix + '/' + filefolder + '/uevent') as f:
                for line in f:
                    if line.split('\n')[0] == of_name:
                        ''' return directory which contains "data" '''
                        if os.path.exists(prefix + '/' + filefolder + '/' + data):
                            return (prefix + '/' + filefolder + '/')
    except OSError:
        pass
    except Exception as exc:
        pass
    return None

prefix_path = found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")
try:
    with open(prefix_path + "in_anglvel_" + 'x_rawscale', 'r') as f:xrawrscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_rawscale', exc)xrawrscale = 0.0

try:
    with open(prefix_path + "in_anglvel_" + 'x_scaleraw', 'r') as f:xscalexraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scaleraw', exc)xscalexraw = 0.0
gyro_x = int(xraw * xscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
        yraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
    yraw = 0.0
try:
    with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
        yscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
    yscale = 0.0gyro_y = int(yraw * yscalerscale * 256.0 / 9.81)

try:
    with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
        zraw = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
    zraw = 0.0
try:
    with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
        zscale = float(f.read())
except Exception as exc:
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
    zscale = 0.0gyro_z = int(zraw * zscalerscale * 256.0 / 9.81)</syntaxhighlight>


===Full script with information displayed in a graphic user interface===<syntaxhighlight lang="python" class="noscroll">

#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GdkPixbuf
import cairo

import random
import math
import os
from time import sleep, time

# time between each sensor mesearuement (1s)
TIME_UPATE = 2000

class Sensors():
    def __init__(self):
        ''' '''
        self.sensor_dictionnary = {}

    def found_iio_device_with_name(self, data, name):
        prefix = "/sys/bus/iio/devices/"
        of_name = 'OF_NAME=' + name
        try:
            for filefolder in os.listdir(prefix):
                with open(prefix + '/' + filefolder + '/uevent') as f:
                    for line in f:
                        if line.split('\n')[0] == of_name:
                            ''' return directory which contains "data" '''
                            if os.path.exists(prefix + '/' + filefolder + '/' + data):
                                return (prefix + '/' + filefolder + '/')
        except OSError:
            pass
        except Exception as exc:
            pass
        return None

    def found_all_sensor_path(self):
        self.sensor_dictionnary['temperature'] = self.found_iio_device_with_name("in_temp_raw", "hts221")
        self.sensor_dictionnary['humidity']    = self.found_iio_device_with_name("in_humidityrelative_raw", "hts221")
        self.sensor_dictionnary['accelerometer'] = self.found_iio_device_with_name("in_accel_x_raw", "lsm6dsl")
        self.sensor_dictionnary['gyroscope'] = self.found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")

        print("[DEBUG] temperature   -> ", self.sensor_dictionnary['temperature'], "<")
        print("[DEBUG] humidity      -> ", self.sensor_dictionnary['humidity'], "<")
        print("[DEBUG] accelerometer -> ", self.sensor_dictionnary['accelerometer'], "<")
        print("[DEBUG] gyroscope     -> ", self.sensor_dictionnary['gyroscope'], "<")

    def temperature_read(self):
        prefix_path = self.sensor_dictionnary['temperature']
        try:
            with open(prefix_path + "in_temp_" + 'raw', 'r') as f:
                raw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'raw', exc)
            raw = 0.0
        try:
            with open(prefix_path + "in_temp_" + 'scale', 'r') as f:
                scale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'scale', exc)
            scale = 0.0
        try:
            with open(prefix_path + "in_temp_" + 'offset', 'r') as f:
                offset = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_temp_" + 'offset', exc)
            offset = 0.0
        return (offset + raw) * scale

    def humidity_read(self):
        prefix_path = self.sensor_dictionnary['humidity']
        try:
            with open(prefix_path + "in_humidityrelative_" + 'raw', 'r') as f:
                raw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'raw', exc)
            raw = 0.0
        try:
            with open(prefix_path + "in_humidityrelative_" + 'scale', 'r') as f:
                scale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'scale', exc)
            scale = 0.0
        try:
            with open(prefix_path + "in_humidityrelative_" + 'offset', 'r') as f:
                offset = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_humidityrelative_" + 'offset', exc)
            offset = 0.0
        return (offset + raw) * scale

    def accelerometer_read(self):
        prefix_path = self.sensor_dictionnary['accelerometer']
        try:
            with open(prefix_path + "in_accel_" + 'x_rawscale', 'r') as f:xrawrscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_rawscale', exc)xrawrscale = 0.0
 try:
            with open(prefix_path + "in_accel_" + 'x_scaleraw', 'r') as f:xscalexraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scaleraw', exc)xscalexraw = 0.0
 accel_x = int(xraw * xscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
                yraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
            yraw = 0.0
try:
            with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
                yscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
            yscale = 0.0
        accel_y = int(yraw * yscale accel_y = int(yraw * rscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
                zraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
            zraw = 0.0
try:
            with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
                zscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
            zscale = 0.0
        accel_z = int(zraw * zscale accel_z = int(zraw * rscale * 256.0 / 9.81)
        return [ accel_x, accel_y, accel_z]

    def gyroscope_read(self):
        prefix_path = self.sensor_dictionnary['gyroscope']
        try:
            with open(prefix_path + "in_anglvel_" + 'x_rawscale', 'r') as f:xrawrscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_rawscale', exc)xrawrscale = 0.0
        try:
            with open(prefix_path + "in_anglvel_" + 'x_scaleraw', 'r') as f:xscalexraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scaleraw', exc)xscalexraw = 0.0
 gyro_x = int(xraw * xscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
                yraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
            yraw = 0.0try:
            with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
                yscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
            yscale = 0.0gyro_y = int(yraw * yscalerscale * 256.0 / 9.81)
        try:
            with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
                zraw = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
            zraw = 0.0try:
            with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
                zscale = float(f.read())
        except Exception as exc:
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
            zscale = 0.0gyro_z = int(zraw * zscalerscale * 256.0 / 9.81)
        return [ gyro_x, gyro_y, gyro_z]

# -------------------------------------------------------------------
# -------------------------------------------------------------------
class MainUIWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Sensor usage")
        #self.set_decorated(False)
        self.maximize()
        self.screen_width = self.get_screen().get_width()
        self.screen_height = self.get_screen().get_height()

        self.set_default_size(self.screen_width, self.screen_height)
        print("[DEBUG] screen size: %dx%d" % (self.screen_width, self.screen_height))
        self.set_position(Gtk.WindowPosition.CENTER)
        self.connect('destroy', Gtk.main_quit)

        # search sensor interface
        self.sensors = Sensors()
        self.sensors.found_all_sensor_path()

        sensor_box = Gtk.VBox(homogeneous=False, spacing=0)

        # temperature
        temp_label = Gtk.Label()
        temp_label.set_markup("<span font_desc='LiberationSans 25'>Temperature</span>")
        self.temp_value_label = Gtk.Label()
        self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- °C</span>")
        temp_box = Gtk.HBox(homogeneous=False, spacing=0)
        temp_box.add(temp_label)
        temp_box.add(self.temp_value_label)
        sensor_box.add(temp_box)

        # humidity
        humidity_label = Gtk.Label()
        humidity_label.set_markup("<span font_desc='LiberationSans 25'>Humidity</span>")
        self.humidity_value_label = Gtk.Label()
        self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- %c</span>" % '%')
        humidity_box = Gtk.HBox(homogeneous=False, spacing=0)
        humidity_box.add(humidity_label)
        humidity_box.add(self.humidity_value_label)
        sensor_box.add(humidity_box)

        # Accel
        accel_label = Gtk.Label()
        accel_label.set_markup("<span font_desc='LiberationSans 25'>Accelerometer</span>")
        self.accel_value_label = Gtk.Label()
        self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
        accel_box = Gtk.HBox(homogeneous=False, spacing=0)
        accel_box.add(accel_label)
        accel_box.add(self.accel_value_label)
        sensor_box.add(accel_box)

        # Gyroscope
        gyro_label = Gtk.Label()
        gyro_label.set_markup("<span font_desc='LiberationSans 25'>Gyroscope</span>")
        self.gyro_value_label = Gtk.Label()
        self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
        gyro_box = Gtk.HBox(homogeneous=False, spacing=0)
        gyro_box.add(gyro_label)
        gyro_box.add(self.gyro_value_label)
        sensor_box.add(gyro_box)

        self.add(sensor_box)

        # Add a timer callback to update
        # this takes 2 args: (how often to update in millisec, the method to run)self.timer = GObject.GLib.timeout_add(TIME_UPATE, self.update_ui, None)
        self.timer_enable = True
)
def destroy(self, widget, data=None):
        Gtk.main_quit()

    def update_ui(self, user_data):if False == self.timer_enable:
            return False;# temperature
        temp = self.sensors.temperature_read()
        self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>%.02f °C</span>" % temp)
        # humidity
        hum = self.sensors.humidity_read()
        self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>%.02f %c</span>" % (hum, '%'))
        # accel
        accel = self.sensors.accelerometer_read()
        self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'>[ %.02f, %.02f, %.02f]</span>" % (accel[0], accel[1], accel[2]))
        # gyro
        gyro = self.sensors.gyroscope_read()
        self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'>[ %.02f, %.02f, %.02f]</span>" % (gyro[0], gyro[1], gyro[2]))

        # As this is a timeout function, return True so that it
        # continues to get called
        return True

# -------------------------------------------------------------------
# -------------------------------------------------------------------
# Main
if __name__ == "__main__":
    # add signal to catch CRTL+C
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    win = MainUIWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()

    Gtk.main()</syntaxhighlight>


* Screenshot showing the results in the graphic user interface
[[File:iks01a2-stm32mp157c-dk2_sensor_python_basic.png|thumb|center|upright=4|alt=Result of Python script|Result of Python script]]

===More screenshot examples with results displayed in a graphic user interface===
[[File:iks01a2-stm32mp157c-dk2_sensor_python_expert_imu.png|thumb|center|upright=4|alt=Example of interpreted IMU data|Example of interpreted IMU data]]<br/>

[[File:iks01a2-stm32mp157c-dk2_sensor_python_expert_move.png|thumb|center|upright=4|alt=Example of raw IMU data|Example of raw IMU data]]<br/>

[[File:iks01a2-stm32mp157c-dk2_sensor_python_expert_sensor.png|thumb|center|upright=4|alt=Example of sensors data presentation|Example of sensors data presentation]]<br/>


== References==<references />

<noinclude>

[[Category:Expansion boards]]
{{PublicationRequestId | 12269 | 07Jun'19}}</noinclude>
(16 intermediate revisions by the same user not shown)
Line 83: Line 83:
 
<pre style="overflow-y: visible; max-height: none;">
 
<pre style="overflow-y: visible; max-height: none;">
 
  &i2c5 {
 
  &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";
 
status = "okay";
   
Line 117: Line 109:
 
  /boot/stm32mp157c-dk2.dtb
 
  /boot/stm32mp157c-dk2.dtb
   
* Add a new entry in extlinux.conf file located in '''/boot/mmc0_stm32mp157c-dk2_extlinux/'''. If the mmc0_<something> directory is not available, add the new entry in '''/boot/extlinux/extlinux.conf'''.
+
* Add a new entry in stm32mp157c-dk2_extlinux.conf file located in '''/boot/mmc0_extlinux/'''. If the mmc0_<something> directory is not available, add the new entry in '''/boot/mmc0_extlinux/extlinux.conf'''.
   
<syntaxhighlight lang="c" line highlight="5,18-21"  class="noscroll">
+
<syntaxhighlight lang="c" line highlight="5,21-24"  class="noscroll">
 
  # Generic Distro Configuration file generated by OpenEmbedded
 
  # Generic Distro Configuration file generated by OpenEmbedded
 
  menu title Select the boot mode
 
  menu title Select the boot mode
Line 125: Line 117:
 
  TIMEOUT 20
 
  TIMEOUT 20
 
  DEFAULT stm32mp157c-dk2-iks01a2
 
  DEFAULT stm32mp157c-dk2-iks01a2
  LABEL stm32mp157c-dk2-sdcard
+
  LABEL OpenSTLinux
        KERNEL /uImage
+
        KERNEL /uImage
        FDT /stm32mp157c-dk2.dtb
+
        FDTDIR /
        APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
+
        INITRD /uInitrd
LABEL stm32mp157c-dk2-a7-examples-sdcard
+
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
        KERNEL /uImage
+
LABEL stm32mp157c-dk2-a7-examples
        FDT /stm32mp157c-dk2-a7-examples.dtb
+
        KERNEL /uImage
        APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
+
        FDT /stm32mp157c-dk2-a7-examples.dtb
LABEL stm32mp157c-dk2-m4-examples-sdcard
+
        INITRD /uInitrd
        KERNEL /uImage
+
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
        FDT /stm32mp157c-dk2-m4-examples.dtb
+
LABEL stm32mp157c-dk2-m4-examples
        APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
+
        KERNEL /uImage
  +
        FDT /stm32mp157c-dk2-m4-examples.dtb
  +
        INITRD /uInitrd
  +
        APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
 
  LABEL stm32mp157c-dk2-iks01a2
 
  LABEL stm32mp157c-dk2-iks01a2
 
         KERNEL /uImage
 
         KERNEL /uImage
 
         FDT /stm32mp157c-dk2-iks01a2.dtb
 
         FDT /stm32mp157c-dk2-iks01a2.dtb
         APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
+
         APPEND root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582 rootwait rw console=ttySTM0,115200
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Line 157: Line 152:
 
  {{Board$}} ls -l /proc/device-tree/soc/i2c\@40015000/
 
  {{Board$}} ls -l /proc/device-tree/soc/i2c\@40015000/
 
<pre style="overflow-y: visible; max-height: none;">total 0
 
<pre style="overflow-y: visible; max-height: none;">total 0
-r--r--r-- 1 root root  4 Dec 19 11:01 #address-cells
+
-r--r--r-- 1 root root  4 Feb  7 15:56 #address-cells
-r--r--r-- 1 root root  4 Dec 19 11:01 #size-cells
+
-r--r--r-- 1 root root  4 Feb  7 15:56 #size-cells
-r--r--r-- 1 root root  8 Dec 19 11:01 clocks
+
-r--r--r-- 1 root root  4 Feb  7 15:56 clock-frequency
-r--r--r-- 1 root root 15 Dec 19 11:01 compatible
+
-r--r--r-- 1 root root 8 Feb  7 15:56 clocks
-r--r--r-- 1 root root  6 Dec 19 11:01 dma-names
+
-r--r--r-- 1 root root 17 Feb 7 15:56 compatible
-r--r--r-- 1 root root 32 Dec 19 11:01 dmas
+
drwxr-xr-x 2 root root  0 Feb  7 15:51 hts221@5f
drwxr-xr-x 2 root root  0 Dec 19 10:54 hts221@5f
+
-r--r--r-- 1 root root  4 Feb  7 15:56 i2c-scl-falling-time-ns
-r--r--r-- 1 root root  4 Dec 19 11:01 i2c-scl-falling-time-ns
+
-r--r--r-- 1 root root  4 Feb  7 15:56 i2c-scl-rising-time-ns
-r--r--r-- 1 root root  4 Dec 19 11:01 i2c-scl-rising-time-ns
+
-r--r--r-- 1 root root 12 Feb  7 15:56 interrupt-names
-r--r--r-- 1 root root 19 Dec 19 11:01 interrupt-names
+
-r--r--r-- 1 root root 28 Feb  7 15:56 interrupts-extended
-r--r--r-- 1 root root 44 Dec 19 11:01 interrupts-extended
+
drwxr-xr-x 2 root root  0 Feb  7 15:51 lsm6dsl@6b
drwxr-xr-x 2 root root  0 Dec 19 10:54 lsm6dsl@6b
+
-r--r--r-- 1 root root  4 Feb  7 15:56 name
-r--r--r-- 1 root root  4 Dec 19 11:01 name
+
-r--r--r-- 1 root root  4 Feb  7 15:56 pinctrl-0
-r--r--r-- 1 root root  4 Dec 19 11:01 pinctrl-0
+
-r--r--r-- 1 root root  4 Feb  7 15:56 pinctrl-1
-r--r--r-- 1 root root  4 Dec 19 11:01 pinctrl-1
+
-r--r--r-- 1 root root 14 Feb  7 15:56 pinctrl-names
-r--r--r-- 1 root root 14 Dec 19 11:01 pinctrl-names
+
-r--r--r-- 1 root root  4 Feb  7 15:56 power-domains
-r--r--r-- 1 root root  4 Dec 19 11:01 power-domains
+
-r--r--r-- 1 root root  8 Feb  7 15:56 reg
-r--r--r-- 1 root root  8 Dec 19 11:01 reg
+
-r--r--r-- 1 root root  8 Feb  7 15:56 resets
-r--r--r-- 1 root root  8 Dec 19 11:01 resets
+
-r--r--r-- 1 root root 12 Feb  7 15:56 st,syscfg-fmp
-r--r--r-- 1 root root 12 Dec 19 11:01 st,syscfg-fmp
+
-r--r--r-- 1 root root  5 Feb  7 15:56 status
-r--r--r-- 1 root root  5 Dec 19 11:01 status
+
-r--r--r-- 1 root root  0 Feb  7 15:56 wakeup-source
 
</pre>
 
</pre>
   
Line 183: Line 178:
   
 
  {{Board$}}  grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
 
  {{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:device0/uevent:OF_NAME=hts221
  /sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adc
+
  /sys/bus/iio/devices/iio:device1/uevent:OF_NAME=lsm6dsl
  /sys/bus/iio/devices/iio:device2/uevent:OF_NAME=hts221
+
  /sys/bus/iio/devices/iio:device2/uevent:OF_NAME=lsm6dsl
/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|If the results are different, check that
 
{{Info|If the results are different, check that
Line 203: Line 195:
   
 
  {{Board$}} grep OF_NAME /sys/bus/iio/devices/iio\:device*/uevent
 
  {{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:device0/uevent:OF_NAME=hts221
  /sys/bus/iio/devices/iio:device1/uevent:OF_NAME=adc
+
  /sys/bus/iio/devices/iio:device1/uevent:OF_NAME=lsm6dsl
  /sys/bus/iio/devices/iio:device2/uevent:OF_NAME=hts221
+
  /sys/bus/iio/devices/iio:device2/uevent:OF_NAME=lsm6dsl
/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 provides the association between entries and MEMS drivers. In the rest of the article, this list is used a as reference.
 
This list provides the association between entries and MEMS drivers. In the rest of the article, this list is used a as reference.
Line 215: Line 204:
 
The HTS221 is a capacitive digital sensor for relative humidity and temperature.  
 
The HTS221 is a capacitive digital sensor for relative humidity and temperature.  
   
In this example, '''hts221''' entry is '''/sys/bus/iio/devices/iio:device2/'''. In case the user has a different setup, the entry should be adapted accordingly in the scripts provided hereafter.
+
In this example, '''hts221''' entry is '''/sys/bus/iio/devices/iio:device0/'''. In case the user has a different setup, the entry should be adapted accordingly in the scripts provided hereafter.
   
 
====Temperature====
 
====Temperature====
 
* Read IIO entries associated to the temperature for '''HTS221''' driver
 
* 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\:device0/in_temp_raw
  {{Board$}}  cat /sys/bus/iio/devices/iio\:device2/in_temp_offset
+
  {{Board$}}  cat /sys/bus/iio/devices/iio\:device0/in_temp_offset
  {{Board$}}  cat /sys/bus/iio/devices/iio\:device2/in_temp_scale
+
  {{Board$}}  cat /sys/bus/iio/devices/iio\:device0/in_temp_scale
   
 
* Calculate real temperature according with the following formula  
 
* Calculate real temperature according with the following formula  
Line 228: Line 217:
   
 
* Calculate temperature by shell script : '''static''' IIO entries
 
* Calculate temperature by shell script : '''static''' IIO entries
Content of '''hts221_read_temperature_on_device2.sh''':
+
Content of '''hts221_read_temperature_on_device0.sh''':
 
<syntaxhighlight lang="bash" class="noscroll">
 
<syntaxhighlight lang="bash" class="noscroll">
 
#!/bin/sh
 
#!/bin/sh
raw=`cat /sys/bus/iio/devices/iio\:device2/in_temp_raw`
+
raw=`cat /sys/bus/iio/devices/iio\:device0/in_temp_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2/in_temp_offset`
+
offset=`cat /sys/bus/iio/devices/iio\:device0/in_temp_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2/in_temp_scale`
+
scale=`cat /sys/bus/iio/devices/iio\:device0/in_temp_scale`
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: offset      %0f\n" $offset
 
printf "Value read: offset      %0f\n" $offset
Line 273: Line 262:
   
 
* Test on board
 
* Test on board
  {{Board$}}  ./hts221_read_temperature_on_device2.sh
+
  {{Board$}}  ./hts221_read_temperature_on_device0.sh
 
  Value read: raw        563.000000
 
  Value read: raw        563.000000
 
  Value read: offset      1036.674817
 
  Value read: offset      1036.674817
Line 282: Line 271:
 
====Humidity====
 
====Humidity====
 
* Read IIO entries associated to humidity for HTS221 driver
 
* 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\:device0/in_humidityrelative_raw
  {{Board$}} cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_offset
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_offset
  {{Board$}} cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_scale
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_scale
   
 
* Calculate real humidity according with the following formula  
 
* Calculate real humidity according with the following formula  
Line 290: Line 279:
   
 
* Calculate humidity  by shell script: '''static''' IIO entries
 
* Calculate humidity  by shell script: '''static''' IIO entries
Content of '''hts221_read_humidity_on_device2.sh''':
+
Content of '''hts221_read_humidity_on_device0.sh''':
 
<syntaxhighlight lang="bash" class="noscroll">
 
<syntaxhighlight lang="bash" class="noscroll">
 
#!/bin/sh
 
#!/bin/sh
raw=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_raw`
+
raw=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_offset`
+
offset=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_scale`
+
scale=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_scale`
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: offset      %0f\n" $offset
 
printf "Value read: offset      %0f\n" $offset
Line 336: Line 325:
   
 
* Test on board
 
* Test on board
  {{Board$}} ./hts221_read_humidity_on_device2.sh
+
  {{Board$}} ./hts221_read_humidity_on_device0.sh
 
  Value read: raw        2669.000000
 
  Value read: raw        2669.000000
 
  Value read: offset      -10661.500000
 
  Value read: offset      -10661.500000
Line 346: Line 335:
 
The LSM6DSL is an inertial measurement unit (IMU) with ultra-low power and high accuracy, for smartphones and battery operated IoT, gaming, wearables and consumer electronics.<br/>
 
The LSM6DSL is an inertial measurement unit (IMU) with ultra-low power and high accuracy, for smartphones and battery operated IoT, gaming, wearables and consumer electronics.<br/>
 
<br/>
 
<br/>
In this example, '''lsm6dsl''' entries are '''/sys/bus/iio/devices/iio:device4/''' and '''/sys/bus/iio/devices/iio:device4/'''.<br/>
+
In this example, '''lsm6dsl''' entries are '''/sys/bus/iio/devices/iio:device1/''' and '''/sys/bus/iio/devices/iio:device2/'''.<br/>
The device4 entry is dedicated to accelerometer and the device5 one to gyroscope.
+
The device2 entry is dedicated to accelerometer and the device1 one to gyroscope.
   
 
====Accelerometer====
 
====Accelerometer====
 
* Read IIO entries associated to accelerometer for LSM6DSL driver
 
* 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\:device2/in_accel_scale
  {{Board$}} cat /sys/bus/iio/devices/iio\:device4/in_accel_x_scale
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device2/in_accel_x_raw
  {{Board$}} cat /sys/bus/iio/devices/iio\:device4/in_accel_y_raw
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device2/in_accel_y_raw
  {{Board$}} cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device2/in_accel_z_raw
{{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  
 
* Calculate accelerometer values according with the following formula  
Line 364: Line 351:
   
 
* Calculate accelerometer value by shell script: '''static''' IIO entries
 
* Calculate accelerometer value by shell script: '''static''' IIO entries
Content of '''lsm6dsl_accel_read_on_device4.sh''':
+
Content of '''lsm6dsl_accel_read_on_device2.sh''':
 
<syntaxhighlight lang="bash" class="noscroll">
 
<syntaxhighlight lang="bash" class="noscroll">
 
#!/bin/sh
 
#!/bin/sh
xraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_raw`
+
rscale=`cat /sys/bus/iio/devices/iio\:device2/in_accel_scale`
xscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_scale`
+
xraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_x_raw`
  +
yraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_y_raw`
  +
zraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_z_raw`
   
yraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_raw`
+
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`
+
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
 
+
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
zraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_raw`
 
zscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_scale`
 
 
 
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
 
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
 
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
 
   
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 397: Line 380:
 
     if grep -q $DRIVER_NAME $d/name ;
 
     if grep -q $DRIVER_NAME $d/name ;
 
     then
 
     then
  +
        rscale=`cat $d/in_accel_x_scale`
 
         xraw=`cat $d/in_accel_x_raw`
 
         xraw=`cat $d/in_accel_x_raw`
        xscale=`cat $d/in_accel_x_scale`
 
 
 
         yraw=`cat $d/in_accel_y_raw`
 
         yraw=`cat $d/in_accel_y_raw`
        yscale=`cat $d/in_accel_y_scale`
 
 
 
         zraw=`cat $d/in_accel_z_raw`
 
         zraw=`cat $d/in_accel_z_raw`
        zscale=`cat $d/in_accel_z_scale`
 
   
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
         xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
         xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
         yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
         yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
         zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
         zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
         printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
         printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 423: Line 402:
   
 
* Test on board
 
* Test on board
  {{Board$}} ./lsm6dsl_accel_read_on_device4.sh
+
  {{Board$}} ./lsm6dsl_accel_read_on_device2.sh
 
  Value read: X (raw/scale)  104 / 0.000598  
 
  Value read: X (raw/scale)  104 / 0.000598  
 
  Value read: Y (raw/scale)  -16378 / 0.000598  
 
  Value read: Y (raw/scale)  -16378 / 0.000598  
Line 431: Line 410:
 
====Gyroscope====
 
====Gyroscope====
 
* Read IIO entries associated to gyroscope for LSM6DSL driver
 
* 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\:device1/in_anglvel_scale
  {{Board$}} cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_scale
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device1/in_anglvel_x_raw
  {{Board$}} cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_raw
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device1/in_anglvel_y_raw
  {{Board$}} cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale
+
  {{Board$}} cat /sys/bus/iio/devices/iio\:device1/in_anglvel_z_raw
{{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  
 
* Calculate gyroscope values according following formula  
Line 444: Line 421:
   
 
* Calculate gyroscope value by shell script: '''static''' IIO entries
 
* Calculate gyroscope value by shell script: '''static''' IIO entries
Content of '''lsm6dsl_gyro_read_on_device5.sh''':
+
Content of '''lsm6dsl_gyro_read_on_device1.sh''':
 
<syntaxhighlight lang="bash" class="noscroll">
 
<syntaxhighlight lang="bash" class="noscroll">
 
#!/bin/sh
 
#!/bin/sh
xraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_raw`
+
rscale=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_scale`
xscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_scale`
+
xraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_x_raw`
 
+
yraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_y_raw`
yraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_raw`
+
zraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_z_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`
 
 
 
zraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_raw`
 
zscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`
 
   
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 476: Line 449:
 
     if grep -q $DRIVER_NAME $d/name ;
 
     if grep -q $DRIVER_NAME $d/name ;
 
     then
 
     then
  +
        rscale=`cat $d/in_anglvel_scale`
 
         xraw=`cat $d/in_anglvel_x_raw`
 
         xraw=`cat $d/in_anglvel_x_raw`
        xscale=`cat $d/in_anglvel_x_scale`
 
 
 
         yraw=`cat $d/in_anglvel_y_raw`
 
         yraw=`cat $d/in_anglvel_y_raw`
        yscale=`cat $d/in_anglvel_y_scale`
 
 
 
         zraw=`cat $d/in_anglvel_z_raw`
 
         zraw=`cat $d/in_anglvel_z_raw`
        zscale=`cat $d/in_anglvel_z_scale`
 
   
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
         xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
         xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
         yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
         yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
         zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
         zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
         printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
         printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 502: Line 471:
   
 
* Test on board
 
* Test on board
  {{Board$}} ./lsm6dsl_gyro_read_on_device5.sh
+
  {{Board$}} ./lsm6dsl_gyro_read_on_device1.sh
 
  Value read: X (raw/scale)  -2293 / 0.000153  
 
  Value read: X (raw/scale)  -2293 / 0.000153  
 
  Value read: Y (raw/scale)  150 / 0.000153  
 
  Value read: Y (raw/scale)  150 / 0.000153  
Line 516: Line 485:
 
echo "===    (temperature)      ==="
 
echo "===    (temperature)      ==="
 
echo "============================="
 
echo "============================="
raw=`cat /sys/bus/iio/devices/iio\:device2/in_temp_raw`
+
raw=`cat /sys/bus/iio/devices/iio\:device0/in_temp_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2/in_temp_offset`
+
offset=`cat /sys/bus/iio/devices/iio\:device0/in_temp_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2/in_temp_scale`
+
scale=`cat /sys/bus/iio/devices/iio\:device0/in_temp_scale`
 
printf "Value read: raw      %0f\n" $raw
 
printf "Value read: raw      %0f\n" $raw
 
printf "Value read: offset  %0f\n" $offset
 
printf "Value read: offset  %0f\n" $offset
Line 532: Line 501:
 
echo "===    (humidity)        ==="
 
echo "===    (humidity)        ==="
 
echo "============================="
 
echo "============================="
raw=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_raw`
+
raw=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_raw`
offset=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_offset`
+
offset=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_offset`
scale=`cat /sys/bus/iio/devices/iio\:device2/in_humidityrelative_scale`
+
scale=`cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_scale`
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: raw        %0f\n" $raw
 
printf "Value read: offset      %0f\n" $offset
 
printf "Value read: offset      %0f\n" $offset
Line 550: Line 519:
 
echo "============================="
 
echo "============================="
   
xraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_raw`
+
rscale=`cat /sys/bus/iio/devices/iio\:device2/in_accel_scale`
xscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_x_scale`
+
xraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_x_raw`
 
+
yraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_y_raw`
yraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_raw`
+
zraw=`cat /sys/bus/iio/devices/iio\:device2/in_accel_z_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_y_scale`
 
 
 
zraw=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_raw`
 
zscale=`cat /sys/bus/iio/devices/iio\:device4/in_accel_z_scale`
 
   
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 575: Line 540:
 
echo "============================="
 
echo "============================="
   
xraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_raw`
+
xscale=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_scale`
xscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_x_scale`
+
xraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_x_raw`
 
+
yraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_y_raw`
yraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_raw`
+
zraw=`cat /sys/bus/iio/devices/iio\:device1/in_anglvel_z_raw`
yscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_y_scale`
 
 
 
zraw=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_raw`
 
zscale=`cat /sys/bus/iio/devices/iio\:device5/in_anglvel_z_scale`
 
   
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
 
factor=`echo "scale=2;256.0 / 9.81" | bc`
xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 647: Line 608:
 
         echo "===    (accelerometer)    ==="
 
         echo "===    (accelerometer)    ==="
 
         echo "============================="
 
         echo "============================="
  +
        rscale=`cat $d/in_accel_scale`
 
         xraw=`cat $d/in_accel_x_raw`
 
         xraw=`cat $d/in_accel_x_raw`
        xscale=`cat $d/in_accel_x_scale`
 
 
 
         yraw=`cat $d/in_accel_y_raw`
 
         yraw=`cat $d/in_accel_y_raw`
         yscale=`cat $d/in_accel_y_scale`
+
         zraw=`cat $d/in_accel_z_raw`
   
        zraw=`cat $d/in_accel_z_raw`
 
        zscale=`cat $d/in_accel_z_scale`
 
   
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
         xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
         xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
         yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
         yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
         zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
         zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
         printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
         printf "Accelerometer value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 675: Line 633:
 
         echo "===    (gyroscope)        ==="
 
         echo "===    (gyroscope)        ==="
 
         echo "============================="
 
         echo "============================="
  +
        rscale=`cat $d/in_anglvel_scale`
 
         xraw=`cat $d/in_anglvel_x_raw`
 
         xraw=`cat $d/in_anglvel_x_raw`
        xscale=`cat $d/in_anglvel_x_scale`
 
 
 
         yraw=`cat $d/in_anglvel_y_raw`
 
         yraw=`cat $d/in_anglvel_y_raw`
        yscale=`cat $d/in_anglvel_y_scale`
 
 
 
         zraw=`cat $d/in_anglvel_z_raw`
 
         zraw=`cat $d/in_anglvel_z_raw`
        zscale=`cat $d/in_anglvel_z_scale`
 
   
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $xscale
+
         printf "Value read: X (raw/scale)  %d / %.06f \n" $xraw $rscale
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $yscale
+
         printf "Value read: Y (raw/scale)  %d / %.06f \n" $yraw $rscale
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $zscale
+
         printf "Value read: Z (raw/scale)  %d / %.06f \n" $zraw $rscale
   
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
 
         factor=`echo "scale=2;256.0 / 9.81" | bc`
         xval=`echo "scale=2;$xraw*$xscale*$factor" | bc`
+
         xval=`echo "scale=2;$xraw*$rscale*$factor" | bc`
         yval=`echo "scale=2;$yraw*$yscale*$factor" | bc`
+
         yval=`echo "scale=2;$yraw*$rscale*$factor" | bc`
         zval=`echo "scale=2;$zraw*$zscale*$factor" | bc`
+
         zval=`echo "scale=2;$zraw*$rscale*$factor" | bc`
   
 
         printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
 
         printf "Gyroscope value: [ %.02f, %.02f, %.02f ]\n" $xval $yval $zval
Line 873: Line 827:
   
 
try:
 
try:
     with open(prefix_path + "in_accel_" + 'x_scale', 'r') as f:
+
     with open(prefix_path + "in_accel_" + 'scale', 'r') as f:
         xscale = float(f.read())
+
         rscale = float(f.read())
 
except Exception as exc:
 
except Exception as exc:
     print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scale', exc)
+
     print("[ERROR] read %s " % prefix_path + "in_accel_" + 'scale', exc)
     xscale = 0.0
+
     rscale = 0.0
accel_x = int(xraw * xscale * 256.0 / 9.81)
+
accel_x = int(xraw * rscale * 256.0 / 9.81)
   
 
try:
 
try:
Line 887: Line 841:
 
     yraw = 0.0
 
     yraw = 0.0
   
try:
+
accel_y = int(yraw * rscale * 256.0 / 9.81)
    with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
 
        yscale = float(f.read())
 
except Exception as exc:
 
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
 
    yscale = 0.0
 
accel_y = int(yraw * yscale * 256.0 / 9.81)
 
   
 
try:
 
try:
Line 902: Line 850:
 
     zraw = 0.0
 
     zraw = 0.0
   
try:
+
accel_z = int(zraw * rscale * 256.0 / 9.81)
    with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
 
        zscale = float(f.read())
 
except Exception as exc:
 
    print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
 
    zscale = 0.0
 
accel_z = int(zraw * zscale * 256.0 / 9.81)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Line 932: Line 874:
   
 
prefix_path = found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")
 
prefix_path = found_iio_device_with_name("in_anglvel_x_raw", "lsm6dsl")
  +
try:
  +
    with open(prefix_path + "in_anglvel_" + 'scale', 'r') as f:
  +
        rscale = float(f.read())
  +
except Exception as exc:
  +
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'scale', exc)
  +
    rscale = 0.0
  +
 
try:
 
try:
 
     with open(prefix_path + "in_anglvel_" + 'x_raw', 'r') as f:
 
     with open(prefix_path + "in_anglvel_" + 'x_raw', 'r') as f:
Line 939: Line 888:
 
     xraw = 0.0
 
     xraw = 0.0
   
try:
+
gyro_x = int(xraw * rscale * 256.0 / 9.81)
    with open(prefix_path + "in_anglvel_" + 'x_scale', 'r') as f:
 
        xscale = float(f.read())
 
except Exception as exc:
 
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scale', exc)
 
    xscale = 0.0
 
gyro_x = int(xraw * xscale * 256.0 / 9.81)
 
   
 
try:
 
try:
Line 954: Line 897:
 
     yraw = 0.0
 
     yraw = 0.0
   
try:
+
gyro_y = int(yraw * rscale * 256.0 / 9.81)
    with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
 
        yscale = float(f.read())
 
except Exception as exc:
 
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
 
    yscale = 0.0
 
gyro_y = int(yraw * yscale * 256.0 / 9.81)
 
   
 
try:
 
try:
Line 969: Line 906:
 
     zraw = 0.0
 
     zraw = 0.0
   
try:
+
gyro_z = int(zraw * rscale * 256.0 / 9.81)
    with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
 
        zscale = float(f.read())
 
except Exception as exc:
 
    print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
 
    zscale = 0.0
 
gyro_z = int(zraw * zscale * 256.0 / 9.81)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
   
Line 1,078: Line 1,009:
 
     def accelerometer_read(self):
 
     def accelerometer_read(self):
 
         prefix_path = self.sensor_dictionnary['accelerometer']
 
         prefix_path = self.sensor_dictionnary['accelerometer']
  +
        try:
  +
            with open(prefix_path + "in_accel_" + 'scale', 'r') as f:
  +
                rscale = float(f.read())
  +
        except Exception as exc:
  +
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'scale', exc)
  +
            rscale = 0.0
  +
 
         try:
 
         try:
 
             with open(prefix_path + "in_accel_" + 'x_raw', 'r') as f:
 
             with open(prefix_path + "in_accel_" + 'x_raw', 'r') as f:
Line 1,084: Line 1,022:
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_raw', exc)
 
             xraw = 0.0
 
             xraw = 0.0
        try:
+
 
            with open(prefix_path + "in_accel_" + 'x_scale', 'r') as f:
+
         accel_x = int(xraw * rscale * 256.0 / 9.81)
                xscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'x_scale', exc)
 
            xscale = 0.0
 
         accel_x = int(xraw * xscale * 256.0 / 9.81)
 
 
         try:
 
         try:
 
             with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
 
             with open(prefix_path + "in_accel_" + 'y_raw', 'r') as f:
Line 1,097: Line 1,030:
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_raw', exc)
 
             yraw = 0.0
 
             yraw = 0.0
        try:
+
 
            with open(prefix_path + "in_accel_" + 'y_scale', 'r') as f:
+
         accel_y = int(yraw * rscale * 256.0 / 9.81)
                yscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'y_scale', exc)
 
            yscale = 0.0
 
         accel_y = int(yraw * yscale * 256.0 / 9.81)
 
 
         try:
 
         try:
 
             with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
 
             with open(prefix_path + "in_accel_" + 'z_raw', 'r') as f:
Line 1,110: Line 1,038:
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_raw', exc)
 
             zraw = 0.0
 
             zraw = 0.0
        try:
+
 
            with open(prefix_path + "in_accel_" + 'z_scale', 'r') as f:
+
         accel_z = int(zraw * rscale * 256.0 / 9.81)
                zscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_accel_" + 'z_scale', exc)
 
            zscale = 0.0
 
         accel_z = int(zraw * zscale * 256.0 / 9.81)
 
 
         return [ accel_x, accel_y, accel_z]
 
         return [ accel_x, accel_y, accel_z]
   
 
     def gyroscope_read(self):
 
     def gyroscope_read(self):
 
         prefix_path = self.sensor_dictionnary['gyroscope']
 
         prefix_path = self.sensor_dictionnary['gyroscope']
  +
        try:
  +
            with open(prefix_path + "in_anglvel_" + 'scale', 'r') as f:
  +
                rscale = float(f.read())
  +
        except Exception as exc:
  +
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'scale', exc)
  +
            rscale = 0.0
 
         try:
 
         try:
 
             with open(prefix_path + "in_anglvel_" + 'x_raw', 'r') as f:
 
             with open(prefix_path + "in_anglvel_" + 'x_raw', 'r') as f:
Line 1,127: Line 1,056:
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_raw', exc)
 
             xraw = 0.0
 
             xraw = 0.0
        try:
+
 
            with open(prefix_path + "in_anglvel_" + 'x_scale', 'r') as f:
+
         gyro_x = int(xraw * rscale * 256.0 / 9.81)
                xscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'x_scale', exc)
 
            xscale = 0.0
 
         gyro_x = int(xraw * xscale * 256.0 / 9.81)
 
 
         try:
 
         try:
 
             with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
 
             with open(prefix_path + "in_anglvel_" + 'y_raw', 'r') as f:
Line 1,140: Line 1,064:
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_raw', exc)
 
             yraw = 0.0
 
             yraw = 0.0
        try:
+
         gyro_y = int(yraw * rscale * 256.0 / 9.81)
            with open(prefix_path + "in_anglvel_" + 'y_scale', 'r') as f:
 
                yscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'y_scale', exc)
 
            yscale = 0.0
 
         gyro_y = int(yraw * yscale * 256.0 / 9.81)
 
 
         try:
 
         try:
 
             with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
 
             with open(prefix_path + "in_anglvel_" + 'z_raw', 'r') as f:
Line 1,153: Line 1,071:
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
 
             print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_raw', exc)
 
             zraw = 0.0
 
             zraw = 0.0
        try:
+
         gyro_z = int(zraw * rscale * 256.0 / 9.81)
            with open(prefix_path + "in_anglvel_" + 'z_scale', 'r') as f:
 
                zscale = float(f.read())
 
        except Exception as exc:
 
            print("[ERROR] read %s " % prefix_path + "in_anglvel_" + 'z_scale', exc)
 
            zscale = 0.0
 
         gyro_z = int(zraw * zscale * 256.0 / 9.81)
 
 
         return [ gyro_x, gyro_y, gyro_z]
 
         return [ gyro_x, gyro_y, gyro_z]
   
Line 1,181: Line 1,093:
 
         self.sensors.found_all_sensor_path()
 
         self.sensors.found_all_sensor_path()
   
         sensor_box = Gtk.VBox(spacing=0)
+
         sensor_box = Gtk.VBox(homogeneous=False, spacing=0)
   
 
         # temperature
 
         # temperature
Line 1,188: Line 1,100:
 
         self.temp_value_label = Gtk.Label()
 
         self.temp_value_label = Gtk.Label()
 
         self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- °C</span>")
 
         self.temp_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- °C</span>")
         temp_box = Gtk.HBox(False, 0)
+
         temp_box = Gtk.HBox(homogeneous=False, spacing=0)
 
         temp_box.add(temp_label)
 
         temp_box.add(temp_label)
 
         temp_box.add(self.temp_value_label)
 
         temp_box.add(self.temp_value_label)
Line 1,198: Line 1,110:
 
         self.humidity_value_label = Gtk.Label()
 
         self.humidity_value_label = Gtk.Label()
 
         self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- %c</span>" % '%')
 
         self.humidity_value_label.set_markup("<span font_desc='LiberationSans 25'>--.-- %c</span>" % '%')
         humidity_box = Gtk.HBox(False, 0)
+
         humidity_box = Gtk.HBox(homogeneous=False, spacing=0)
 
         humidity_box.add(humidity_label)
 
         humidity_box.add(humidity_label)
 
         humidity_box.add(self.humidity_value_label)
 
         humidity_box.add(self.humidity_value_label)
Line 1,208: Line 1,120:
 
         self.accel_value_label = Gtk.Label()
 
         self.accel_value_label = Gtk.Label()
 
         self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
 
         self.accel_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
         accel_box = Gtk.HBox(False, 0)
+
         accel_box = Gtk.HBox(homogeneous=False, spacing=0)
 
         accel_box.add(accel_label)
 
         accel_box.add(accel_label)
 
         accel_box.add(self.accel_value_label)
 
         accel_box.add(self.accel_value_label)
Line 1,218: Line 1,130:
 
         self.gyro_value_label = Gtk.Label()
 
         self.gyro_value_label = Gtk.Label()
 
         self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
 
         self.gyro_value_label.set_markup("<span font_desc='LiberationSans 25'> [ --.--, --.--, --.--]</span>")
         gyro_box = Gtk.HBox(False, 0)
+
         gyro_box = Gtk.HBox(homogeneous=False, spacing=0)
 
         gyro_box.add(gyro_label)
 
         gyro_box.add(gyro_label)
 
         gyro_box.add(self.gyro_value_label)
 
         gyro_box.add(self.gyro_value_label)
Line 1,227: Line 1,139:
 
         # Add a timer callback to update
 
         # Add a timer callback to update
 
         # this takes 2 args: (how often to update in millisec, the method to run)
 
         # this takes 2 args: (how often to update in millisec, the method to run)
         self.timer = GObject.timeout_add(TIME_UPATE, self.update_ui, None)
+
         GLib.timeout_add(TIME_UPATE, self.update_ui)
        self.timer_enable = True
 
   
   
Line 1,236: Line 1,147:
   
 
     def update_ui(self, user_data):
 
     def update_ui(self, user_data):
        if False == self.timer_enable:
 
            return False;
 
 
         # temperature
 
         # temperature
 
         temp = self.sensors.temperature_read()
 
         temp = self.sensors.temperature_read()