Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. [SOLVED] s17021 vs HTU21

[SOLVED] s17021 vs HTU21

Scheduled Pinned Locked Moved Hardware
temperature
9 Posts 3 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 4 Offline
    4 Offline
    4994james
    wrote on last edited by Yveaux
    #1

    I have had plenty of success with s17021 sensors and the mysensors library in the past however I have recently purchased some more boards for what I thought was a reasonable deal from Amazon. This is exactly what I have.
    0394aaa5-5ce0-493f-b787-a59fed5bc57b-image.png
    The issue I have is that none of them work. When it gets to Begin() it just stops. It doesn't return at all so doesn't issue a "sensor not detected" which is what I would expect if not connected. I hooked up my logic analyser trace and can see the initial command but nothing comes back.
    I can see the basic chip is different to the ones to the boards I have used previously so assume there is some software incompatibility. However I have looked at the data sheet and it is a I2C component and seems to have identical addresses and commands as the si7021. Have I just got a load of defective items or should I be using different software?

    Y 1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      Maybe try an i2c scanner to see if the datasheet has got the address wrong? https://playground.arduino.cc/Main/I2cScanner/

      4 1 Reply Last reply
      1
      • 4 4994james

        I have had plenty of success with s17021 sensors and the mysensors library in the past however I have recently purchased some more boards for what I thought was a reasonable deal from Amazon. This is exactly what I have.
        0394aaa5-5ce0-493f-b787-a59fed5bc57b-image.png
        The issue I have is that none of them work. When it gets to Begin() it just stops. It doesn't return at all so doesn't issue a "sensor not detected" which is what I would expect if not connected. I hooked up my logic analyser trace and can see the initial command but nothing comes back.
        I can see the basic chip is different to the ones to the boards I have used previously so assume there is some software incompatibility. However I have looked at the data sheet and it is a I2C component and seems to have identical addresses and commands as the si7021. Have I just got a load of defective items or should I be using different software?

        Y Offline
        Y Offline
        Yveaux
        Mod
        wrote on last edited by
        #3

        @4994james How do you connect the board? Do you have the I2C pull-up resistors mounted?

        http://yveaux.blogspot.nl

        4 1 Reply Last reply
        1
        • mfalkviddM mfalkvidd

          Maybe try an i2c scanner to see if the datasheet has got the address wrong? https://playground.arduino.cc/Main/I2cScanner/

          4 Offline
          4 Offline
          4994james
          wrote on last edited by
          #4

          @mfalkvidd Hi. Thank you. Most useful. Just tried and it reports:

          I2C Scanner
          Scanning...
          I2C device found at address 0x40 !
          done

          So seems to be the same as si7021 and correct. Will respond to @Yveaux with more details as still not working with si7021 library.

          1 Reply Last reply
          1
          • Y Yveaux

            @4994james How do you connect the board? Do you have the I2C pull-up resistors mounted?

            4 Offline
            4 Offline
            4994james
            wrote on last edited by
            #5

            @Yveaux
            Many thanks for your response.
            I think the board has onboard pull up resistors, But to eliminate doubt I added 2 1k pull ups to sda and scl. This is the debug output when i use a sparkfun si7021 board (also with same pull ups - though not needed for this board for sure):

            setup!10446 MCO:BGN:INIT OK,TSP=1
            Temp 18.83C	Hum 50.94
            

            and this is a screenshot of the trace on sda and scl:
            5c5812d9-a6fe-4b15-8026-3cf5def7d828-image.png

            E3 is temp command.

            followed by
            71c0c256-9b3c-470a-aeb0-98f7e2dac52e-image.png

            Temp reading and another (not shown) set of commands and humidity reading.

            However with the HTU21D the sketch hangs here:

            setup!10397 MCO:BGN:INIT OK,TSP=1
            

            i get the same first command trace as you would expect (same library) but no response from the board.

            Y 1 Reply Last reply
            0
            • 4 4994james

              @Yveaux
              Many thanks for your response.
              I think the board has onboard pull up resistors, But to eliminate doubt I added 2 1k pull ups to sda and scl. This is the debug output when i use a sparkfun si7021 board (also with same pull ups - though not needed for this board for sure):

              setup!10446 MCO:BGN:INIT OK,TSP=1
              Temp 18.83C	Hum 50.94
              

              and this is a screenshot of the trace on sda and scl:
              5c5812d9-a6fe-4b15-8026-3cf5def7d828-image.png

              E3 is temp command.

              followed by
              71c0c256-9b3c-470a-aeb0-98f7e2dac52e-image.png

              Temp reading and another (not shown) set of commands and humidity reading.

              However with the HTU21D the sketch hangs here:

              setup!10397 MCO:BGN:INIT OK,TSP=1
              

              i get the same first command trace as you would expect (same library) but no response from the board.

              Y Offline
              Y Offline
              Yveaux
              Mod
              wrote on last edited by
              #6

              @4994james as you own the tools to monitor the i2c traffic, what is going on with the htu on the bus during initialization?

              http://yveaux.blogspot.nl

              4 1 Reply Last reply
              0
              • Y Yveaux

                @4994james as you own the tools to monitor the i2c traffic, what is going on with the htu on the bus during initialization?

                4 Offline
                4 Offline
                4994james
                wrote on last edited by
                #7

                @Yveaux
                This is what I see on trigger. this is identical when HTU21 and Si7021 boards are connected.
                97c3c3a0-5146-4e00-a868-f60a571b7185-image.png

                4 1 Reply Last reply
                0
                • 4 4994james

                  @Yveaux
                  This is what I see on trigger. this is identical when HTU21 and Si7021 boards are connected.
                  97c3c3a0-5146-4e00-a868-f60a571b7185-image.png

                  4 Offline
                  4 Offline
                  4994james
                  wrote on last edited by
                  #8

                  @4994james
                  Hi. I have been reading https://forum.mysensors.org/topic/476/htu21d-humidity-temperature-sensor/8 and have now got this working using the adafruit htu21d library. Not sure what the difference is but there obviously is something. I also confirm that the board works without external pull up resistors. Thanks for you help.

                  This is my new (working) code:

                  /**
                   * The MySensors Arduino library handles the wireless radio link and protocol
                   * between your home built sensors/actuators and HA controller of choice.
                   * The sensors forms a self healing radio network with optional repeaters. Each
                   * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                   * network topology allowing messages to be routed to nodes.
                   *
                   * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                   * Copyright (C) 2013-2015 Sensnology AB
                   * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                   *
                   * Documentation: http://www.mysensors.org
                   * Support Forum: http://forum.mysensors.org
                   *
                   * This program is free software; you can redistribute it and/or
                   * modify it under the terms of the GNU General Public License
                   * version 2 as published by the Free Software Foundation.
                   *
                   *******************************
                   *
                   * REVISION HISTORY
                   * Version 1.0: Andrew Sutcliffe
                   *  
                   * DESCRIPTION
                   * This sketch provides an example of how to implement a humidity/temperature
                   * sensor using a HTU21DF Sensor.
                   *  
                   * For more information, please visit:
                   * http://www.mysensors.org/build/humidity
                   * 
                   * Connect Vin to 3-5VDC
                   * Connect GND to ground
                   * Connect SCL to I2C clock pin (A5 on UNO)
                   * Connect SDA to I2C data pin (A4 on UNO)
                   * 
                   */
                  
                  // Enable debug prints
                  #define MY_DEBUG
                  
                  // Enable and select radio type attached 
                  //#define MY_RADIO_NRF24
                  //#define MY_RADIO_RFM69
                  #define MY_RS485
                  
                  // Define this to enables DE-pin management on defined pin
                  #define MY_RS485_DE_PIN 2
                  
                  // Set RS485 baud rate to use
                  #define MY_RS485_BAUD_RATE 9600
                  
                  #include <MySensors.h>  
                  #include <Wire.h>
                  #include "Adafruit_HTU21DF.h"
                  
                  Adafruit_HTU21DF htu = Adafruit_HTU21DF();
                  
                  // Set this offset if the sensor has a permanent small offset to the real temperatures
                  #define SENSOR_TEMP_OFFSET 0
                  
                  // Sleep time between sensor updates (in milliseconds)
                  
                  static const uint64_t UPDATE_INTERVAL = 60000;
                  
                  // Force sending an update of the temperature after n sensor reads, so a controller showing the
                  // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
                  // the value didn't change since;
                  // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
                  static const uint8_t FORCE_UPDATE_N_READS = 10;
                  
                  #define CHILD_ID_HUM 0
                  #define CHILD_ID_TEMP 1
                  
                  #define MY_NODE_ID 104
                  
                  float lastTemp;
                  float lastHum;
                  uint8_t nNoUpdatesTemp;
                  uint8_t nNoUpdatesHum;
                  bool metric = true;
                  
                  MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                  MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                  
                  void presentation()  
                  { 
                    // Send the sketch version information to the gateway
                    sendSketchInfo("HTU21DF-TemperatureAndHumidity", "1.0");
                  
                    // Register all sensors to gw (they will be created as child devices)
                    present(CHILD_ID_HUM, S_HUM);
                    present(CHILD_ID_TEMP, S_TEMP);
                  }
                  
                  void setup()
                  {
                    Serial.begin(115200);
                    Serial.println("HTU21D-F test");
                  
                    if (!htu.begin()) {
                      Serial.println("Couldn't find sensor!");
                      while (1);
                      }
                  }
                  
                  void loop(){
                    // Get temperature from HTU21DF library
                    float temperature = (htu.readTemperature());
                   if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
                      // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
                      lastTemp = temperature;
                      
                      // Reset no updates counter
                      nNoUpdatesTemp = 0;
                      temperature += SENSOR_TEMP_OFFSET;
                      send(msgTemp.set(temperature, 1));
                  
                      #ifdef MY_DEBUG
                      Serial.print("T: ");
                      Serial.println(temperature);
                      #endif
                    } 
                    else {
                      // Increase no update counter if the temperature stayed the same
                      nNoUpdatesTemp++;
                    }
                  
                    // Get humidity from HTU21DF library
                    float humidity = (htu.readHumidity());
                    if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
                      // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
                      lastHum = humidity;
                      // Reset no updates counter
                      nNoUpdatesHum = 0;
                      send(msgHum.set(humidity, 1));
                  
                      #ifdef MY_DEBUG
                      Serial.print("H: ");
                      Serial.println(humidity);
                      #endif
                  }
                    else {
                      // Increase no update counter if the humidity stayed the same
                      nNoUpdatesHum++;
                    }
                  
                    // Sleep for a while to save energy
                    sleep(UPDATE_INTERVAL); 
                  }
                  
                  Y 1 Reply Last reply
                  0
                  • 4 4994james

                    @4994james
                    Hi. I have been reading https://forum.mysensors.org/topic/476/htu21d-humidity-temperature-sensor/8 and have now got this working using the adafruit htu21d library. Not sure what the difference is but there obviously is something. I also confirm that the board works without external pull up resistors. Thanks for you help.

                    This is my new (working) code:

                    /**
                     * The MySensors Arduino library handles the wireless radio link and protocol
                     * between your home built sensors/actuators and HA controller of choice.
                     * The sensors forms a self healing radio network with optional repeaters. Each
                     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                     * network topology allowing messages to be routed to nodes.
                     *
                     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                     * Copyright (C) 2013-2015 Sensnology AB
                     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                     *
                     * Documentation: http://www.mysensors.org
                     * Support Forum: http://forum.mysensors.org
                     *
                     * This program is free software; you can redistribute it and/or
                     * modify it under the terms of the GNU General Public License
                     * version 2 as published by the Free Software Foundation.
                     *
                     *******************************
                     *
                     * REVISION HISTORY
                     * Version 1.0: Andrew Sutcliffe
                     *  
                     * DESCRIPTION
                     * This sketch provides an example of how to implement a humidity/temperature
                     * sensor using a HTU21DF Sensor.
                     *  
                     * For more information, please visit:
                     * http://www.mysensors.org/build/humidity
                     * 
                     * Connect Vin to 3-5VDC
                     * Connect GND to ground
                     * Connect SCL to I2C clock pin (A5 on UNO)
                     * Connect SDA to I2C data pin (A4 on UNO)
                     * 
                     */
                    
                    // Enable debug prints
                    #define MY_DEBUG
                    
                    // Enable and select radio type attached 
                    //#define MY_RADIO_NRF24
                    //#define MY_RADIO_RFM69
                    #define MY_RS485
                    
                    // Define this to enables DE-pin management on defined pin
                    #define MY_RS485_DE_PIN 2
                    
                    // Set RS485 baud rate to use
                    #define MY_RS485_BAUD_RATE 9600
                    
                    #include <MySensors.h>  
                    #include <Wire.h>
                    #include "Adafruit_HTU21DF.h"
                    
                    Adafruit_HTU21DF htu = Adafruit_HTU21DF();
                    
                    // Set this offset if the sensor has a permanent small offset to the real temperatures
                    #define SENSOR_TEMP_OFFSET 0
                    
                    // Sleep time between sensor updates (in milliseconds)
                    
                    static const uint64_t UPDATE_INTERVAL = 60000;
                    
                    // Force sending an update of the temperature after n sensor reads, so a controller showing the
                    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
                    // the value didn't change since;
                    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
                    static const uint8_t FORCE_UPDATE_N_READS = 10;
                    
                    #define CHILD_ID_HUM 0
                    #define CHILD_ID_TEMP 1
                    
                    #define MY_NODE_ID 104
                    
                    float lastTemp;
                    float lastHum;
                    uint8_t nNoUpdatesTemp;
                    uint8_t nNoUpdatesHum;
                    bool metric = true;
                    
                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                    
                    void presentation()  
                    { 
                      // Send the sketch version information to the gateway
                      sendSketchInfo("HTU21DF-TemperatureAndHumidity", "1.0");
                    
                      // Register all sensors to gw (they will be created as child devices)
                      present(CHILD_ID_HUM, S_HUM);
                      present(CHILD_ID_TEMP, S_TEMP);
                    }
                    
                    void setup()
                    {
                      Serial.begin(115200);
                      Serial.println("HTU21D-F test");
                    
                      if (!htu.begin()) {
                        Serial.println("Couldn't find sensor!");
                        while (1);
                        }
                    }
                    
                    void loop(){
                      // Get temperature from HTU21DF library
                      float temperature = (htu.readTemperature());
                     if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
                        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
                        lastTemp = temperature;
                        
                        // Reset no updates counter
                        nNoUpdatesTemp = 0;
                        temperature += SENSOR_TEMP_OFFSET;
                        send(msgTemp.set(temperature, 1));
                    
                        #ifdef MY_DEBUG
                        Serial.print("T: ");
                        Serial.println(temperature);
                        #endif
                      } 
                      else {
                        // Increase no update counter if the temperature stayed the same
                        nNoUpdatesTemp++;
                      }
                    
                      // Get humidity from HTU21DF library
                      float humidity = (htu.readHumidity());
                      if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
                        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
                        lastHum = humidity;
                        // Reset no updates counter
                        nNoUpdatesHum = 0;
                        send(msgHum.set(humidity, 1));
                    
                        #ifdef MY_DEBUG
                        Serial.print("H: ");
                        Serial.println(humidity);
                        #endif
                    }
                      else {
                        // Increase no update counter if the humidity stayed the same
                        nNoUpdatesHum++;
                      }
                    
                      // Sleep for a while to save energy
                      sleep(UPDATE_INTERVAL); 
                    }
                    
                    Y Offline
                    Y Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #9

                    @4994james great to hear you solved it, and thanks for reporting back!

                    http://yveaux.blogspot.nl

                    1 Reply Last reply
                    0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    12

                    Online

                    12.0k

                    Users

                    11.2k

                    Topics

                    113.4k

                    Posts


                    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • MySensors
                    • OpenHardware.io
                    • Categories
                    • Recent
                    • Tags
                    • Popular