I am interfacing the HTU21D sensor with my nodeMCU v3. All good! I managed to get some readings etc. But when I re-upload my code the device does not respond. If I remove the power supply from the pin and hard reset it, it works again. I have exactly the same problem using the Sparkfun library, so it seems more of a hardware problem. Anyone else had the same problem? link to the sparkfun library https://github.com/sparkfun/SparkFun_HTU21D_Breakout_Arduino_Library for reference, here is my code
This program interfaces the HTU21 temp/humidity sensor via I2C
*/
#include <Wire.h>
#include <Math.h>
const int HTU21_ADDR = 0x40;
const int Trigger_Temp_Measurement = 0xE3;// hold master
const int Trigger_Hum_Measurement = 0xE5; // hold master
const int Trigger_Temp = 0xF3; //No Hold Master
const int Trigger_Hum = 0xF5; //No Hold Master
int16_t Temp, Hum;//variables to store temp and humidity
int8_t TmpCrc, HumCrC;
void setup() {// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(HTU21_ADDR);
Wire.write(0xFE);
Wire.endTransmission(true);
}
void loop() {// put your main code here, to run repeatedly:
TempReading();
HumReading();
}
void TempReading() {
Wire.beginTransmission(HTU21_ADDR);
Wire.write(Trigger_Temp_Measurement);
Wire.endTransmission();
Wire.requestFrom(HTU21_ADDR, 3, true);
if (Wire.available() <= 3) {
Temp = (Wire.read() << 8) | (Wire.read() );
TmpCrc = Wire.read();
}
float TempCalc = -46.85 + (175.72 * ((float)Temp / (pow(2, 16))));
Serial.print("Temperature \t");
Serial.print(TempCalc);
//Serial.println(TmpCrc, HEX);
}
void HumReading() {
Wire.beginTransmission(HTU21_ADDR);
Wire.write(Trigger_Hum_Measurement);
Wire.endTransmission();
Wire.requestFrom(HTU21_ADDR, 3, true);
if (Wire.available() <= 3) {
Hum = (Wire.read() << 8) | (Wire.read());
HumCrC = Wire.read();
}
float HumCalc = -6 + 125 * (Hum / (pow(2, 16)));
Serial.print("\t Humidity \t");
Serial.println(HumCalc);
//Serial.println(HumCrC, HEX);
}```
loop())