Environment sensors

DHT22 temperature & humidity sensor

BMP280 barometric pressure sensor

Pressure conversion

Sensor reports the Absolute Barometric Pressure, for comparison, Equivalent Sea Level Barometric Pressure should be used.

P0 = P * (1 - 0.0065h / (T + 0.0065h + 273.15))^-5.257

HC-SR501 PIR motion detector

GL55 serie LDR light sensor

Usage (Linux / Raspberry Pi)

I2C interface

I2C interface must be enabled to use BMP280

sudo raspi-config
> Interfacing Options
> I2C > Enable/Disable automatic loading of I2C kernel module

Raw I2C access:

# Adds i2c tools
sudo apt install i2c-tools

# to list i2c buses
i2cdetect -l
i2c-1 i2c         bcm2835 I2C adapter               I2C adapter

# to detect i2c devices
i2cdetect -y 1
# BMP280, by default, uses adress 0x76

# read Chip Id (BMP280 should return 0x58, BME280 is 0x60)
i2cget -y 1 0x76 0xd0

BMP280 linux device driver

BMP280 can be enabled via device tree

sudo vim.tiny /boot/config.txt
# BMP280 pressure/temp sensor
dtoverlay=i2c-sensor,bmp280

Then, values can be read from sysfs:

cat /sys/bus/iio/devices/iio\:device0/in_pressure_input
98.660992187
cat /sys/bus/iio/devices/iio\:device0/in_temp_input
20630

Interpretation:

DHT22 Linux device driver

To build and use DHT22 driver:

# Download sources:
cd Documents
git clone https://github.com/edwardlintw/DHT22 dht22-kmod
cd dht22-kmod

# Patch sources:
patch -p1 < /media/tognoli.fr/howto/mcu/dht22.patch
# wget https://bertrand.tognoli.fr/howto/mcu/dht22.patch
# patch -p1 < dht22.patch

# To build:
make

# Trigger a measure:
echo 1 > /sys/kernel/dht22/trigger
# Read temperature:
cat /sys/kernel/dht22/temperature

INA219 current sensor

Linux device driver

Driver is included in Linux kernel:

Raspberry Pi Device Tree support

INA2xx is not included by default in Raspberry Pi DT

ina219-overlay.dts
/ Definitions for I2C based current sensor INA219
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target = <&i2c_arm>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;

                        ina219@40 {
                                status = "okay";
                                compatible = "ti,ina219";
                                reg = <0x40>;
                                shunt-resistor = <100000>;  // R100
                        };
                };
        };
};

Overlay need to be compiled and installed:

dtc -@ -I dts -O dtb -o ina219.dtbo ina219-overlay.dts
sudo cp ina219.dtbo /boot/overlays/
echo "dtoverlay=ina219" | sudo tee -a /boot/config.txt
28-Sep-2020