Giter Site home page Giter Site logo

enjoyneering / htu21d Goto Github PK

View Code? Open in Web Editor NEW
55.0 13.0 16.0 126 KB

This is an Arduino library for HTU21D, Si7021 and SHT21 Digital Humidity & Temperature Sensor

C++ 100.00%
sht21 htu21d si7021 arduino-library temperature-sensor humidity-sensor i2c-sensors

htu21d's People

Contributors

enjoyneering avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

htu21d's Issues

Can not use read functions outside loop [ESP-8266]

Hi.
I've recently test the library with the HTU21D & SI7021 to read the sensor data in some interval callback like this:

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <HTU21D.h>
#include <Ticker.h>

#define D5 14
#define D6 12
#define D3 0
#define D4 2

static Ticker timer;

static HTU21D htu21d;

static void read() {
	if (!htu21d.batteryStatus()) {
		Serial.printf("HTU21D Battery: Not OK! \n");
	}

	float htu_h = htu21d.readHumidity();
	float htu_t = htu21d.readTemperature();
	Serial.printf("HTU21D(T): %f, HTU21D(RH): %f \n", htu_t, htu_h);
}

void setup() {
	Serial.begin(115200);

	WiFi.mode(WIFI_OFF);

	while (!htu21d.begin(D5, D6)) {
		Serial.print('.');
		delay(1000);
	}

	if (htu21d.batteryStatus()) {
		Serial.printf("\n HTU21D Battery: OK\n");
	}

	timer.attach(2.0, &read);
}

void loop() {

}

But inside the timer callback, sensors always report battery status as false and the humidity and temperature as error (255 == HTU21D_ERROR).

The situation for polling is not the same and sensors working properly! :

#include <ESP8266WiFi.h>
#include <Wire.h>
#include <HTU21D.h>

#define INTERVAL 2000
#define D5 14
#define D6 12
#define D3 0
#define D4 2

static HTU21D htu21d;

void setup() {
	Serial.begin(115200);

	WiFi.mode(WIFI_OFF);

	while (!htu21d.begin(D5, D6)) {
		Serial.print('.');
		delay(1000);
	}

	if (htu21d.batteryStatus()) {
		Serial.printf("\n HTU21D Battery: OK\n");
	}
}

void loop() {
	float htu_h = htu21d.readHumidity();
	float htu_t = htu21d.readTemperature();
	Serial.printf("HTU21D(T): %f, HTU21D(RH): %f \n", htu_t, htu_h);

	delay(INTERVAL);
}

No idea what's the problem here

Setup:

  • Latest lib version
  • Latest Arduino Git version
  • ESP-8266(nodemcu)

Regards.

reading errors after FOTA update

Hello, my board is a esp8266 NCU. The sensor HTU21D is detected and reading normally when sketch is loaded by USB or BasicOTA(direct IP). However, when using ESPHTTPUPDATE to be updated from and internet server, the sensor is not detected again unless I do a power down and up.
I have tried many i2C clear buses codes and resets and none seems to work.
I also used the HTU.softReset but no successful result.

I will appreciate any comment.
thanks

Fails with SHT21

Hello

I am using the Wemos D1 mini Pro and a SHT21 sensor (identical to this one:).

I have connected the SDA from the sensor to D2 on the board and SCL from the sensor to D1 on the board. But all I'm getting is: "HTU21D, SHT21 sensor is faild or not connected", when I run the HTU21D_Demo.

When I run I2C scanner (link) it finds an I2C device at address 0x40 and nothing when I remove the sensor. So I guess the sensor is wired up correctly and there might be something else I am doing wrong/missing.

Hope you are able and willing to help me

The Wire.endTransmission() can not be called over and over again.

When the Wire.endTransmission() is called in a while-loop, it could be called over and over again. The Wire.endTransmission() should not be called on its own. It is part of the: Wire.beginTransmission - Wire.Write - Wire.endTransmission.

At this moment, calling the Wire.endTransmission() once more might restart the complete I2C bus transaction. That is however not documented, and it might change in the future.

The Wire.requestFrom() is polled a number of times, until the same amount of bytes is received that was requested.
I have seen that as well in the Sparkun library, but that is to poll the sensor until the data is ready. It is not to compensate for a bad I2C bus. Since you already have the appropriate delay, I suggest to call Wire.requestFrom() just once and return an error if it fails.

Warning compling on ESP32

Probably not specific to ESP32, but I got warnings when compiling for ESP32, here is the warning:
lib\HTU21D\src\HTU21D.cpp: In member function 'float HTU21D::readHumidity(HTU21D_HUMD_OPERATION_MODE)':
lib\HTU21D\src\HTU21D.cpp:249:43: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
Wire.requestFrom(HTU21D_ADDRESS, 3, true); //true, stop message after transmission & releas the I2C bus
^
In file included from lib\HTU21D\src\HTU21D.h:49:0,
from lib\HTU21D\src\HTU21D.cpp:32:
C:\Users\tihomir.platformio\packages\framework-arduinoespressif32\libraries\Wire\src/Wire.h:98:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int, int)
uint8_t requestFrom(int address, int size, int sendStop);
^
C:\Users\tihomir.platformio\packages\framework-arduinoespressif32\libraries\Wire\src/Wire.h:93:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint16_t, uint8_t, bool)
uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop);

Attached is zipped patch that fixes the warning. It is zipped because it didn't allow me to attach .patch file.

Created PR #11

ESP8266 Invalid values

I'm using this library on ESP8266 processors. It was previously working properly, but it is now reporting temperature and humidity at 255. I've verified the sensor works using an Arduino Nano, and the same demo example. The only difference between the two is the pins used (I'm using D4 and D5 for SDA and SCL on a Wemos D1 mini).

Here's what I've changed in the example:
(myHTU21D.begin(D4,D5) != true)

Use of Delays

Hello, Not an issue but a quick question. I was wondering what would be the reason for using blocking code i.e use of delay function while calculating Temperature and Humidity.

I was thinking to go Non blocking using millis. Also not sure how you got to those number for delays for different resolution.
What are your thoughts ?

Thank you for your effort and putting this wonderful library in public domain.

Temperature compensated humidity for SHT21

Hi,

What is your source for the temperature compensation of the humidity at line 418 in HTU21D.CPP . You claim it is valid for the SHT21 but I cannot any reference in the Sensirion datasheets for the SHT21.

Sincerely,
Diederik vd Pant

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.