upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for sht1x.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "sht1x.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a SHT1X sensor using D2 as the clock, and D3 as the
// data pin.
sht1x_context sensor = sht1x_init(2, 3);
if (!sensor)
{
printf("sht1x_init() failed.\n");
return 1;
}
// Every 2 seconds, update and print values
while (shouldRun)
{
if (sht1x_update(sensor))
{
printf("sht1x_update() failed, exiting.\n");
break;
}
printf("Temperature: %f C\n", sht1x_get_temperature(sensor));
printf("Humidity: %f RH\n", sht1x_get_humidity(sensor));
printf("\n");
upm_delay(2);
}
printf("Exiting\n");
sht1x_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _sht1x_context
 

Functions

sht1x_context sht1x_init (unsigned int clk_pin, unsigned int data_pin)
 
void sht1x_close (sht1x_context dev)
 
void sht1x_reset (const sht1x_context dev)
 
upm_result_t sht1x_update (const sht1x_context dev)
 
float sht1x_get_temperature (const sht1x_context dev)
 
float sht1x_get_humidity (const sht1x_context dev)
 
upm_result_t sht1x_read_status (const sht1x_context dev, uint8_t *status)
 
upm_result_t sht1x_write_status (const sht1x_context dev, uint8_t status)
 
void sht1x_set_volts (const sht1x_context dev, SHT1X_VOLTS_T volts)
 
upm_result_t sht1x_send_command (const sht1x_context dev, SHT1X_CMD_T cmd)
 
upm_result_t sht1x_wait_for_response (const sht1x_context dev)
 
void sht1x_start_xmit (const sht1x_context dev)
 
void sht1x_read_8bits (const sht1x_context dev, uint8_t *value)
 
upm_result_t sht1x_write_8bits (const sht1x_context dev, uint8_t byte)
 

Typedefs

typedef struct _sht1x_contextsht1x_context
 

Function Documentation

sht1x_context sht1x_init ( unsigned int  clk_pin,
unsigned int  data_pin 
)

SHT1X Initializer

Parameters
clk_pinSpecify the GPIO pin to use for the clock.
data_pinSpecify the GPIO pin to use for data.
Returns
an initialized device context on success, NULL on error.

Here is the call graph for this function:

void sht1x_close ( sht1x_context  dev)

SHT1X sensor close function

Here is the caller graph for this function:

void sht1x_reset ( const sht1x_context  dev)

Perform a soft reset of the device.

Parameters
devsensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t sht1x_update ( const sht1x_context  dev)

Query the device and store the latest values. You must call this function before querying the temperature or the humidity.

Parameters
devsensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

float sht1x_get_temperature ( const sht1x_context  dev)

Query the temperature in degrees Celsius. sht1x_update() must have been called prior to calling this function.

Parameters
devsensor context
Returns
The temperature in Celsius

Here is the caller graph for this function:

float sht1x_get_humidity ( const sht1x_context  dev)

Query the relative humidity. sht1x_update() must have been called prior to calling this function.

Parameters
devsensor context
Returns
The relative humidity.

Here is the caller graph for this function:

upm_result_t sht1x_read_status ( const sht1x_context  dev,
uint8_t *  status 
)

Read the status register.

Parameters
devsensor context
statusThe pointer to a uint8_t the status register will be stored in.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t sht1x_write_status ( const sht1x_context  dev,
uint8_t  status 
)

Write a value to the status register.

Parameters
devsensor context
statusThe uint8_t to write to the register.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void sht1x_set_volts ( const sht1x_context  dev,
SHT1X_VOLTS_T  volts 
)

The Vdd voltage the sensor is being driven at can affect the temperature measurements. This function allows you to specify a voltage as close as you are using to power the sensor, so that the appropriate compensation can be made. By default, the coefficients are set for 5v operation.

Parameters
devsensor context
voltsOne of the SHT1X_VOLTS_T values.

Here is the caller graph for this function:

upm_result_t sht1x_send_command ( const sht1x_context  dev,
SHT1X_CMD_T  cmd 
)

Send a command to the device. This is a low level command that should not be used directly unless you know exactly what you are doing.

Parameters
devsensor context
cmdOne of the SHT1X_CMD_T values.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t sht1x_wait_for_response ( const sht1x_context  dev)

Wait for the appropriate response when starting a temperature or humidity measurement. This is a low level command that should not be used directly unless you know exactly what you are doing.

Parameters
devsensor context
Returns
UPM result

Here is the caller graph for this function:

void sht1x_start_xmit ( const sht1x_context  dev)

Issue the start transmission sequence. This is a low level command that should not be used directly unless you know exactly what you are doing.

Parameters
devsensor context
Returns
UPM result

Here is the caller graph for this function:

void sht1x_read_8bits ( const sht1x_context  dev,
uint8_t *  value 
)

Read 8 bits (a byte) from the device. This is a low level command that should not be used directly unless you know exactly what you are doing.

Parameters
devsensor context
valuePointer to a uint8_t that will hold the received byte.
Returns
UPM result

Here is the caller graph for this function:

upm_result_t sht1x_write_8bits ( const sht1x_context  dev,
uint8_t  byte 
)

Write 8 bits (a byte) to the device. This is a low level command that should not be used directly unless you know exactly what you are doing.

Parameters
devsensor context
valueA uint8_t that will be sent to the device.
Returns
UPM result

Here is the caller graph for this function:

Typedef Documentation

typedef struct _sht1x_context * sht1x_context

Device context