mgaggero / Adafruit_Python_HTU21D

Python Library for the Adafruit HTU21D-F Humidity/Temperature sensor breakout board
MIT License
11 stars 1 forks source link

Adafruit_Python_HTU21D

Python Library for the Adafruit HTU21D-F Humidity/Temperature sensor breakout board.

Partially based on the code of the Adafruit_Python_BMP library written by Tony DiCola for Adafruit Industries.

Warning:

Currently supported platforms

Board Options
Raspberry PI 1 Model B busnum=0
Raspberry PI 2 Model B busnum default or 1
Raspberry PI 3 Model B busnum default or 1

Installation

Setuptools

The following commands install HTU21D library system wide:

git clone https://github.com/mgaggero/Adafruit_Python_HTU21D.git
cd Adafruit_Python_HTU21D
sudo python setup.py install

In order to install the library on the user's home directory, a local installation that not requires sudo/root privileges, the last command should be:

python setup.py install --user

And the library will be installed in the folder

$HOME/.local/lib/python3.6/site-packages/

Pip

The following commands install HTU21D library system wide:

git clone https://github.com/mgaggero/Adafruit_Python_HTU21D.git
cd Adafruit_Python_HTU21D
sudo pip install .

In order to install the library on the user's home directory, a local installation that not requires sudo/root privileges, the last command should be:

pip install . --user

And the library will be installed in the folder

$HOME/.local/lib/python3.6/site-packages/

Permissions and privileges

Accessing I2C devices usually requires root privileges or privileged group membership. These can be obtained with:

Creation of the 'i2c' group

sudo groupadd -r i2c        # creates the 'i2c' group as a 'system' group
sudo chgrp i2c /dev/i2c*    # changes group ownership of the i2c device files
sudo chmod g+rw /dev/i2c*   # allow owning group to read/write to the devices
sudo usermod -aG i2c $USER  # add the current user to the 'i2c' group

Logout and re-login.

Usage

>>> from Adafruit_HTU21D.HTU21D import HTU21D

>>> h = HTU21D()

>>> h.read_temperature()
24.117971191406248

>>> h.read_humidity()
35.1224365234375

>>> h.read_dewpoint()
7.783974941964999

>>> h.reset()

Troubleshooting

ArchLinux

Before reporting any bugs or issues, make sure that: