Introduction

Documentation Status Discord Build Status

CircuitPython module for use with the SI7021 Temperature and Humidity Sensor.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-si7021

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-si7021

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-si7021

Usage Notes

Of course, you must import the library to use it:

import adafruit_si7021

This driver takes an instantiated and active I2C object (from the busio or the bitbangio library) as an argument to its constructor. The way to create an I2C object depends on the board you are using. For boards with labeled SCL and SDA pins, you can:

from busio import I2C
from board import SCL, SDA

i2c = I2C(SCL, SDA)

Once you have created the I2C interface object, you can use it to instantiate the sensor object:

sensor = adafruit_si7021.SI7021(i2c)

And then you can start measuring the temperature and humidity:

print(sensor.temperature)
print(sensor.relative_humidity)

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/si7021_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
"""
Initializes the sensor, gets and prints readings every two seconds.
"""
import time
import board
import adafruit_si7021

# Create library object using our Bus I2C port
sensor = adafruit_si7021.SI7021(board.I2C())

while True:
    print("\nTemperature: %0.1f C" % sensor.temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    time.sleep(2)

adafruit_si7021

This is a CircuitPython driver for the SI7021 temperature and humidity sensor.

  • Author(s): Radomir Dopieralski

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_si7021.SI7021(i2c_bus, address=64)[source]

A driver for the SI7021 temperature and humidity sensor.

Parameters:
  • i2c_bus – The busio.I2C object to use. This is the only required parameter.
  • address (int) – (optional) The I2C address of the device.
relative_humidity

The measured relative humidity in percent.

start_measurement(what)[source]

Starts a measurement.

Starts a measurement of either HUMIDITY or TEMPERATURE depending on the what argument. Returns immediately, and the result of the measurement can be retrieved with the temperature and relative_humidity properties. This way it will take much less time.

This can be useful if you want to start the measurement, but don’t want the call to block until the measurement is ready – for instance, when you are doing other things at the same time.

temperature

The measured temperature in degrees Celcius.

Indices and tables