0

HTU31 on Arduino (PRODUCT ID: 4832)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Mon Aug 02, 2021 2:37 pm

Trying to use the HTU31 on an Arduino (Adafruit Huzzah with ESP6288)

When I tell you it took me a little while to find the right library, "Adafruit HTU31D Library", you may think I am beyond help. But for others following in my footsteps... there is a library! That's the name. If you put HTU into the filter of the Library Manager, that will reduce the hits to a manageable number. (Don't install the HTU *2* 1D library by mistake!)

I loaded the simple example. (The one not using the OLED display.) Set the serial monitor to operate at 115200.

And now I get SOMETHING!

Code: Select all | TOGGLE FULL SIZE
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90:  3fffdad0 00000000 3ffee6bc 40201084 
3fffffa0:  feefeffe feefeffe 3ffee710 40202b98 
3fffffb0:  feefeffe feefeffe 3ffe85e0 40100e21 
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000440f0
~ld
Adafruit HTU31D test
Couldn't find sensor!


(I've tried running it with all four combinations of the address line and (sensor module's) RST line pulled high and pulled low. Made no difference. (Can they ordinarily be left floating? I hope the RST is an input to the sensor module!? Yes. I'm tired. Long day. Not just stupid.))

I HAVE got my sensor on the end of a 6' cable (telephone hook-up). Asking to much of I2C?

Ideas?
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Tue Aug 03, 2021 4:19 am

Update/ question

Tried shortening the cable. Sensor now 15cm from microprocessor. Same results, precisely. (Same numbers.)

Might I please at least have an answer, Adafruit, on whether the Address and Reset lines can be left floating?

(And can I suggest that you put a link to the library into the product's description page, and a link to...
https://learn.adafruit.com/adafruit-htu ... r/overview
... if that's also appropriate as an overview for the 31d? (With perhaps a little editing of the 21's overview, to discuss the differences between the two.)

It's disappointing to buy from a "big name" Arduino supplier on the assumption (based on past purchases!) that I'm paying not just for the device, but for great documentation, and find my faith misplaced... in this instance.

95% of what I know about using these things comes from the product support pages at Adafruit and Sparkfun. It's been a great ride.
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Tue Aug 03, 2021 4:39 am

I wondered if maybe I needed pull-up resistors on SCL/SDA. Does the breakout have pull-ups on those lines?

Tried adding 10k pull-ups. Made no difference. (The fact that my error message has been the same, exactly, all along, is good news/ bad news. If it weren't always the same, some possibilities would arise. Always the same rules some out? (E.g. noise?))

If pull-ups should be added, could an expert advise on an appropriate value for the resistors, please?
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by adafruit_support_mike on Wed Aug 04, 2021 8:39 pm

Post a photo showing your hardware and connections and we’ll take a look. 800x600 images usually work best.

A couple meters of twisted-pair phone cable shouldn’t be a problem for an I2C connection. It isn’t ideal, but isn’t a huge parasitic load.

adafruit_support_mike
 
Posts: 63669
Joined: Thu Feb 11, 2010 2:51 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sat Aug 07, 2021 10:13 am

Herewith response to your request....

N.B.: The colors on the cable are a trap for the unwary... an unfortunate consequence of sequencing them for prettiness...
Vcc is, in the cable, in the BLACK conductor
Gnd is, in the cable, in the RED connector.

Red and black used normally (the other way around) everywhere else. "Power" indicator on breakout comes on perfectly well.

Cable green is jumper green
Cable blue is jumper yellow.

============
Completely rebuilt after question first posted. Still get, consistently, exactly the same run time error messages as before, c/o Serial Monitor, as is normal.

============
Cable is not twisted pairs... but then again, it isn't 2m anymore, either.

============
Are pull-ups needed on SCL/SDA? or are they provided on the breakout?

Can RST and ADDR be left floating?

===========
Code: Select all | TOGGLE FULL SIZE
[code]
/***************************************************
  This is an example for the HTU31 Humidity & Temp Sensor

  Designed specifically to work with the HTU31 sensor from Adafruit
  ----> https://www.adafruit.com/products/4832

  These displays use I2C to communicate, 2 pins are required to
  interface
 ****************************************************/

#include <Wire.h>
#include "Adafruit_HTU31D.h"

Adafruit_HTU31D htu = Adafruit_HTU31D();
uint32_t timestamp;
bool heaterEnabled = false;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    delay(10); // wait till serial port opens
  }
  Serial.println("Adafruit HTU31D test");

  if (!htu.begin(0x40)) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
  timestamp = millis();
}

void loop() {
  sensors_event_t humidity, temp;
 
  htu.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data

  Serial.print("Temp: ");
  Serial.print(temp.temperature);
  Serial.println(" C");
 
  Serial.print("Humidity: ");
  Serial.print(humidity.relative_humidity);
  Serial.println(" \% RH");

  // every 5 seconds
  if ((millis() - timestamp) > 5000) {
    // toggle the heater
    heaterEnabled = !heaterEnabled;
    if (heaterEnabled) {
      Serial.println("Turning on heater");
    } else {
      Serial.println("Turning off heater");
    }
    if (! htu.enableHeater(heaterEnabled)) {
      Serial.println("Command failed");
    }

    timestamp = millis();
  }

  delay(500);
}
[/code]
Attachments
iec220-on-huzzah8266-lp1190627.jpg
iec220-on-huzzah8266-lp1190627.jpg (230 KiB) Viewed 50 times
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sat Aug 07, 2021 4:09 pm

Further work... many hours, several boards and TYPES of board, and sensor... And I am beginning to think something in the 8266's attempts to connect to WiFi is causing my crashes. Beginning to suspect that the code execution never even gets to the I2C stuff. Will come back with further information if I make any progress.
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sat Aug 07, 2021 7:28 pm

Well... I got to the bottom of it eventually. Over a day to figure out. No faults in my hardware, thankfully... neither my Sparkfun Thing Dev, nor my Adafruit Feather Huzzah 8622.

Now working nicely with Sparkfun Si7021 I2C temperature/humidity sensor, in both 8266 systems.

Disappointed that no one at Adafruit has taken time to answer my "basic" questions. (Repeated in previous post.) Nor helped me out, by pointing me towards the quirk of the Feather's design that was at the root of this.
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sun Aug 08, 2021 5:44 am

Many hours of further work, and I like the HTU31D / Huzzah With 8266 less and less.

Sparkfun Si7021 still working on both Thing Dev and Huzzah. (The latter being more of a struggle to use... port init issues)

HTU31 still NOT working on either.

Sigh.

I like that with the Huzzah you can "move" the I2C interface to non-standard pins. Not sure why I'd "need" that, but it was nice, here, as a way to check that I hadn't fried the standard pins. (Si7021 worked on both the standard pins, and with the right code, pins 12 and 13.)

https://arduino-esp8266.readthedocs.io/ ... ashes.html

... is very helpful in respect of the complex messages that arise in some cases., e.g.
Code: Select all | TOGGLE FULL SIZE
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90:  3fffdad0 00000000 3ffee6bc 40201084...
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sun Aug 08, 2021 8:02 am

Can I get ANYTHING to work on my Huzzah ESP8266? (my ref ICH09b). Maybe I bricked it?

Good news! My Huzzah worked fine with an Adafuit AHT20 (stock ID 4566) (my ref IEC224) (The sensor also worked fine on the Sparkfun Thing Dev)

(AFTER all of the travails described above)
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sun Aug 08, 2021 8:22 am

Progress, I guess... but disappointment....

When I used a Stemma QT cable to connect the device, as opposed to the very short cable shown in the illustration above, it worked! (At last)

Yes, I could have made a wiring mistake in the cable. Do you know how many times I have reconnected everything in the past two days? Tell yourself it is a wiring mistake if you like. And, absent any feedback from Adafruit, I tried that with and without pull-ups on the I2C lines.

If the I2C bus can't tolerate my short cable, what hope for my plan to build a monitor to compare humidity in a bookcase-with-doors with the humidity in the room it sits in?

The https://learn.adafruit.com/dht/using-a-dhtxx-sensor DHT22 seemed a possible alternative sensor... but I can't get that to work on either the Huzzah or the Sparkfun.

Ah well.
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Re: HTU31 on Arduino (PRODUCT ID: 4832)

by Sheepdog on Sun Aug 08, 2021 9:14 am

Well... very long road... but I now have either the Huzzah or the Thing reading two HTU31s. Only a few tweaks needed, but (as ever) the slightest stray semicolon, and no go.

The sensors are connected with a JST-JST cable, and the proximal sensor connected to microprocessor (on a breadboard) with a JST to DuPont cable.

Using the Adafruit Adafruit HTU31D library. (And the standard "Wire" library.)

A blob of solder on the back of one of the sensor breakouts changed its address to 41.

The ADDR and RST inputs to the breakout left floating.
No pull-ups put on SDA/SCL- I guess there ARE pullups for these on the breakouts.

---
Now... can I get that working inside a webserver?? I hope so, after the work to get this far!
Sheepdog
 
Posts: 19
Joined: Wed Sep 14, 2011 2:16 pm

Please be positive and constructive with your questions and comments.