Upgraded SHT11 example

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
CSL
Posts: 3
Joined: 04 Mar 2011 23:28

Upgraded SHT11 example

#1 Post by CSL » 24 Mar 2011 16:27

Working with your SHT11 example for SHT1x additional board, we corrected several problems which we encounter.
Current version of Sensirion’s SHT1x chips is V4, which comes with different coefficient for calculation of temperature and relative humidity. Coefficients which are used in your example are probably for V3 sensors which are not soled anymore. SHT1x V3 and V4 sensors can be differentiated by code mark; V3 sensors are marked by three digit numeric code, while V4 sensors are marked by three digit alphanumeric code.

Code: Select all

// SHT1x V4 humidity conversion coefficients  (12 bits)
const unsigned int C1 = 205;             // -2.0468
const unsigned int C2 = 367;             // 0.0367  (367 * 10^-4)
const unsigned short C3 = 16;           // -1.5955* 10^-6  (15.955 * 10^-7)

// SHT1x V4 temperature compensation coefficients (12 bits)
const unsigned int T1 = 1000;            // 0.01 (1*10^-2)
const unsigned int T2 = 8;               // 0.00008  (8 * 10^-5)

// SHT1x V4 temperature conversion coefficients (14 bits)
const unsigned int D1 = 4010;            // -40.1
const unsigned short D2 = 1;             // 0.01

// Original coefficients,  probably for SHT V3 sensors
// const unsigned int C1 = 400;             // -4
// const unsigned int C2 = 405;             // 0.0405  (405 * 10^-4)
// const unsigned short C3 = 28;            // -2.8 * 10^-6  (28 * 10^-7)
// const unsigned int D1 = 4000;            // -40
// const unsigned short D2 = 1;             // 0.01
Also we added piece of code for temperature compensation (according to SHT1x datasheet) which increases accuracy of relative humidity measurement.

Code: Select all

// Temperature compensation
// RHtrue=(T-25)*(T1+T2*SOrh)+RHlin
temp=(T1+(T2*SOrh))/1000;
temp=((Ta_res-2500)*temp)/100;
Rh_res=temp+Rh_res;
Since SHT1x sensors require external pull-up resistors which are used to pull SCL and SDA lines to Vdd, originally SCL line was left as output after communication with sensor was over. Since state of RC3 pin was 0, it enabled current to flow through SCL pull-up resistor during inactive time. Resistor has dissipation of 25mW which also heats up SHT11 sensor which is in its close proximity on PCB board and adds temperature error of 1 - 2 degrees Celsius. According to Sensirion’s documents this temperature error will cause 5 – 10 % error in measurement of relative humidity. After the end of communication with SHT11 sensor, we defined SCL as input and prevent temperature error caused by heating of SCL pull-up resistor.

Code: Select all

SCL_Direction = 0;                     // define SCL as output
// Measuring temperature
SOt = Measure(0x03);             // function for measuring (command 0x03 is for temperature)
// Measuring humidity
SOrh = Measure(0x05);            // function for measuring (command 0x05 is for humidity)
SCL_Direction = 1;                     // define SCL as input
Your example was designed to display only absolute value of temperature. We modified it, so it can display both positive and negative temperatures.

Code: Select all

// Calculating temperature
// Ta_res = D1 + D2 * SOt
Ta_res = SOt * D2 - D1;        // calculate temperature

Code: Select all

// Display minus sign on LCD if temperature is negative
    if (Ta_res < 0)
       Ta[4] = '-';
We are sending you complete upgraded SHT11 example in attachment. Example is tested on EasyPIC6 with 16F887 MCU.

Best regards,
Uroš Pešović, teaching assistant
Computer Science Laboratory
Technical Faculty Čačak
Serbia
Attachments
Upgraded SHT11 example for MikroC Pro.zip
(59.85 KiB) Downloaded 1650 times

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Upgraded SHT11 example

#2 Post by tihomir.losic » 25 Mar 2011 11:37

Hello Uros,

thank you for sharing that with us.
Also, I am suggesting you to place your project on our Projects Page:
http://www.mikroe.com/eng/projects/index/
There users can view project made by users of our compilers.
Users can also post their project in order to share experience and knowledge using mikroElektronika compilers.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

prmurthy
Posts: 2
Joined: 15 Feb 2011 08:30

Re: Upgraded SHT11 example

#3 Post by prmurthy » 13 Oct 2015 18:44

Hello Uros,

I don't know if this updated code was tested or not. But I have used the same as it is for 18F4620 with GLCD and also simulated the same code compiled version of yours in 16F887. I get wrong readings in both and exactly the same error. The errors are as follows:

1. Once the sensor enter into negative and again back to positive values the minus sign still present on the display.
2. Once the sensor enter into negative reading it shows - './+ some thing like that and also keep changing as the temperature decreases. But it will never show the numbers.

I got solution for the point number 1 by passing one simple statement as follows.

if (Ta_res < 0)
Ta[4] = '-';
else Ta[4] = ' ';

But I am unable to solve the other issue which is quite strange and unable to understand. Hope you have some solution for this.

Thanks and Regards
P R M

Post Reply

Return to “mikroC PRO for PIC General”