electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Temprature measurement with SHT11 sensor


Goto page Previous  1, 2, 3  Next
Post new topic  Reply to topic    EDAboard.com Forum Index -> Robotics and Automatics Forum -> Temprature measurement with SHT11 sensor
Author Message
gricesj



Joined: 10 Jan 2005
Posts: 6


Post10 Jan 2005 16:17   

jonathan avr sht11


Hello,

I am currently designing a microprocessor contolled parrot incubator. I am using the SHT15 sensor (the SHT11 is out of stock), the ATMEL ATMega8 micro-controller, and the LM016L (2x16) LCD display. The trouble is I have never had to programme before and have no clue on how to write the code for the micro-controller. Please Help!

I was hoping someone could provide me with the AVR code which would interface the SHT15 with the ATMega8, and then output it to the LCD. By looking at the picture of the LCD on the first link, the connections are identical to the LM016L LCD.

Any help offered would be VERY MUCH appreciated! I can't afford to buy a proper incuabtor, they are way too expensive!

Many thanks indeed,

Steve.
E-mail: captaingrice(at)blueyonder.co.uk.
Back to top
mgajo



Joined: 15 May 2001
Posts: 347


Post14 Jan 2005 23:04   

sensirion et picbasic


Hi
Take a look at w_w.fastavr.com
they have code for avr and sht11, also Bascom AVR site.
Hope this will help, but sht11 is difficult sensor to start with

anyway wish you luck
Back to top
gricesj



Joined: 10 Jan 2005
Posts: 6


Post17 Jan 2005 22:21   

sht11 source code


Hi, thanks for the reply.

The trouble is, I have to do it in assembly code, using the AVR Studio 3.56. So far I have my 2x16 display outputting a user defined sentence, in my case, I've put in "Roll on Easter, 11 weeks to go"

My code so far is:

--------------------------

.include "m8def.inc"

.def temp =r16
.def disp =r17
.equ width =$00dd


;********************************************************
.equ LCD_O =portd ;Output to LCD
.equ LCD_I =pinb ;Input from LCD
.equ CTRL_O =portc ;Control output
.equ E =2 ;Active high enable
.equ DC =0 ;Data/Command
.equ BF =7 ;Busy Flag
.equ FS =$3f ;Function set
.equ DISP_ON =$0c ;Display on w/o blink or flash
.equ DISP_OFF =$08 ;Display, blink, cursor off
.equ DISP_CL =$01 ;Clear display
.equ DISP_EN =$06 ;Data entry mode
.equ LINE_1 =$80 ;DDRAM address for first line
.equ LINE_2 =$c0 ;DDRAM address for second line
.equ SH_LFT =$18 ;Left-shift display
.equ SH_RT =$1c ;Right-shift display
.equ HOME =$02 ;Return home
;********************************************************


reset: ldi temp, low(ramend)
out SPL, temp
ldi temp, high(ramend)
out SPH, temp

ser temp
out DDRB, temp
out DDRC, temp
out DDRD, temp

;rjmp pwm
rcall lcd_en
rcall del
rcall del
rcall del
rcall del
rcall del
ldi zl, low(Steve*2)
ldi zh, high(Steve*2)
loop2: lpm disp, z+
cpi disp, $ff
breq label
rcall wrt_d
rcall del
rjmp loop2

label: ldi disp, Line_2
rcall wrt_c
ldi zl, low(date*2)
ldi zh, high(date*2)
loop: lpm disp, z+
cpi disp, $ff
breq pwm
rcall wrt_d
rcall del
rjmp loop

;*********************************
pwm: ldi temp, $a1
out TCCR1A, temp
ldi temp, high(width)
out OCR1AH, temp
out OCR1BH, temp
ldi temp, low(width)
out OCR1AL, temp
out OCR1BL, temp
ldi temp, $01
out TCCR1B, temp


here: rjmp here


;********************************************************
;Set up lcd
LCD_EN: rcall del
rcall del
rcall del
rcall del
ldi disp, FS
rcall wrt_c
rcall wrt_c
rcall wrt_c
rcall wrt_c
rcall del
rcall del
ldi disp, DISP_ON
rcall wrt_c
ldi disp, DISP_EN
rcall wrt_c
ldi disp, DISP_CL
rcall wrt_c
rcall del
rcall del
ret
;********************************************************

;********************************************************
;Writes the command in the 'disp' register to the LCD.
wrt_c: rcall del
cbi CTRL_O, DC
sbi CTRL_O, E
out LCD_O, disp
cbi CTRL_O, E
ret
;********************************************************
;Writes data in the 'disp' register to the LCD.
wrt_d: rcall del
sbi CTRL_O, DC
sbi CTRL_O, E
out LCD_O, disp
cbi CTRL_O, E
ret
;********************************************************

;********************************************************
;64us delay using 8-bit timer
del: push temp
ldi temp, $df
out TCNT0, temp
ldi temp, $02
out TCCR0, temp
dloop: in temp, TIFR
andi temp, $01
cpi temp, $01
breq cflg
cpi temp, $08
brne dloop
cflg: ldi temp, $01
out TIFR, temp
clr temp
out TCCR0, temp
pop temp
ret
;********************************************************

Steve: .db "ROLL ON EASTER--",$ff,$ff
date: .db "11 WEEKS TO GO!!",$ff

------------------
The PWM is to control power resistors which I am using as a heater. The code you pointed me in the direction os great, but its in BASIC. I have to do it in assembly language. Can that code be converted to Assembly? If so, how?

Can you help me please? I don't have a clue! By the way, this code is not mine, it was given to me by someone - please dont think I can program :0).

Anyway, I hope you can help.

Many thanks,
Steve (captaingrice(at)blueyonder.co.uk)
Back to top
SAR



Joined: 25 Sep 2002
Posts: 152
Helped: 4


Post18 Jan 2005 1:41   

sht71 code disassembly


Talk to Steve Hageman at: http://www.analoghome.com/projects/dewpointer.html

He will give you the code and you can adapt it to the AVR micro. His code is for the pic. His code using CCS C compiler.
Back to top
jobla



Joined: 19 Jan 2005
Posts: 4


Post19 Jan 2005 11:22   

sht11 with cvavr


Hello,
i wrote code for the sht-11 using avr-gcc some time ago.
Perhaps it will help you. I put the code below, like it is.
That means the comments are in german and there are some
missing code-parts (helper-functions like delay) and some parts
not necessary (because it was intended to run two of these sensors on
different inputs).
If this is a problem, tell me, and i will translate it.
Furthermore i do not garantie error-freeness.
Greets,

J. B.



Sorry, but you need login in to view this attachment

Back to top
gricesj



Joined: 10 Jan 2005
Posts: 6


Post19 Jan 2005 15:14   

sht11 winavr


JB,

Many thanks, can I ask as Im not familiar with programming, is this Assembly language?

If you have the time to translate into English that would be great!

Thank you very much indeed for your help, I really appreciate it.

Steve.
Back to top
jobla



Joined: 19 Jan 2005
Posts: 4


Post20 Jan 2005 12:58   

sht15 pic source


Hi Steve,

i added some comments and translated the existing ones to english. The programming-language is C. Good Luck Smile

Johann



Sorry, but you need login in to view this attachment

Back to top
jobla



Joined: 19 Jan 2005
Posts: 4


Post20 Jan 2005 13:09   

code avr sht11


addon: i know you need the assembly, but i have only the C-sources. The only thing i can do for you is to give you the disassembled C-Code. But disassembled C-Code isn't too easy to read. If it helps, here it is:


Sorry, but you need login in to view this attachment

Back to top
rolemodel



Joined: 30 Mar 2005
Posts: 2


Post30 Mar 2005 18:17   

cvavr sht11


Hi i'm need help with my project , i'm building a device that read temp and humidity , i use a pic16f84 and a sht11 sencor also my device has a lcd display , please some one can help me with the source code for the pic , of any thing that can help me
Back to top
gricesj



Joined: 10 Jan 2005
Posts: 6


Post30 Mar 2005 19:03   

sht11 pic basic


Do you have to use the pic16f84? And what language do you have to program in?

Steve
Back to top
rolemodel



Joined: 30 Mar 2005
Posts: 2


Post06 Apr 2005 18:50   

sht11 pic16f84


gricesj wrote:
Do you have to use the pic16f84? And what language do you have to program in?

Steve
hi i have to program in C , my progam is pic c compiler , if you can help me , my email is kuku41(at)hotmail.com
Back to top
vadlimus



Joined: 22 May 2005
Posts: 1


Post22 May 2005 12:30   

picbasic sht11


hello

anyone can help me with a schematic for connecting sht11 with an AVR Atmega8 and seding results to a PC using USB. I would appreciate some links or advices. I have to do a project with this subject and I can't find anything with usb,atmel and sht11 together. And program in C....

Thank you in advance
vadlimus(at)yahoo.com
Back to top
frederic



Joined: 03 Jun 2005
Posts: 1


Post03 Jun 2005 15:05   

sth11 sensor


Hi Everyone,

I am currently trying to set up communication between the SHT71 sensor and a PIC18F452 microcontroller. I cant receive any data from the sensor. Please does anyone have an example code using a similar a similar microcontroller with the MPLAB C18 compiler. That would be extremely helpful.

THANK U VERY MUCH

FREDERIC
Back to top
Kripton2035



Joined: 19 Jul 2001
Posts: 587
Helped: 20
Location: Earth


Post09 Jul 2005 14:47   

sht11 atmel


the code I gave at the previous page is for pic 16f876 and sht11 written in ccs c
it should not be a big work to translate it (if either it needs it !!!) to 18f452, sht71 and mplab c18 !!!!!!
Back to top
willie



Joined: 27 Mar 2006
Posts: 3


Post28 Mar 2006 12:21   

bascom float to string


asena wrote:
And i have it for Microchips C18.
It works very well with the 18F series.

asena


Could somebody maybe post some code snippets for the C18.
Back to top
vlad2007



Joined: 29 Mar 2006
Posts: 2


Post29 Mar 2006 13:58   

pic basic sht11


willie wrote:
asena wrote:
And i have it for Microchips C18.
It works very well with the 18F series.

asena


Could somebody maybe post some code snippets for the C18.


Hi

do you managed to read the sht11 sensor using the mplap c18 compiler? I have a Pic18f4550 and I am trying for 2 long days to comunicate with the sensor but it`s not working. I tryed to rewrite ccs code and even the c code form the sensirion web site but it still doesn`t work.

If you succeed this issue using c18, please let me now. Even if not, maybe we can still keeping touch.

Thanks,
Vlad
Back to top
willie



Joined: 27 Mar 2006
Posts: 3


Post29 Mar 2006 16:34   

sht11 sensör


vlad2007 wrote:
willie wrote:
asena wrote:
And i have it for Microchips C18.
It works very well with the 18F series.

asena


Could somebody maybe post some code snippets for the C18.


Hi

do you managed to read the sht11 sensor using the mplap c18 compiler? I have a Pic18f4550 and I am trying for 2 long days to comunicate with the sensor but it`s not working. I tryed to rewrite ccs code and even the c code form the sensirion web site but it still doesn`t work.

If you succeed this issue using c18, please let me now. Even if not, maybe we can still keeping touch.

Thanks,
Vlad


Hi Vlad!
I will use the sht75, but I thing this will make not a big different.
This week I will try to find time to wirte some first comunication code (wiht mpl c18).
I will report my progress.


Willie
Back to top
vlad2007



Joined: 29 Mar 2006
Posts: 2


Post01 Apr 2006 8:05   

sht11 picbasic pro


Hi Willie!

I finally succeded to comunicate with the sht11 sensor. I attached the working code. Let me know how it works with your SHT75. Do you know where I can find the ftoa.c library, used to convert float numbers to ASCII ? In this example I used a trick to show the read values with two digits.

Thanks,
Vlad



Sorry, but you need login in to view this attachment

Back to top
willie



Joined: 27 Mar 2006
Posts: 3


Post02 Apr 2006 14:21   

tuckca


Hi!
I will try you code!

ftoa :


http://forum.microchip.com/tm.aspx?m=141613&mpage=1&key=float&#141752


Tracy Kuhrt
Moderator


To answer the question--No, MPLAB C18 does not yet support floating-point with the standard output functions (e.g., printf, sprintf). I believe there was a post on this recently that pointed to another thread that gave example code.

...



http://forum.microchip.com/tm.aspx?m=55402&mpage=1&key=sprintf&# :

I also have a sprintf routine if anyone is interested.

/*******************************************************************
* FUNCTION: ftoa
* AUTHOR = TRAMPAS STERN
* FILE = strio.c
* DATE = 2/6/2003 4:27:14 PM
*
* PARAMETERS: long,*str, int count
*
* DESCRIPTION: Convets an float to string
* format 'f', 'E', or 'e'
*
*
* RETURNS:
*
* NOTE this code was found on the web and modified to actually work
*******************************************************************/
int ftoa (float x, CHAR *str, char prec, char format)
{

int ie, i, k, ndig, fstyle;
double y;
CHAR *start;

start=str;

//based on percission set number digits
ndig=prec+1;
if (prec<0)
ndig=7;
if (prec>22)
ndig=23;

fstyle = 0; //exponent 'e'
if (format == 'f' || format == 'F')
fstyle = 1; //normal 'f'
if (format=='g' || format=='G')
fstyle=2;

ie = 0;
/* if x negative, write minus and reverse */
if ( x < 0)
{
*str++ = '-';
x = -x;
}

//if (x<0.0) then increment by 10 till betwen 1.0 and 10.0
if (x!=0.0)
{
while (x < 1.0)
{
x =x* 10.0;
ie--;
}
}

//if x>10 then let's shift it down
while (x >= 10.0)
{
x = x*(1.0/10.0);
ie++;
}

if (ABS(ie)>MAX_MANTISA)
{
if (fstyle==1)
{
fstyle=0;
format='e';
//ie=2;
}
}


/* in f format, number of digits is related to size */
if (fstyle)
ndig =ndig + ie;

if(prec==0 && ie>ndig && fstyle)
{
ndig=ie;
}

/* round. x is between 1 and 10 and ndig will be printed to
right of decimal point so rounding is ... */
y=1;
for (i = 1; i < ndig; i++) //find lest significant digit
y = y *(1.0/10.0); //multiply by 1/10 is faster than divides

x = x+ y *(1.0/2.0); //add rounding

/* repair rounding disasters */
if (x >= 10.0)
{
x = 1.0;
ie++;
ndig++;
}

//check and see if the number is less than 1.0
if (fstyle && ie<0)
{
*str++ = '0';
if (prec!=0)
*str++ = '.';
if (ndig < 0)
ie = ie-ndig; /* limit zeros if underflow */
for (i = -1; i > ie; i--)
*str++ = '0';
}

//for each digit
for (i=0; i < ndig; i++)
{
float b;
k = x; //k = most significant digit
*str++ = k + '0'; //output the char representation
if (((!fstyle && i==0) || (fstyle && i==ie)) && prec!=0)
*str++ = '.'; //output a decimal point
b=(float)k;
//multiply by 10 before subtraction to remove
//errors from limited number of bits in float.
b=b*10.0;
x=x*10.0;
x =x - b; //subtract k from x
//b=x+b;
//x =x* 10.0; //get next digit
}

/* now, in estyle, put out exponent if not zero */
if (!fstyle && ie != 0)
{
*str++ = format;
if (ie < 0) //if number has negative exponent
{
ie = -ie;
*str++ = '-';
}

//now we need to convert the exponent to string
for (k=1000; k>ie; k=k/10); //find the decade of exponent

for (; k > 0; k=k/10)
{
char t;
t=DIV(ie,k);
*str++ = t + '0';
ie = ie -(t*k);
}

}
*str++ = '\0';
return (str-start); //return string length
}
Back to top
abihasan



Joined: 06 Mar 2006
Posts: 1


Post01 May 2006 4:36   

how to read sht11 using pic16f84


my name thedy,
i have a problem interfacing SHT11 and atmega8535,i'am using winAVR to make a program and to compile it, when i read Mr. Jobla file "sht11.pdf" i think i can use it, but the problem is, there is an include that i cannot found....
there is :
#include "ssb_sensor.h"
#include "ssb_magic_number.h"

so, since i cannot found it, i cannot use it to my project...
anybody can help me how to solve this problem???
Back to top
Google
AdSense
Google Adsense




Post01 May 2006 4:36   

Ads




Back to top
fatihpenbe



Joined: 04 Jun 2006
Posts: 1


Post04 Jun 2006 14:36   

sht11 control bascom-avr


does anyone have the schematics and source codes? can u send it to me. thanks in advance...
Back to top
meiling9



Joined: 02 May 2007
Posts: 1


Post02 May 2007 11:46   

pic basic sht


i have acquired several SHT15 sensors and i am using them to monitor temperature gradients inside a room. i am already able to retrieve data and convert them to actual values. the problem i have is i observe fluctuations of almost +/-6degC in the readings. is this normal even though i can not think of anything that might cause this sharp rise? i sample every 15seconds.

here's a sample of several datapoints i have:

counter, LM35, SHT15

...
12,22.070, 33.160
13,22.119, 33.200
14,22.119, 26.960
15,22.070, 25.720
16,22.070, 25.080
17,22.070, 31.000
18,22.070, 25.720
19,22.021, 24.840
20,22.021, 30.720
21,22.021, 31.760



thank you.
Back to top
kicco



Joined: 03 May 2007
Posts: 1


Post04 May 2007 0:05   

atmega ftoa


sorry i m new i would know how send a float number into a 16x2 lcd using st7 micro
with c code.
for esemple if the result of temperature is 76.58 i would display the same number in the lcd.
i wait for help.

yankinibra(at)hotmail.com
Back to top
gpakos



Joined: 04 Apr 2008
Posts: 7


Post04 Apr 2008 18:18   

sht11 sensor eur


Hello all,

I am very new to this forum as you can see from my post number!

I have noticed that the date of these messages is a bit old, but i would appreciate you help.

Did anyone manage to attach the SHT11 humidity sensor to his circuit?

I want to interface the SHT11 with a PIC and and LCD.

If someone can, is it possible to attach the schematics and the source code for me?

I prefer the code to be in assembly (.asm)

Thank u for your time
Back to top
london_bet



Joined: 16 Jun 2008
Posts: 1


Post06 Jul 2008 21:46   

sht11 avr asm


does anyone have a report after they fınıshed their projects or kind of similar jobs.I m gonna write a report for SHT11 and PİC 16F84 temperature and humıdıty measurement and ı m looking for a predone report whıch could be very helpful.Please contact me by thıs email:

nip-tuckca(at)hotmail.com

thanks alot
Back to top
crocu



Joined: 16 Oct 2008
Posts: 12


Post02 Dec 2008 10:49   

pic18 sht11 code


Hello,

I'm also looking for a code ( C18 prefered ) to get a SHT75 or 11 working with a PIC 18Fxxxx.

It would be great to display result on regular LCD display and also send value to Pic USART port.

Has someone a such project working ?
I will really appreciate if you can share your code

Many thanks,
Back to top
amitumi1003



Joined: 08 Apr 2009
Posts: 3


Post08 Apr 2009 9:20   

sht11 jyp


i have some prob.i alwayes getting the same valu.even i change temp or hum code.

pls help me


#include<18F8720.h>
#include <math.h>
#include<stdlib.h>


typedef union
{
unsigned int i;
float f;
} value;


#byte PORT_G =0x00FD
#byte PORT_f =0x0000
#byte PORT_c =0x00BF
#byte PORT_D = 0x0000
#byte PORT_E = 0x0002
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600,rcv=PIN_G2, xmit=PIN_G1, STREAM = COMM_B)


enum {TEMP,HUMI};
#define sht11_data PIN_F2
#define sht11_sck PIN_F3
#define sht_noACK 0
#define sht_ACK 1

//adr command r/w
#define sht_STATUS_REG_W 0x06 //000 0011 0
#define sht_STATUS_REG_R 0x07 //000 0011 1
#define sht_MEASURE_TEMP 0x03 //000 0001 1
#define sht_MEASURE_HUMI 0x05 //000 0010 1
#define sht_RESET 0x1e //000 1111 0




/********************************************************************************/
/********************************************************************************/

//Send the calculated data to the pc

/********************************************************************************/
/********************************************************************************/

void sendDataToPC(char *data,int len)
{
int i;
output_high(PIN_G0);
delay_ms(10);//wait

for(i=0;i<len;i++)
{
fprintf(COMM_B,"%c",*data);// write in the file
data++;
}
delay_ms(10); //wait
output_low(PIN_G0);
delay_ms(10);
}


int checkLength(int value)
{
int len=0;
while(value!=0)
{
value=value/10;
len++;
}
return len;
}


void floatToInt(double value)
{
int a,rem,len=0,lent;
char arr[5];
char *data,temp;
double d=100.0;
a=abs(value);
len=checkLength(a);
lent=len;
while(a!=0)
{
rem=a%10;
arr[len-1]=rem+48;
a=a/10;
len--;
}
data=arr;
sendDataToPC(data,lent);

temp='.';
sendDataToPC(&temp,1);

a=abs(value);
value=value-a;
value=value*d;
a=abs(value)+1;
len=checkLength(a);
lent=len;
while(a!=0)
{
rem=a%10;
arr[len-1]=rem+48;
a=a/10;
len--;
}
data=arr;
sendDataToPC(data,lent);
temp=' ';
sendDataToPC(&temp,2);
}




/*******************************************************************************/
/*******************************************************************************/

// writes a byte on the Sensibus and checks the acknowledge

/*******************************************************************************/
/*******************************************************************************/
char sht11_write_byte(unsigned char value)
{
unsigned char i,error=0;
for (i=0x80;i>0;i/=2) //shift bit for masking
{
if (i & value)
output_high(sht11_data); //masking value with i , write to SENSI-BUS
else
output_low(sht11_data);

output_high(sht11_sck); //clk for SENSI-BUS
delay_us( 5); //pulswith approx. 5 us
output_low(sht11_sck);
}
output_high(sht11_data); //release DATA-line
output_high(sht11_sck); //clk #9 for ack
error=input(sht11_data) ; //check ack (DATA will be pulled down by SHT11)
output_low(sht11_sck);
return error; //error=1 in case of no acknowledge
}



/********************************************************************************/
/********************************************************************************/

// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"

/********************************************************************************/
/********************************************************************************/
char sht11_read_byte(unsigned char ack)
{
unsigned char i,val=0;
output_high(sht11_data); //release DATA-line
for (i=0x80;i>0;i/=2) //shift bit for masking
{
output_high(sht11_sck); //clk for SENSI-BUS
if (input(sht11_data)==1)
val=(val | i); //read bit
output_low(sht11_sck);
}
output_bit(sht11_data,!ack); //in case of "ack==1" pull down DATA-Line
output_high(sht11_sck); //clk #9 for ack
delay_us( 5); //pulswith approx. 5 us
output_low(sht11_sck);
output_high(sht11_data); //release DATA-line
return val;
}



/********************************************************************************/
/********************************************************************************/

// generates a transmission start
// _____ ________
// DATA: |_______|
// ___ ___
// SCK : ___| |___| |______

/********************************************************************************/
/********************************************************************************/
void sht11_transstart(void)
{
output_high(sht11_data);
output_low(sht11_sck); //Initial state
delay_us( 1);
output_high(sht11_sck);
delay_us( 1);
output_low(sht11_data);
delay_us( 1);
output_low(sht11_sck);
delay_us( 3);
output_high(sht11_sck);
delay_us( 1);
output_high(sht11_data);
delay_us( 1);
output_low(sht11_sck);
}




/********************************************************************************/
/********************************************************************************/

// communication reset: DATA-line=1 and at least 9 SCK cycles
// followed by transstart
// _____________________________________________________ ________
// DATA: |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______

/********************************************************************************/
/********************************************************************************/

void sht11_connectionreset(void)
{
unsigned char i;
output_high(sht11_data);
output_low(sht11_sck); //Initial state
for(i=0;i<9;i++) //9 SCK cycles
{
output_high(sht11_sck);
output_low(sht11_sck);
}
sht11_transstart(); //transmission start
}




/********************************************************************************/
/********************************************************************************/

// resets the sensor by a softreset

/********************************************************************************/
/********************************************************************************/
char sht11_softreset(void)
{
unsigned char error=0;
sht11_connectionreset(); //reset communication
error+=sht11_write_byte(sht_RESET); //send RESET-command to sensor
return error; //error=1 in case of no response form the sensor
}





/********************************************************************************/
/********************************************************************************/

// reads the status register with checksum (8-bit)

/********************************************************************************/
/********************************************************************************/
char sht11_read_statusreg()
{
unsigned char error=0;
unsigned char p_value,p_checksum;
sht11_transstart(); //transmission start
error=sht11_write_byte(sht_STATUS_REG_R); //send command to sensor
p_value=sht11_read_byte(sht_ACK); //read status register (8-bit)
p_checksum=sht11_read_byte(sht_noACK); //read checksum (8-bit)
return error; //error=1 in case of no response form the sensor
}




/********************************************************************************/
/********************************************************************************/

// writes the status register with checksum (8-bit)

/********************************************************************************/
/********************************************************************************/

char sht11_write_statusreg(unsigned char *p_value)
{
unsigned char error=0;
sht11_transstart(); //transmission start
error+=sht11_write_byte(sht_STATUS_REG_W);//send command to sensor
error+=sht11_write_byte(*p_value); //send value of status register
return error; //error>=1 in case of no response form the sensor
}





/********************************************************************************/
/********************************************************************************/

// makes a measurement (humidity/temperature) with checksum

/********************************************************************************/
/********************************************************************************/
char sht11_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
{
unsigned error=0;
unsigned int i;
sht11_transstart(); //transmission start
switch(mode)
{ //send command to sensor
case TEMP : error+=sht11_write_byte(sht_MEASURE_TEMP); break;
case HUMI : error+=sht11_write_byte(sht_MEASURE_HUMI); break;
default : break;
}

for (i=0;i<65535;i++)
if(input(sht11_data)==0)
break; //wait until sensor has finished the measurement
if(input(sht11_data)==1)
error+=1; // or timeout (~2 sec.) is reached

*(p_value+1) =sht11_read_byte(sht_ACK); //read the first byte (MSB)
*(p_value)=sht11_read_byte(sht_ACK); //read the second byte (LSB)
*p_checksum =sht11_read_byte(sht_noACK); //read checksum
return error;
}




char sht11_measure_temp(unsigned char *p_value, unsigned char *p_checksum)
{
return sht11_measure( p_value, p_checksum, TEMP);
}

char sht11_measure_humi(unsigned char *p_value, unsigned char *p_checksum)
{
return sht11_measure( p_value, p_checksum, HUMI);
}



/********************************************************************************/
/********************************************************************************/

// calculates temperature [°C] and humidity [%RH]
// input : humi [Ticks] (12 bit)
// temp [Ticks] (14 bit)
// output: humi [%RH]
// temp [°C]

/********************************************************************************/
/********************************************************************************/
void sth11_calc(float *p_humidity ,float *p_temperature)
{
const float C1=-4.0; // for 12 Bit
const float C2=+0.0405; // for 12 Bit
const float C3=-0.0000028; // for 12 Bit
const float T1=+0.01; // for 14 Bit @ 5V
const float T2=+0.00008; // for 14 Bit @ 5V

float rh,t,rh_lin,rh_true,t_C;
// rh_lin: Humidity linear
// rh_true: Temperature compensated humidity
// t_C : Temperature [°C]
rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit
t=*p_temperature; // t: Temperature [Ticks] 14 Bit

t_C=t*0.01 - 40; //calc. temperature from ticks to [°C]
rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]
rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]

if(rh_true>100)
rh_true=100; //cut if the value is outside of
if(rh_true<0.1)
rh_true=0.1; //the physical possible range

*p_temperature=t_C; //return temperature [°C]
*p_humidity=rh_true; //return humidity[%RH]
}



/********************************************************************************/
/********************************************************************************/

// calcul de l'humidite en entier (sans calcul float)

/********************************************************************************/
/********************************************************************************/
int sht11_calc_humid_int( int16 w_humidity)
{
int32 h1,h2;

h1 = ((int32) w_humidity) * ((int32) w_humidity);
h1 = h1 / (int32)1000;
h1 = h1 * (int32)28;
h2 = ((int32) w_humidity) * (int32)405;
h2 = h2 - h1;
h2 = h2 / (int32)1000;
h2 = h2 - (int32)40;
h2 = h2 / (int32)10;
return (h2);
}


/********************************************************************************/
/********************************************************************************/

// calculates dew point
// input: humidity [%RH], temperature [°C]
// output: dew point [°C]

/********************************************************************************/
/********************************************************************************/
float sht11_calc_dewpoint(float h,float t)
{
float logEx,dew_point;
logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
return dew_point;
}





/*********************************************************************************/
/*********************************************************************************/
//----------------------------------------------------------------------------------
// sample program that shows how to use SHT11 functions
// 1. connection reset
// 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
// 3. calculate humidity [%RH] and temperature [.C]
// 4. calculate dew point [.C]
// 5. print temperature, humidity, dew point
/**********************************************************************************/
/**********************************************************************************/

void main()
{
value humi_val,temp_val;
float dew_point;
unsigned char error,checksum,temp;
sht11_connectionreset();
while(1)
{
error=0;
error+=sht11_measure((unsigned char*) &humi_val.i,&checksum,HUMI); //measure humidity
error+=sht11_measure((unsigned char*) &temp_val.i,&checksum,TEMP); //measure temperature
if(error!=0)
sht11_connectionreset(); //in case of an error: connection reset
else
{
humi_val.f=(float)humi_val.i; //converts integer to float
temp_val.f=(float)temp_val.i; //converts integer to float
sth11_calc(&humi_val.f,&temp_val.f); //calculate humidity, temperature
dew_point=sht11_calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
//send final data to serial interface (UART)
//printf(“temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n”,temp_val.f,humi_val.f,dew_point);
//sendDataToPC(temp_val.f,0x04);
//sendDataToPC(humi_val.f,0x04);
//sendDataToPC(dew_point,0x04);*/
floatToInt(temp_val.f);
floatToInt(humi_val.f);
floatToInt(dew_point);
floatToInt(error);

}
//----------wait approx. 0.8s to avoid heating up SHTxx------------------------------
delay_ms(1000);
temp='\r';
sendDataToPC(&temp,1);
//temp='\n';
//sendDataToPC(&temp,1);
}
}



help me pls
Back to top
dhika-rock



Joined: 29 Apr 2009
Posts: 2


Post30 Apr 2009 10:53   

sht11 assembly code


hai..
i need help..
this is for my final assignment.. please..
i need C language for SHT11 .. i use CodeVision Compiler and Atmega 8535..
thank you

Added after 32 minutes:

hai kripton..

i tried your link..
but i have problem..
there are many errors..
it says :

"cannot open #include file:AT89s53"
"unindified symbol P1_1"
"unindified Symbol P1_0"
"undindified symbol nop"

i know that has already #define DATA P1_1
#define SCK P1_0

i use CodeVision Compiler and Atmega 8535..
can you help me??
thank you very much
Back to top
tjiptotjupu



Joined: 06 May 2009
Posts: 3


Post06 May 2009 17:38   

sht11 c code microchip


help me ....

i use sht11 and atmega8535
in c language...

anyone help me to get the c code???
Back to top
andes



Joined: 20 Jul 2009
Posts: 1
Location: bekasi


Post20 Jul 2009 5:24   

avr-gcc +return string


saya mempunyai kendala dalam pemrograman sensor sht 11, bisakah anda mengrimkan contoh pemrograman sensor tersebut dengan berbasis atmega 32 menggunakan CVAVR bahasa C!
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Robotics and Automatics Forum -> Temprature measurement with SHT11 sensor
Page 2 of 3 All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Similar topics:
problem in interfacing lm335 temprature sensor with lm741 (4)
SHT11 temperature and humdity sensor interface with pic16 (2)
interfacing 8051 to DS1620(digital temprature sensor) (1)
Sensor Humidity SHT11 (5)
PSOC reading SHT11 sensor (2)
SHT11 temperature and humidity sensor (3)
HELP WITH SHT11 and PIC 16F877 (1)
Sensor impedance measurement (2)
color sensor measurement problem (1)
Pressure measurement values difference - electronic sensor (3)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS