Giter Club home page Giter Club logo

Comments (9)

OttoWinter avatar OttoWinter commented on August 21, 2024

Thanks for reporting this too 👍

Oh... I forgot to initialize the HTU21D pointers here 🤕. (I don't have this sensor yet so I can't really test it; that's also why it's marked as experimental in the docs)

from esphome-core.

warfair1337 avatar warfair1337 commented on August 21, 2024

Thanks again. I'll test htu21d for you :)
I have some esp32's around that I also can test.

from esphome-core.

warfair1337 avatar warfair1337 commented on August 21, 2024

After successfully connecting wifi (using alphanumeric psk) I got some progress on the htu21d.
I tested with Adafruit HTU21D library example first to verify, and it works.

I'm a little unsure what pins you are asking to define. Is it gpio-number (e.g 5 and 4 for NodeMCU) or pin-number (e.g D2 and D1 for NodeMCU). Must this be specified? What about defaulting to boards i2c-pins.

Here's serial log output. I can see the htu21d is connected, first temperature reading is always 128,9C. After that NaN on both temperature and humidity.

[C][sensor::htu21d:setup:55]: Setting up HTU21D...
[C][component:setup_:126]:     Update interval: 15000ms
[C][sensor::mqtt:setup:30]: Setting up MQTT Sensor 'HTU21D Temperature'
[C][sensor::mqtt:setup:32]:     Expire After: 450s
[C][sensor::mqtt:setup:33]:     Unit of Measurement: '°C'
[C][sensor::mqtt:setup:34]:     Accuracy Decimals: 0
[C][sensor::mqtt:setup:35]:     Icon: ''
[C][sensor::mqtt:setup:36]:     # Filters: 1
[C][sensor::mqtt:setup:30]: Setting up MQTT Sensor 'HTU21D Humidity'
[C][sensor::mqtt:setup:32]:     Expire After: 450s
[C][sensor::mqtt:setup:33]:     Unit of Measurement: '%'
[C][sensor::mqtt:setup:34]:     Accuracy Decimals: 0
[C][sensor::mqtt:setup:35]:     Icon: 'mdi:water-percent'
[C][sensor::mqtt:setup:36]:     # Filters: 1
[I][application:loop:50]: Running through first loop()
[I][application:loop:59]: First loop finished successfully!
[D][sensor::htu21d:update:68]: Got Temperature=128.9°C Humidity=nan%
[W][sensor::htu21d:update:78]: Invalid Humidity: nan%
[D][sensor::htu21d:update:68]: Got Temperature=nan°C Humidity=nan%
[W][sensor::htu21d:update:73]: Invalid Temperature: nan!C
[W][sensor::htu21d:update:78]: Invalid Humidity: nan%

from esphome-core.

warfair1337 avatar warfair1337 commented on August 21, 2024

Also tested on the ESP32. I defined pins 21 SDA and 22 SCL which is the boards default.
Code is identical to what I used for the 8266, except sda/scl pins.
Failed the connection to htu21d. See output.

[C][ota:setup:22]: Setting up OTA...
[C][ota:setup:23]:     port: 3232
[C][ota:setup:28]:     hostname: 'testhtu21d'
[C][sensor::htu21d:setup:55]: Setting up HTU21D...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][sensor::htu21d:setup:60]: Connection to HTU21D failed.
[C][component:setup_:126]:     Update interval: 15000ms
[C][sensor::mqtt:setup:30]: Setting up MQTT Sensor 'HTU21D Temperature'
[C][sensor::mqtt:setup:32]:     Expire After: 450s
[C][sensor::mqtt:setup:33]:     Unit of Measurement: '°C'
[C][sensor::mqtt:setup:34]:     Accuracy Decimals: 0
[C][sensor::mqtt:setup:35]:     Icon: ''
[C][sensor::mqtt:setup:36]:     # Filters: 1
[C][sensor::mqtt:setup:30]: Setting up MQTT Sensor 'HTU21D Humidity'
[C][sensor::mqtt:setup:32]:     Expire After: 450s
[C][sensor::mqtt:setup:33]:     Unit of Measurement: '%'
[C][sensor::mqtt:setup:34]:     Accuracy Decimals: 0
[C][sensor::mqtt:setup:35]:     Icon: 'mdi:water-percent'
[C][sensor::mqtt:setup:36]:     # Filters: 1
[I][application:loop:50]: Running through first loop()
[I][application:loop:59]: First loop finished successfully!
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 40
[D][sensor::htu21d:update:68]: Got Temperature=nan°C Humidity=nan%
[W][sensor::htu21d:update:73]: Invalid Temperature: nan!C
[W][sensor::htu21d:update:78]: Invalid Humidity: nan%

from esphome-core.

OttoWinter avatar OttoWinter commented on August 21, 2024

I'm a little unsure what pins you are asking to define. Is it gpio-number (e.g 5 and 4 for NodeMCU) or pin-number (e.g D2 and D1 for NodeMCU). Must this be specified? What about defaulting to boards i2c-pins.

esphomelib uses the GPIO pin numbers (i.e. 5 & 4) everywhere. Because of the magic of esphomelib (or to be more precise the arduino framework), you can type the following 🤓

App.init_i2c(D2, D1);
# equivalent to: 
App.init_i2c(4, 5);

I'm not a huge user of the ESP8266 myself, but are D2 and D1 really always the default i2c pins on all boards? If not, I'd rather have users type out the full pin numbers instead of some users needing to debug the code because their board uses different default i2c pins...

Re HTU21D "Connection to HTU21D failed.": Hmmm, I don't know what could be going wrong here. I mean I'm just using an existing library (i2cdevlib) for getting the sensor values here and I'd hope that that library works...

Anyway, I think there might have been another issue in my own code (but I kind of doubt it). Otherwise I think I'll just re-write the library myself as I just did with the DS18b20 sensors (ended up making those sensors much more stable). The quality of the 3rd party libraries I've been using apparently seems to not be too good :/

from esphome-core.

warfair1337 avatar warfair1337 commented on August 21, 2024

The htu21d says connected on esp8266, but fails to connect on the esp32.

As for default pins, all pinout diagrams etc and papers i have read says that esp12-chip uses gpio 4 and 5 (d1 and d2 on nodemcu/wemos etc). for i2c, and 21 and 22 on the esp32-chip. This can be changed, but unless defined somewhere, it will use these default pins. That's my understanding, don't take my word for it 😆

from esphome-core.

OttoWinter avatar OttoWinter commented on August 21, 2024

Well, at least some progress 😺

That's really weird that it would only work on one board... I'll try my BMP180 (also i2c-based) on the ESP32 again too to maybe gain some more insight. And looking at the pin definitions, you're right that the SDA and SCL pins are well defined, I will put it in the code; thanks very much 👍

from esphome-core.

OttoWinter avatar OttoWinter commented on August 21, 2024

Oh well, I just found the esp8266 thing board uses different SDA/SCL pins :/

With some C++/C macro magic that shouldn't be a problem though 😀

from esphome-core.

OttoWinter avatar OttoWinter commented on August 21, 2024

Ok, I think the issue should now be fixed with the sensor rewrite/refactor in 1.3.0. Closing this issue...

from esphome-core.

Related Issues (20)

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.