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);
}]