Uno WiFi Rev2 & SHT31 sensor SOLVED

Arduino Uno WiFI Rev2 & SHT31 sensor

Hello All,

I am having some trouble getting data from an SHT31 temperature and humidity sensor, I am connecting the sensor as per the diagram using the SDA SCL dedicated pins (Not A4 A5) ground and 5v.

I then did ran an i2c_scanner and found the address of the sensor was 0x44, all good so I thought, I then ran the code listed at the bottom of this post, provided by DFROBOT every time I run it I get "Failed to Initialize the chip, please confirm the wire connection"

I then Added

[

#include <Wire.h>

setup(){

    Wire.begin();

}

]

To the code listed below, this still did not work.

I tried adding 4R7 resistors connected to the SCA SCL and +5v as pullup, and still nothing.

I then changed the Arduino Uno Wifi Rev2, to a Uno MK3 connected the same way with the same code, minus the resistors and it worked stright away.

I am guessing its something to do with the I2C but I have no clue how to fix this to be used on the Uno WiFi Rev2, as I need to be able to eventually need to send the data via MQTT any ideas would be gladly received

[

#include <DFRobot_SHT3x.h>

/*!

 * @brief Construct the function

 * @param pWire I2C bus pointer object and construction device, both can pass or not pass parameters,

 * Wire in default.

 * @param address Chip I2C address, two optional addresses 0x44 and 0x45(0x45 in default).

 * @param RST RST Chip reset pin, 4 in default.

 * @n I2C address is determined by the pin addr on the chip.

 * @n When the ADR is connected to VDD, the chip I2C address is 0x45.

 * @n When the ADR is connected to GND, the chip I2C address is 0x44.

 */

DFRobot_SHT3x sht3x(&Wire,/*address=*/0x44,/*RST=*/4);

//DFRobot_SHT3x   sht3x;

void setup() {

  Serial.begin(9600);

  //Initialize the chip

  while (sht3x.begin() != 0) {

    Serial.println("Failed to Initialize the chip, please confirm the wire connection");

    delay(1000);

  }

  /**

   * readSerialNumber Read the serial number of the chip.

   * @return Return 32-digit serial number.

   */

  Serial.print("Chip serial number");

  Serial.println(sht3x.readSerialNumber());

  /**

   * softReset Send command resets via I2C, enter the chip's default mode single-measure mode,

   * turn off the heater, and clear the alert of the ALERT pin.

   * @return Read the register status to determine whether the command was executed successfully,

   * and return true indicates success.

   */

   if(!sht3x.softReset()){

     Serial.println("Failed to Initialize the chip....");

   }

  /**

   * heaterEnable(): Turn on the heater inside the chip to enable the sensor get correct humidity value in wet environments.

   * @return Read the status of the register to determine whether the command was executed successfully,

   * and return true indicates success.

   * @note Heaters should be used in wet environments, and other cases of use will result in incorrect readings

   */

  //if(!sht3x.heaterEnable()){

  // Serial.println("Failed to turn on the heater....");

  //}

  Serial.println("------------------Read adta in single measurement mode-----------------------");

}

void loop() {

  Serial.print("Ambient Temperature(°C/F):");

  /**

   * getTemperatureC Get the meansured temperature(℃).

   * @return Return float temperature data.

   */

  Serial.print(sht3x.getTemperatureC());

  Serial.print(" C/");

  /**

   * getTemperatureF:Get the meansured temperature(℉).

   * @return Return float temperature data.

   */

  Serial.print(sht3x.getTemperatureF());

  Serial.print(" F ");

  Serial.print("Relative Humidity(%RH):");

  /**

   * getHumidityRH: Get the meansured humidity (%RH)

   * @return Return float humidity data

   */

  Serial.print(sht3x.getHumidityRH());

  Serial.println(" %RH");

  /**

   * @brief Get temperature and humidity data in single measurement mode.

   * @param repeatability Set repeatability to read temperature and humidity data with the type eRepeatability_t.

   * @note  Optional parameters:

               eRepeatability_High /**In high repeatability mode, the humidity repeatability is 0.10%RH, the temperature repeatability is 0.06°C

               eRepeatability_Medium,/**In medium repeatability mode, the humidity repeatability is 0.15%RH, the temperature repeatability is 0.12°C.

               eRepeatability_Low, /**In low repeatability mode, the humidity repeatability is0.25%RH, the temperature repeatability is 0.24°C

   * @return Return a structure containing celsius temperature (°C), Fahrenheit temperature (°F), relative humidity(%RH), status code.

   * @n Return O indicates right data return.

  DFRobot_SHT3x::sRHAndTemp_t data = sht3x.readTemperatureAndHumidity(sht3x.eRepeatability_High);

  if(data.ERR == 0){

    Serial.print("Ambient Temperature(°C/F):");

    Serial.print(data.TemperatureC);

    Serial.print(" C/");

    Serial.print(data.TemperatureF);

    Serial.print(" F ");

    Serial.print("Relative Humidity(%RH):");

    Serial.print(data.Humidity);

    Serial.println(" %RH");

  }

  */

  delay(1000);

}]

I came to the post expecting it to be the A4/A5 issue, but you're way ahead of me there!

The only suggestion I have, which is not a very great one, is to check around for other libraries for this sensor and try them out. I get lucky that way fairly often.

Even though it's best to understand the real cause of something working, I find that often finding a working and a non-working state is the best start to that investigation. After that, you only need to figure out what is the difference between the two states and that leads you to the cause of the non-working behavior.

It's strange that it works on the mk3, I have read that this may be a problem with the I2C and the ATMEGA4829 architecture, but that's beyond me!

Solved

After a lot of googling and having friends in high places, I have found a solution.

It seems the way the I2C Library writes to the registry on the Uno Wifi Rev2 is different to the Uno Rev3,

not just that but it seems to boil down to a file in the Wire.h Library called OneWire_direct_gpio.h
that will not work with the Uno Wifi Rev2 ATmega4809 architecture.

The solution is using Bit banging i2c lib with a custom Addafruit_SHT31 library a friend made for me attached to this post. The SDA pin will be pin 13 and the SCL pin 12 on the Uno Wifi Rev2

Good luck

BB_Adafruit_SHT31-master.zip (426.2 KB)
BitBang_I2C-2.1.3.zip (25.8 KB)

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.