2014 views|3 replies

1453

Posts

1

Resources
The OP
 

【AT-START-F403A Review】+DHT22 temperature and humidity detection and display [Copy link]

 

In addition to driving display devices, driving various digital sensors is also very beneficial.

Here we introduce a driving method for a single-bus digital temperature and humidity sensor. The device is DHT22, which has higher accuracy than DHT11 and can reach 1 decimal place.

When using this device, its data pin is connected to PB11, so there are the following definition pins for outputting high and low levels and reading pin status:

#define DHT22_D0_H GPIOB->BSRE = GPIO_Pins_15

#define DHT22_D0_L GPIOB->BRE = GPIO_Pins_15

#define DHT22_D0_R GPIO_ReadInputDataBit(GPIOB, GPIO_Pins_15)

The function to initialize DHT22 is:

uint8_t DHT22_Init(void)
{
 GPIO_InitType GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
 GPIO_StructInit(&GPIO_InitStructure);
 GPIO_InitStructure.GPIO_Pins = GPIO_Pins_15;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
 GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  DHT22_Rst();
  return DHT22_Check();
}

The function to read DHT22 data is:

uint8_t DHT22_Read_Data(uint8_t *temp,uint8_t *humi)
{
 uint8_t buf[5];
 uint8_t i;
 DHT22_Rst();
 if(DHT22_Check()==0)
 {
 for(i=0;i<5;i++)
 {
 buf[i]=DHT22_Read_Byte();
 }
 if((buf[0]+buf[1]+buf[2]+buf[3])==buf[4])
 {
 *humi=(buf[0]*256+buf[1])/10;
 *temp=(buf[2]*256+buf[3])/10;
 }
 }else return 1;
 return 0;
}

The program to realize the temperature and humidity detection function is as follows:

if(i==4)
{
 showhanzi16h(80,100,5,1);
 showhanzi16h(80,84,6,1);
 showhanzi16h(180,280,13,0);
 showhanzi16h(180,264,14,0);
 while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pins_0)==0);
    LCD_Clear(WHITE);
  show_imageh(10,300,0); //200*200 * 1
 BACK_COLOR=WHITE;
  POINT_COLOR=RED;
 LCD_ShowStringH(60,90,"DHT22 TEST");
  senflag=DHT22_Init();
  if(senflag) LCD_ShowStringH(80,90,"NO");
  else LCD_ShowStringH(80,90,"OK");
  while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pins_0)==0)
  {
  if(!senflag)
  {
   DHT22_Read_Data(&temperature,&humidity);
  LCD_ShowCharh(100,90,'T',1);
  LCD_ShowCharh(100,80,'e',1);
  LCD_ShowCharh(100,70,'m',1);
  LCD_ShowCharh(100,60,'p',1);
  LCD_ShowCharh(100,50,':',1);
     LCD_ShowCharh(100,40,temperature/10+'0',0);
     LCD_ShowCharh(100,30,temperature%10+'0',0);
  LCD_ShowCharh(120,90,'H',1);
  LCD_ShowCharh(120,80,'u',1);
  LCD_ShowCharh(120,70,'m',1);
  LCD_ShowCharh(120,60,'i',1);
  LCD_ShowCharh(120,50,':',1);
  LCD_ShowCharh(120,40,humidity/10+'0',0);
  LCD_ShowCharh(120,30,humidity%10+'0',0);
    }
  Delay_ms(200u);
  }
  LCD_Clear(WHITE);
  AT32_jm();
  showhanzi16h(80,100,5,1);
  showhanzi16h(80,84,6,1);
 showhanzi16h(180,280,13,0);
   showhanzi16h(180,264,14,0);
}

The running effect of the program is shown in Figure 1 and Figure 2, where Figure 1 is the selection of the environment detection function, and Figure 2 is the temperature and humidity display interface.

Figure 1 Function selection

Figure 2 Temperature and humidity display

This post is from Domestic Chip Exchange

Latest reply

Yatli AT-START-F403A Review Summary Summary post: https://en.eeworld.com/bbs/thread-1143018-1-1.html   Details Published on 2020-10-19 09:46
 
 

1942

Posts

2

Resources
2
 

Thanks for sharing. You can also display the temperature to one decimal place. This will better reflect DHT22!

This post is from Domestic Chip Exchange

Comments

I didn't add it at the time to save trouble, otherwise I would have to add another statement to display the decimal places.  Details Published on 2020-10-16 10:11
 
 
 

1453

Posts

1

Resources
3
 
w494143467 published on 2020-10-15 21:53 Thanks for sharing. You can also display the temperature to one decimal place. This will better reflect DHT22!

I didn't add it at the time to save trouble, otherwise I would have to add another statement to display the decimals.

This post is from Domestic Chip Exchange
 
 
 

1w

Posts

204

Resources
4
 

Yatli AT-START-F403A Review Summary

Summary post: https://en.eeworld.com/bbs/thread-1143018-1-1.html

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list