Go Down

Topic: Sensirion Temp/Humidity sensor library help (Read 9 times) previous topic - next topic

novice

Quote
Can someone post their working code?

A working code library has already been published at http://github.com/practicalarduino/SHT1x/
Use the example provided.

pelletta

Hi all! I have a problem with a SHT11 sensor. I tell you my configuration: arduino duemilanove, a 2x16 lcd display, a DS1307 (RTC) and a SHT11 sensor. What I want to do is write the time given by the RTC in the first row of the display and in the second row I want to write the temperature and the humidity collected by the SHT11 sensor.  I wrote few lines of code and I saw that the time shown in the display is not accurate, in fact every minute it skips 5 or 6 seconds. I think it happens because in the library that I'm using there are some delays(). I thought so because in another project I had the same problem and I solved it changing the delay() function with millis(). In this case the delay() is in the library, not in the script, how could I fix this problem? I post a simplified version of the script I'm working on, I hope someone can help me, I'm a newbie and please excuse me if I've made some mistakes when i wrote this post, I'm italian. Here comes the script:

Quote

  #include <WProgram.h>
  #include <Wire.h>
  #include <DS1307.h>
  #include <LiquidCrystal.h>
  #include <SHT1x.h>
  #define dataPin  12
  #define clockPin 13
  SHT1x sht1x(dataPin, clockPin);
  float temp_c;
  float humidity;
  LiquidCrystal lcd(2,3,4,5,6,7,8);
  int rtc[7];
  
  void setup()
{
  RTC.stop();
  RTC.set(DS1307_SEC,1);
  RTC.set(DS1307_MIN,59);
  RTC.set(DS1307_HR,22);
  RTC.set(DS1307_DOW,2);
  RTC.set(DS1307_DATE,18);
  RTC.set(DS1307_MTH,2);
  RTC.set(DS1307_YR,9);
  RTC.start();
  lcd.begin(16,2);
  lcd.clear();
}

  void loop()

  temp_c = sht1x.readTemperatureC();
  humidity = sht1x.readHumidity();
  
  lcd.setCursor(0,0); // 1st row display
  
  RTC.get(rtc,true);
  lcd.print(rtc[2]); // hours
  lcd.print(":");
  lcd.print(rtc[1]); // minutes
  lcd.print(":");
  lcd.print(rtc[0]); // seconds
    
  lcd.setCursor(0,1); // 2nd row display
  lcd.print("T=");
  lcd.print(temp_c);
  lcd.print(" U=");
  lcd.print(humidity);  
}







novice

You've got 2 things running, the RTC & the Senirion.
Comment one out (the SHT11) & then see if the RTC works.

Use a process of elimination.

pelletta

If I comment the SHT11 code, the time runs well.

novice

You should also run the SHT11 code on its own.

Did you use the "working code library" I mentioned above?.

Go Up