Pressure Sensor Tutorial


The access of the pressure sensor can be done using the iio dev nodes that are created by the driver.

Here we will show you a simple way to extract data from the device node.

To discover the iio device you need to first list the directory contents of all iio nodes:

root@beaglebone:~# ls -l /sys/bus/iio/devices/
 total 0
 lrwxrwxrwx 1 root root 0 Dec 8 18:23 iio:device0 -> ../../../devices/platform/ocp/44e0b000.i2c/i2c-0/0-0068/iio:device0
 lrwxrwxrwx 1 root root 0 Dec 8 18:23 iio:device1 -> ../../../devices/platform/ocp/44e0b000.i2c/i2c-0/0-005c/iio:device1
 lrwxrwxrwx 1 root root 0 Dec 8 18:23 trigger0 -> ../../../devices/platform/ocp/44e0b000.i2c/i2c-0/0-0068/trigger0
 lrwxrwxrwx 1 root root 0 Dec 8 18:23 trigger1 -> ../../../devices/platform/ocp/44e0b000.i2c/i2c-0/0-005c/trigger1

As you can see we have 2 iio devices 0 and 1.  Inspect the contents of the folders to see what the devices are.  e.g.:

root@beaglebone:~# ls -l /sys/bus/iio/devices/iio\:device1/

For the ST pressure sensor we need the following contents :

drwxr-xr-x 2 root root 0 Dec 8 18:24 buffer
-r--r--r-- 1 root root 4096 Dec 8 18:24 dev
-rw-r--r-- 1 root root 4096 Dec 8 18:24 in_pressure_raw
-rw-r--r-- 1 root root 4096 Dec 8 18:24 in_pressure_scale
-rw-r--r-- 1 root root 4096 Dec 8 18:24 in_temp_offset
-rw-r--r-- 1 root root 4096 Dec 8 18:24 in_temp_raw
-rw-r--r-- 1 root root 4096 Dec 8 18:24 in_temp_scale
-r--r--r-- 1 root root 4096 Dec 8 18:24 name
lrwxrwxrwx 1 root root 0 Dec 8 18:24 of_node -> ../../../../../../../firmware/devicetree/base/ocp/i2c@44e0b000/lps331ap@5C
drwxr-xr-x 2 root root 0 Dec 8 18:24 power
-r--r--r-- 1 root root 4096 Dec 8 18:24 sampling_frequency_available
drwxr-xr-x 2 root root 0 Dec 8 18:24 scan_elements
lrwxrwxrwx 1 root root 0 Dec 8 18:23 subsystem -> ../../../../../../../bus/iio
drwxr-xr-x 2 root root 0 Dec 8 18:24 trigger
-rw-r--r-- 1 root root 4096 Dec 8 18:23 uevent

Check that we have the correct device by querying the name:

root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/name
lps331ap

Pressure

If we need to know the current pressure we can simply cat the dev node to extract the reading:

root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/in_pressure_raw
4144784
root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/in_pressure_scale
0.000024414

Reading the datasheet for the scaling it is the following calculation:

(in_pressure_raw * in_pressure_scale)*10 = mb

(4144784 * 0.000024414) *10 = 1011.90756576 mb

 

Temperature

If we need to know the current temperature we can simply cat the dev node to extract the reading:

root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/in_temp_offset
42.500000000
root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/in_temp_raw
-1621
root@beaglebone:~# cat /sys/bus/iio/devices/iio\:device1/in_temp_scale
0.002083333

Reading the datasheet for the scaling it is the following calculation:

in_temp_offset+(in_temp_raw * in_temp_scale) = degC

42.500000000 + ( -1621 * 0.002083333 ) = 39.122917207 deg C

Don’t forget that the measured temperature will be of the sensor on the board, so if you have it in an enclosed case and the processor loaded it will read high temperatures.