Coder Social home page Coder Social logo

sparkfun / sparkfun_rht03_particle_library Goto Github PK

View Code? Open in Web Editor NEW
4.0 42.0 5.0 10 KB

Firmware library for the SparkFun RHT03 humidity and temperature sensor.

License: MIT License

C++ 66.25% Arduino 33.75%
particle-photon particle-io humidity sparkfun

sparkfun_rht03_particle_library's Introduction

SparkFun RHT03 Particle Library

A firmware library for the SparkFun's RHT03 humidity and temperaure sensor.

RHT03 About

The RHT03 is a one-wire digital sensor that measures relative humidity from 0-100% and temperature from -40-80 deg C.

Repository Contents

  • /firmware - Source files for the library (.cpp, .h).
  • /firmware/examples - Example sketches for the library (.cpp). Run these from the Particle IDE.
  • spark.json - General library properties for the Particle library manager.

Example Usage

Create an RHT03 Object & Initialize

To begin, create an RHT03 class object. This'll often go in the global section of the code:

///////////////////////////
// RHT03 Object Creation //
///////////////////////////
RHT03 rht; // This creates a RTH03 object, which we'll use to interact with the sensor

To initialize the sensor, call the begin([pin]) function, where [pin] is the Photon pin connected to the RHT03 data pin.

void setup()
{
	...
	rht.begin(D3); // Initialize an RHT03 sensor, with the data pin connected to D3.
	...
}

Update and Read Humidity and Temp Values

Temperature and humidity values are updated in one fell single-wire swoop. To get new values from the sensor, call update(). update() returns either 1 on success, or a negative value if it fails.

int updateRet = rht.update();

If the update succeeds, use the humidity(), tempC(), and tempF() functions to get relative humidity, celsius, and farenheit temperatures. All variables are returned as float's.

if (updateRet == 1)
{
	float rh = rht.humidity();
	float tf = rht.tempF();
	float tc = rht.tempC();
}

Recommended Components

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact [email protected].

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_rht03_particle_library's People

Contributors

sdicke avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_rht03_particle_library's Issues

Temperatures below 0°C are rolling over

This code

"\"RHT03\":{" +
   "\"T\":" + String(rht.tempC(), 2) + "," +
   "\"H\":" + String(rht.humidity(), 2) + 
"}," +

is creating this result

"RHT03":{"T":3279.80,"H":83.30}

These where all the readings on the same board during that fetch:

{"BME280":{"T":-1.88,"H":84.75,"P":1023.99},
 "RHT03":{"T":3279.80,"H":83.30},
 "DS18B20":{
   "28CEB45204000083":{"T":-3.19,"C":1},
   "28646952040000A2":{"T":-3.19,"C":1}
 },
 "A0":{"L":2.50}
}

I consider the DS18B20's temperature readings to be the "most precise"

Does not return correct values for new Particle mesh devices.

When using the RHT03 sensor and this library for the new Particle Mesh devices, the return values are not consistent. There is a thread in the Particle community forums about the issue here:

https://community.particle.io/t/incorrect-data-output-with-rht03-temp-humidity-sensor-using-argon-solved-but-now-using-dht11/46808

It is possible that the use of noInterrupts() and interrupts() may cause unintended problems with timing on the Mesh devices.

Compile errors when using Particle Build

There are two code issues in this library source that result in compilation errors if copy/pasted in to the Particle Build cloud IDE. I am not familiar enough with the Particle ecosystem and history to understand if/how this worked previously.

Compile errors:

src/SparkFunRHT03.cpp:119:28: error: 'CHECKSUM' was not declared in this scope
     if (checksum(dataBytes[CHECKSUM], dataBytes, 4))
                            ^
src/SparkFunRHT03.cpp:121:48: error: 'HUMIDITY_H' was not declared in this scope
   _humidity = (static_cast<uint16_t>(dataBytes[HUMIDITY_H] << 8) | dataBytes[HUMIDITY_L]);
                                                ^
src/SparkFunRHT03.cpp:121:78: error: 'HUMIDITY_L' was not declared in this scope
   _humidity = (static_cast<uint16_t>(dataBytes[HUMIDITY_H] << 8) | dataBytes[HUMIDITY_L]);
                                                                              ^
src/SparkFunRHT03.cpp:122:52: error: 'TEMP_H' was not declared in this scope
   _temperature = static_cast<uint16_t> ((dataBytes[TEMP_H] << 8) | dataBytes[TEMP_L]);
                                                    ^
src/SparkFunRHT03.cpp:122:78: error: 'TEMP_L' was not declared in this scope
   _temperature = static_cast<uint16_t> ((dataBytes[TEMP_H] << 8) | dataBytes[TEMP_L]);
                                                                              ^
src/SparkFunRHT03.cpp:131:6: error:
prototype for 'bool RHT03::checksum(byte, const byte*, unsigned int)' 
does not match any in class 'RHT03'
 bool RHT03::checksum(const byte check, const byte * data, const unsigned int datalen)
      
src/SparkFunRHT03.cpp:35:7: error: candidate is: bool RHT03::checksum(byte, byte*, unsigned int)
  bool checksum(byte check, byte * data, const unsigned int datalen);       

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.