Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Temprature measurement with SHT11 sensor

Status
Not open for further replies.
sht11 pic16f84

gricesj said:
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@hotmail.com
 

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@yahoo.com
 

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
 

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 !!!!!!
 

bascom float to string

asena said:
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.
 

pic basic sht11

willie said:
asena said:
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
 

sht11 sensör

vlad2007 said:
willie said:
asena said:
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
 

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
 

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
}
 

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???
 

sht11 control bascom-avr

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

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.
 

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@hotmail.com
 

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
 

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@hotmail.com

thanks alot
 

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,
 

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
 

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
 

sht11 c code microchip

help me ....

i use sht11 and atmega8535
in c language...

anyone help me to get the c code???
 

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!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top