Pi IoT In C Using Linux Drivers - Hwmon
Written by Harry Fairhead   
Monday, 21 June 2021
Article Index
Pi IoT In C Using Linux Drivers - Hwmon
HWMON
Working!

As well as raw bus drivers there are also many direct device drivers which hide the details of how the devices are interfaced. Many of these conform to either the IIO or Hwmon approach. In this extract from my recent book on Linux drivers the focus is on Hwmon - the oldest of the approaches.

Raspberry Pi IoT In C Using Linux Drivers

By Harry Fairhead

Cdrivers360

Buy from Amazon.

Contents

  1.  Choosing A Pi For IoT

  2. C and Visual Studio Code

  3.  Drivers: A First Program

  4.  The GPIO Character Driver
         Extract: GPIO Character Driver

  5. GPIO Using I/O Control

  6.  GPIO Events

  7.  The Device Tree
        Extract: The DHT22

  8.  Some Electronics

  9.  Pulse Width Modulation
    Extract:  The PWM Driver 

  10. SPI Devices
    Extract: The SPI Driver 

  11. I2C Basics

  12. The I2C Linux Driver

  13. Advanced I2C

  14. Sensor Drivers – Linux IIO & Hwmon
      Extract: Hwmon  

  15. 1-Wire Bus
      Extract: 1-Wire And The DS18B20 ***NEW!

  16. Going Further With Drivers

  17. Appendix I

 <ASIN:1871962641>

<ASIN:B08W9V7TP9>

Sensor Drivers – Linux IIO & Hwmon

As well as supporting the I2C bus in a general way, there are also a number of I2C device drivers. These allow you to use I2C devices without worrying about the exact nature of the protocol in use. Some of these device drivers conform to either one or other of a broader, protocol-independent way of implementing drivers – hwmon, relating to the hardware monitoring system and iio, for interfacing Linux Industrial I/O devices. These form a framework for creating, publishing and using drivers for devices irrespective of the protocol used to control them. As you can see in the table below the majority are I2C devices.

At the time of writing the following devices are supported:

bme680

I2C or SPI

iio

Bosch Sensortronic BME680 Temperature, Humidity and Pressure Sensor

bmp085

I2C or SPI

iio

Bosch Sensortronic BMP085 superseded by the BMP180

bmp180

I2C

iio

Bosch Sensortronic BMP180 Barometric Pressure Sensor

bme280

I2C

iio

Bosch Sensortronic BME280 Temperature, Humidity and Pressure Sensor

ds1621

I2C

hwmon

Dallas Semiconductors Temperature Sensor range including DS1621, DS1625, DS1631, DS1721 and DS1731

hdc100x

I2C

iio

Texas Instruments HDC100x Temperature Sensor range -only HDC1010 and HDC1080 are current

htu21

SPI

iio

HTU21 Temperature and Humidity Sensor

lm75

I2C

hwmon

Maxim LM75 Temperature Sensor and compatible devices.

max17040

I2C

hwmon

Maxim Integrated MAX17040 Battery Monitor

sht3x

I2C

hwmon

Sensiron SHT3x Temperature and Humidity Sensor

Si7020

I2C

hwmon

Silicon Labs Si7013/20/21 Humidity/Temperature Sensor

sps30

I2C

iio

Sensirion SPS30 Particulate Matter Sensor

tmp102

I2C

hwmon

Texas Instruments TMP102 Temperature Sensor

tsl4531

I2C

iio

AMS TSL4531 Digital Ambient Light Sensor

veml6070

I2C

iio

Vishay VEML6070 Ultraviolet Light Sensor


There are many more devices available as drivers that you have to build and install for yourself, but these are usually provided by the manufacturer of the device and you will find instructions on the relevant websites.

The majority of these devices are available at reasonable cost in either prototype-friendly DIL packages or as breakout boards. Of course, there are many sensors that are not supported by a Linux driver, but making a choice from this list can save you a lot of time and trouble.

Some of the above device drivers are part of the Industrial I/O (IIO) subsystem project and some are part of the older hwmon subsystem. The hwmon subsystem is intended to be a way of reading and configuring sensors and devices that are built into the system. For example, you can read the CPU temperature or the supply voltage of the Pi using the built-in sensors that are part of hwmon. However, you can also add drivers to the hwmon subsystem that aren’t built in. This use of hwmon as a “home” for sensors is what led to the decision to create IIO as a better and more appropriate place for sensors.

There are some big differences between hwmon and IIO. In particular IIO only deals with input devices and, in principle, it can do so in much more sophisticated ways than hwmon. Hwmon has the advantage of dealing with input and output devices, but it is much simpler. Let’s start with hwmon and see the general principles in action.



Last Updated ( Monday, 21 June 2021 )