Measuring temperature and humidity with a digital sensor
The
upm
library includes support for the digital temperature and humidity breakout board that uses the TH02 sensor in the pyupm_th02
module. The TH02
class declared in this module represents a digital temperature and humidity sensor that uses the TH02 sensor, connected to our board. The class makes it easy to initialize the sensor and retrieve the temperature and humidity values through the I2C bus. The class works with the mraa.I2c
class under the hoods to talk with the sensor, that is, to write data to and read data from the TH02 sensor that acts as a slave device connected to the I2C bus.
We will create a new TemperatureAndHumiditySensor
class to represent the temperature and humidity sensor and make it easier for us to retrieve the temperature and humidity values in the appropriate units working with an instance of the TH02
class. We will use the TH02
class to interact with the sensor. The following lines show the code for the...