HCSHT3x - Library for SHT3x Temperature & Humidity devices

Useful guides, libraries, and example sketches to support our Arduino based products.
Post Reply
admin
Site Admin
Posts: 865
Joined: Sun Aug 05, 2012 4:02 pm

HCSHT3x - Library for SHT3x Temperature & Humidity devices

Post by admin » Wed Jun 07, 2017 3:14 pm

[IMAGE TBA]

Image


Arduino library for the SHT3x digital temperature and humidity senor.
Products currently supported by this library:

WeMos SHT30 I2C Digital Temperature Humidity Sensor Shield (HCWEMO0011) available from hobbycomponents.com


You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/

Linux:
Usually found within the users home area under /Arduino/libraries/



Using the HCSHT3x library

To use the library just include the HCSHT3x .h header file and then create an instance of the library. E.g:

Code: Select all

#include <HCSHT3x .h>
HCSHT3x HCSHT3x(I2C_ADD);

Where I2C_Add is the I2C address of the SHT3x. Valid values for I2C_Add are 0x44 & 0x45.


To initialise the library add the following line to the setup() section of your sketch:

Code: Select all

SHT3x.init();


The following functions are available with this library:


void HCSHT3x.Read(void)

Performs a read of the SHT3x and updates the currently stored values for temperature and humidity. The new values read back from the sensor can then be obtained using the
Temp_oC(), Temp_oF(), and/or Hum() library functions.

Note that this function is blocking and requires 500ms for the sensor to complete a measurement.

Example:

Code: Select all

HCSHT3x.Read();



float HCSHT3x.Temp_oC(void)

Returns a floating point value containing the temperature in Centigrade which was previously read using the Read() library function.

Example:

Code: Select all

float Temp = HCSHT3x.Temp_oC();



float HCSHT3x.Temp_oF(void)

Returns a floating point value containing the temperature in Fahrenheit which was previously read using the Read() library function.

Example:

Code: Select all

float Temp = HCSHT3x.Temp_oF();



float HCSHT3x.Hum(void)

Returns a floating point value containing the relative humidity in % which was previously read using the Read() library function.

Example:

Code: Select all

float Humidity = HCSHT3x.Hum();



bool HCSHT3x.CheckCRC(void)

Checks if the last data read back using the Read() library function has a valid CRC.

Returns a boolean value where:
true = CRC is valid
false = CRC is invalid

Example:

Code: Select all

if(HCSHT3x.CheckCRC())
{
	Temp = HCSHT3x.Temp_oC();
	Humidity = HCSHT3x.Hum();
}


Image

Code: Select all

/* FILE:    HCPCF8574_Blink_Example.cpp
   DATE:    24/05/17
   VERSION: 0.1
   AUTHOR:  Andrew Davies
   
24/05/17 version 0.1: Original version

This example sketch uses the HCPCF8574 library to toggle one of the PCF8574's digital pins
emulating the standard Arduino 'blink' sketch. This sketch has been written specifically for
the Hobby Components PCF8574 I2C to 8-bit digital port expander (HCMODU0120). To use the 
sketch change the I2C_ADD to match the address of your device (default is 0x38 for HCMODU0120)
and connect and LED (via a current limiting resistor) to the PCF8574's digital pin 0 (marked
D0 on HCMODU0120). You can connect your Arduino to the module as follows:

UNO/NANO........HCMODU0120
VCC.............5V
GND.............GND
A4..............SDA
A5..............SCL

More information about the library can be found in the software section of our support 
forum here:

http://forum.hobbycomponents.com/software


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/


#include "HCPCF8574.h"    //Include the HCPCF8574 library

#define I2C_ADD 0x38      //I2C address of the PCF8574

HCPCF8574 Port(I2C_ADD);  //Create an instance of the library


void setup() 
{
  Port.init();            //Initiliase the PCF8574 (all pins are set to high)

  Port.pinMode(0, OUTPUT); //Set digital pin 0 to an ouput
}


void loop() 
{
  Port.pinWrite(0, HIGH); //Set digital pin 0 high
  delay(1000);            //Wait 1 second
  Port.pinWrite(0, LOW);  //Set digital pin 0 low
  delay(1000);            //Wait another second
}



Image
HCSHT3x.zip

Diagrams, libraries, and example code are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.
You do not have the required permissions to view the files attached to this post.

Post Reply

Return to “Arduino”