3 Replies Latest reply on Jul 22, 2015 1:59 PM by Intel_Alvarado

    I2C communication with HTU21D sensor not working


      I bought a HTU21D temperature and humidity sensor by Adafruit and have been using it successfully with an Arduino micro and with an Arduino UNO using the library supplied by Adafruit. The sensor uses I2C communication


      However, I recently tried to switch to using an Intel Galileo gen 1. For some reason, when I try to use the example code ("HTU21DFTest"), I get the message "Couldn't find sensor!" The code is as follows:


      #include <Wire.h>

      #include "Adafruit_HTU21DF.h"


      // 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)


      Adafruit_HTU21DF htu = Adafruit_HTU21DF();


      void setup() {


        Serial.println("HTU21D-F test");


        if (!htu.begin()) {

          Serial.println("Couldn't find sensor!");

          while (1);




      void loop() {

        Serial.print("Temp: "); Serial.print(htu.readTemperature());

        Serial.print("\t\tHum: "); Serial.println(htu.readHumidity());




      I have tried using the SCL and SDA pins on the Galileo as well as using the A4 and A5 pins but neither way works. Is this a compatibility issue with the Wire library? Is there any way around it? Also, I'm aware that another post discussed a problem with the same sensor but this was a different problem (Re: Galileo Gen 2 i2c problem)



        • 1. Re: I2C communication with HTU21D sensor not working



          First, make sure that you are using the latest image available and the latest IDE. Make sure you are powering both the board and the sensor with proper values. Use a different power supply for the sensor. Also remember that to use I2C you need to use pull up resistors. Look at this guide Pull-up Resistors - learn.sparkfun.com for more info on pull up resistors.

          Also, I don’t think that the issue is with the Wire library, it works well on the Galileo. Take a look at HTU21D Humidity Sensor Hookup Guide - learn.sparkfun.com and make sure you’ve followed all suggestions.



          • 2. Re: I2C communication with HTU21D sensor not working

            Hi Sergio,


            Thanks for the reply. I'm using the latest image and IDE. Also, the sensor breakout has pullup resitors so I don't think I need to add any.


            I read somewhere else (Looking for I2C example) that the Wire library can only use the A4 and A5 pins for I2C so it will ignore the Galileo's labelled SDA and SCL pins. Unfortunately, I can't use the A4 and A5 pins because I need all the analogue imputs for other sensors. Also, as I mentioned, I already tried using the A4 and A5 pins but they didn't work. Is there any way I can communicate over I2C in an Arduino sketch without using the Wire library?

            • 3. Re: I2C communication with HTU21D sensor not working


              I did some tests using a logic analyzer. When I uploaded a sketch that used A4 and A5 that same signal is repeated in SCL and SDA. This sketch sends I2C data. Take a look at picture 1. This test was made connecting the logic analyzer to A4, A5, SCL and SDA.


              I also tried using a couple of potentiometers. This time in our sketch we used the analogRead function. One potentiometer was connected to A4 and the other one to A5. So we ran the logic analyzer and moved the potentiometer to see if the result would also be duplicated in the SCL and SDA pins. This sketch was not using the Wire library. This means that the signals shown in A4 and A5 are the same that show SCL and SDA.


              As a last test I did a sketch that used both analog and I2C data. The sketch was using the Wire library. When I took the samples with the logic analyzer I got the following graphic.


              As you can see, the signal is not as in the last images. The galileo tries to switch its muxing from I2C and the analog but it didn’t do any of those correctly as you can see in the graphic. This is because according to the schematic the mux reads an analog data but it is not able to send I2C simultaneously so it switches between analog and I2C producing a wrong output.


              According to this, the behavior of these signals is not because of the wire library but because of the hardware of the board itself. In this case the I2C signal share the same mux as A4 and A5. Even though you use a different library you will still see these results.