Copyright 2020 Chih-Yu Hsiang [email protected]
Copyright 2009 Jonathan Oxer [email protected] / http://www.practicalarduino.com
Copyright 2008 Maurice Ribble [email protected] / http://www.glacialwanderer.com
This repository is based on practicalarduino/SHT1x and fully support all commands of sht1x.
Provides a simple interface to the SHT1x series (SHT10, SHT11, SHT15) and SHT7x series (SHT71, SHT75) temperature / humidity sensors from Sensirion, http://www.sensirion.com. These sensors use a "2-wire" communications buss that is similar to I2C and can co-exist on the same physical wire as I2C devices.
Download the directory "SHT1x" and move it into the "libraries" directory inside your sketchbook directory, then restart the Arduino IDE. You will then see it listed under File->Examples->SHT1x.
The library is instantiated as an object with methods. Include it in your sketch and then create an object, specifying the pins to use for communication with the sensor and initial it:
#include <SHT1x.h>
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
sht1x.init();
You can then call methods on that object within your program. In this example we created an object called "sht1x", but it could have been called whatever you like. A simple example program is included with the library and can be accessed from the File->Examples->SHT1x menu.
The readTemperature()
method returns a float within the valid range of the sensor of -40 to +123.8C (-40 to +254.9F).
A value of -40 is returned in the event of a communication error with
the sensor.
Example:
// read temperature and covert to degree Celsius
float tempC = sht1x.readTemperature(TempUnit::C);
// read temperature and covert to degree Fahrenheit
float tempF = sht1x.readTemperature(TempUnit::F);
The readHumidity()
method returns a float within the valid range of the sensor of 0 to 100%.
A negative value is returned in the event of a communication error with
the sensor.
Example:
float humidity = sht1x.readHumidity();
If communication with the device is lost the connectionReset()
method
can reset the serial interface.
(interface only)
Example:
sht1x.connectionReset();
The softReset()
method can
resets the interface, clears the
status register to default values.
Example:
sht1x.softReset();
The readStatusReg()
method will read status register from sht1x
and return it.
Example:
auto reg_value = sht1x.readStatusReg();
The writeStatusReg()
method will write value to sht1x status register.
Example:
sht1x.readStatusReg(value);
This library support CRC-8. In default, the CRC is used, but it can be disabled via the argument.
Example:
// read temperature without CRC
float tempC = sht1x.readTemperature(TempUnit::C, false);
// read humidity without CRC
float humidity = sht1x.readHumidity(false);
// read status register without CRC
float humidity = sht1x.readStatusReg(false);