Main Content

readHumidity

Read one relative humidity data sample from HTS221 sensor

Description

example

[humidityReading,timestamp] = readHumidity(sensor) returns one sample of the relative humidity data from the HTS221 sensor. The relative humidity sample is returned as a scalar in percentage. The function also returns the timestamp at which MATLAB® receives the relative humidity data from the HTS221 sensor. The timestamp output is optional.

Examples

collapse all

Read the relative humidity data from the HTS221 sensor.

Create a connection from MATLAB to the Raspberry Pi™ hardware board.

mypi = raspi;
mypi = 

  Raspi with Properties:

           DeviceAddress: 'raspberrypi-hysdu8X38o'
                    Port: 18734
               BoardName: 'Raspberry Pi 3 Model B+'
           AvailableLEDs: {'led0'}
    AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
    AvailableSPIChannels: {‘CE0’,’CE1’}
       AvailableI2CBuses: {'i2c-1'}
             I2CBusSpeed: 100000
        AvailabelWebCams: mmal service 16.1 (platform:bcm2835-v4l2)

Create an hts221 sensor object on the I2C bus 'i2c-1' on address '0x5F'.

sensor = hts221(mypi,'Bus','i2c-1');
sensor = 

  hts221 with properties:

                         I2CAddress: 95 ("0x5F")
                                Bus: i2c-1

Return one sample of relative humidity data read from the HTS221 sensor.

[humidityReading,timestamp] = readHumidity(sensor);
humidityReading =

  data

    69.6689

timestamp = 

  datetime

   22-Dec-2020 17:23:34.694

Since the timestamp output is optional, you can obtain only the relative humidity data from the HTS221 sensor.

[humidityReading] = readHumidity(sensor);
humidityReading =

  data

    69.6689

Input Arguments

collapse all

HTS221 sensor object connection to the Raspberry Pi hardware board, specified as a hts221 object.

Example: sensor = hts221(mypi) creates a connection to the HTS221 sensor on the Raspberry Pi object mypi.

Output Arguments

collapse all

Read the relative humidity data from the HTS221 sensor.

Read the date and time at which MATLAB receives the relative humidity sample value from the HTS221 sensor, specified as a datetime.

Extended Capabilities

Introduced in R2021a