Skip to content

fix hang due to powerdown of hts221 sensor #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2019

Conversation

Rocketct
Copy link
Contributor

@Rocketct Rocketct commented Aug 8, 2019

Introducing a delay before the power off of the hts in the end function the seems that allow to fix the issue due a power cycle of the module in loop.

this change seems that allow to power down the sensor without generate the issue

the test sketch is:

#include <SPI.h>
#include <MKRENV.h>
#include <ArduinoLowPower.h>

int counter = 0;

void setup() {
  pinMode(0, OUTPUT);
    pinMode(1, OUTPUT);
}

void loop() {
  digitalWrite(1, LOW);
  if (!ENV.begin()) { 
      digitalWrite(1, HIGH);
  }
  float celsius = ENV.readTemperature();
  ENV.end();

  

  if (celsius > 0) {
    digitalWrite(0, HIGH);
    delay(1000);

    celsius = 0;
  }

  digitalWrite(0, LOW);
  delay(1000);  



//LowPower.sleep(1000);
}

with @facchinm have also check that the delay could be reduce to 50, we have choose 80 to give a higher tollerance.

cc/ @sandeepmistry @facchinm please make test, i have tested on wifi1010 + MKRENV shield

i'll try to take a look to the datasheet to check the register and sensor operation to see if compliant whit this change.

This change should be also ported on https://github.com/arduino-libraries/Arduino_HTS221/tree/master/src

@Rocketct
Copy link
Contributor Author

Rocketct commented Aug 8, 2019

UPDATE: seems that also calling two times the read like:

   float celsius = ENV.readTemperature();
   celsius = ENV.readTemperature();

rise the issue, then maybe is better move the delay on the read instead of the end.

@Rocketct Rocketct force-pushed the master branch 2 times, most recently from 1118ae6 to acfa7ae Compare August 27, 2019 10:51
Rocketct added a commit to Rocketct/Arduino_HTS221 that referenced this pull request Aug 27, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
Rocketct added a commit to Rocketct/Arduino_HTS221 that referenced this pull request Aug 27, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
@sandeepmistry
Copy link
Contributor

After some testing, I don't think this is the best solution, I found better results by added the following to the start of readTemperature() and readHumidity():

while (i2cRead(HTS221_ADDRESS, HTS221_CTRL2_REG) & 0x01);

This is based on the data sheet, section 7.4:

The ONE_SHOT bit is used to start a new conversion. In this situation a single acquisition of temperature and humidity is started when the ONE_SHOT bit is set to ‘1’. At the end of conversion the new data are available in the output registers, the STATUS_REG[0] and STATUS_REG[1] bits are set to ‘1’ and the ONE_SHOT bit comes back to ‘0’ by hardware.

What do you think?

I think we should also consider to set the CTRL_REG1 BDU bit as you mentioned in another comment.

@Rocketct
Copy link
Contributor Author

yes as discussed i think that the problem of the sensor is that we make operation while the sensor is involved in conversion operation, this should work, let me test, about the BDU yes i think too we need because:

0: continuous update; 1: output registers not updated until MSB and LSB reading)

@Rocketct
Copy link
Contributor Author

Ok works !! i'll add also the BDU

Rocketct added a commit to Rocketct/Arduino_HTS221 that referenced this pull request Aug 28, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
src/MKRENV.cpp Outdated
@@ -141,8 +147,8 @@ float ENVClass::readHumidity()

// read value and convert
int16_t hout = i2cRead16(HTS221_ADDRESS, HTS221_HUMIDITY_OUT_L_REG);

return (hout * _hts221HumiditySlope + _hts221HumidityZero);
float reading = hout * _hts221HumiditySlope + _hts221HumidityZero;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is unnecessary for the fix.

src/MKRENV.cpp Outdated
@@ -87,7 +87,7 @@ int ENVClass::begin()
readHTS221Calibration();

// enable HTS221
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should update the comment as well?

src/MKRENV.cpp Outdated
@@ -111,6 +111,9 @@ void ENVClass::end()

float ENVClass::readTemperature(int units)
{
// Wait for trigger a new read operation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are waiting here for hardware, to reset the bit to set to zero as stated in datasheet comment.

@Rocketct Rocketct force-pushed the master branch 2 times, most recently from 4a11f83 to 2d2bba9 Compare August 28, 2019 14:07
fix the hangs due to consecutive HTS221 readings
@Rocketct Rocketct merged commit 052d676 into arduino-libraries:master Aug 28, 2019
Rocketct added a commit to Rocketct/Arduino_HTS221 that referenced this pull request Aug 28, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
Rocketct added a commit to Rocketct/Arduino_HTS221 that referenced this pull request Aug 28, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
Rocketct added a commit to arduino-libraries/Arduino_HTS221 that referenced this pull request Aug 28, 2019
fix the hang issue due to consecutive reads of the temperature register

porting of arduino-libraries/Arduino_MKRENV#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants