Getting HTU21 Temperature/Humidity Sensor to work with Pi 1/2/3/Zero

enable i2s

  • sudo raspi-config
  • Advanced Settings > Enable I2C

or run the commands below

  • sudo sed -i 's/#dtparam=i2s-arm=on/dtparam=i2s-arm=on/g' /boot/config.txt
  • sudo sed -i 's/#dtparam=i2s=on/dtparam=i2s=on/g' /boot/config.txt

install i2c tools

  • sudo apt-get install i2c-tools python-smbus -y
  • sudo i2cdetect -y 1 (see if you can spot the connection, mine said 40)

install the pigpio libary

  • wget abyz.co.uk/rpi/pigpio/pigpio.zip
  • unzip pigpio.zip && cd PIGPIO
  • make && sudo make install
  • sudo pigpiod

get the pi code

  • git clone https://github.com/dalexgray/RaspberryPI_HTU21DF.git && cd RaspberryPI_HTU21DF
  • sudo python HTU21DF.py install

test it

  • python HTU21DF_test.py

https://github.com/dalexgray/RaspberryPI_HTU21DF