//----------------------------------------------------------------------------------
void main()
//----------------------------------------------------------------------------------
// 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  

{ value humi_val,temp_val;
  float dew_point;
  unsigned char error,checksum;
  unsigned int i;

  init_uart();
  s_connectionreset();
  while(1)
  { error=0;
    error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
    error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
    if(error!=0) s_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
      calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
      dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
      printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n",temp_val.f,humi_val.f,dew_point);
    }
    //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------      
    for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
    //-----------------------------------------------------------------------------------                       
  }
} 
Beispiel #2
0
int main(int argc, const char *argv[])
{

    // SHT11
    // 6257 1547 2287 5062

    const int16_t raw_temp = 6257;
    const int16_t raw_humi = 1547;

    {
        printf("SHT11 single conversion\n\n");

        printf("%6s %6s\n", "Traw", "Hraw");
        printf("%6d %6d\n", raw_temp, raw_humi);

        float Tcels1 = sht11_temp_convert_sensirion(raw_temp);
        float RHtrue1 = sht11_humid_convert_sensirion(Tcels1, raw_humi);
        printf("%6.2f %6.2f Host: Sensirion convert mine\n", Tcels1, RHtrue1);

        float RHtrue2 = raw_humi;
        float Tcels2 = raw_temp;
        calc_sth11(&RHtrue2, &Tcels2);
        printf("%6.2f %6.2f Host: Sensirion convert datasheet\n", Tcels2, RHtrue2);
        printf("%6.2f %6.2f AVR:  Highlevel output\n", (float)2287 / 100.f, (float)5062 / 100.f);
    }

    printf("**************************************************\n\n"
           "SHT11 tabular conversion with fixed temperature\n"
           "and raw humidity ranging in [0..3500]\n\n");

    const float Tcels = sht11_temp_convert_sensirion(raw_temp);

    printf("Traw Hraw Tcels Tcels2 RH1    RH2    DP    DP2\n");

    int16_t SOrh;
    float RHtrue, RHtrue2, Tcels2;
    float DP;
    float DP2;
    for (SOrh = 0; SOrh <= 3500; SOrh += 50) {
        RHtrue = sht11_humid_convert_sensirion(Tcels, SOrh);

        Tcels2 = raw_temp;
        RHtrue2 = SOrh;
        calc_sth11(&RHtrue2, &Tcels2);
        DP = calc_dewpoint(RHtrue2, Tcels2);
        DP2 = calc_dewpoint_approx((int) RHtrue2, Tcels2 * 10) / 10.0;
        printf("%4hu %4hu %5.2f %5.2f  %6.2f %6.2f %6.2f %6.2f\n", raw_temp, SOrh, Tcels, Tcels2, RHtrue, RHtrue2, DP, DP2);
    }

    return 0;
}
int main(void)
{
    int fd,ret,i;
    	unsigned int value_t=0;
        unsigned int value_h=0;
        float fvalue_t,fvalue_h;
        float dew_point;
	fd = open("/dev/sht11",0);

	if(fd<0)
	{
		printf("open /dev/sht11 error!\n");
		return -1;
	}
 
	for(;;)
	{
                fvalue_t=0.0,fvalue_h=0.0;value_t=0;value_h=0;
		ioctl(fd,0);
		ret=read(fd,&value_t,sizeof(value_t));
                if(ret<0)
		{
			printf("read err!\n");
			continue;
		}
                sleep(1);
		
                value_t=value_t&0x3fff;//温度:14位测量数据
                //printf("value_t=%d\n",value_t);
                fvalue_t=(float)value_t;

                ioctl(fd,1);
		ret=read(fd,&value_h,sizeof(value_h));
               // printf("value_h=%d\n",value_h);
                sleep(1);
		if(ret<0)
		{
			printf("read err!\n");
			continue;
		}
                value_h=value_h&0xfff;//湿度:12位测量数据
                fvalue_h=(float)value_h;
                calc_sht11(&fvalue_h,&fvalue_t);//将输出转换为物理量
                dew_point=calc_dewpoint(fvalue_h,fvalue_t);//空气的露点值
                printf("temp:%fc humi:%f dew point:%fc\n",fvalue_t,fvalue_h,dew_point);
                sleep(1);
               
}
}
u16 get_sht11_hanback_data(u8 type)
{
acq_type=type;

error=0;
error+=s_measure(&sht11_humi,&checksum,HUMI); //measure humidity
error+=s_measure(&sht11_temp,&checksum,TEMP); //measure temperature
if(error!=0) s_connectionreset(); //in case of an error: connection reset
else
{ 
calc_sth11(sht11_humi,sht11_temp); //calculate humidity, temperature
if(acq_type==DEW)dew_point=calc_dewpoint(sht11_humi,sht11_temp); //calculate dew point
//char buf[10];
//puts("sht11_humi="); itoa(sht11_humi,buf,10); puts(buf); puts("\r\n");
//puts("sht11_temp="); itoa(sht11_temp,buf,10); puts(buf); puts("\r\n");
}
if(acq_type == DEW)return (u16)(dew_point*10);
else if(acq_type == HUMI)return myhumi;
else if(acq_type == TEMP)return mytemp;
else return 0;
}
Beispiel #5
0
void takeHumiAnfTemperature()
{ 
  unsigned char error,checksum;
  //unsigned int i;

  //WDTCTL = WDTPW + WDTHOLD;
  s_connectionreset();

  error=0;
  error+=s_measure(&t_temp,&checksum,TEMP);
  error+=s_measure(&t_hum,&checksum,HUMI);   
  if(error!=0) s_connectionreset();                
  else
  {
    temperatureSHT11 = (float) t_temp;
    hum = (float) t_hum;
    calc_sth11(&hum, &temperatureSHT11);            //calculate humidity, temperature
    dew_point=calc_dewpoint(hum,temperatureSHT11); //calculate dew point
  }
    //1 second delay
  //__delay_cycles (16000000);
}