dht22傳感器溫度
這段程式在dht 11 傳感器上 溫度與濕度顯是都是正常我把傳感器換成dht22 溫度 濕度都會變成 %
如何轉換謝謝
// verify cheksum and print the verified data
if((j>=40)&&(dht11_val==((dht11_val+dht11_val+dht11_val+dht11_val)& 0xFF)))
{
printf("Humidity = %d.%d %% Temperature = %d.%d°C\n",dht11_val,dht11_val,dht11_val,dht11_val);
char text;
time_t now = time(NULL);
struct tm *t = localtime(&now);
strftime(text, sizeof(text)-1, "%d-%m-%Y", t);
char prefix = "/var/www/log-";
strcat(prefix,text);
char suffix = ".csv";
strcat(prefix,suffix);
FILE *fp;
fp=fopen(prefix,"a");
fprintf(fp,"%u000,%d%d,%d\n",(unsigned)time(NULL),dht11_val,dht11_val,dht11_val);
fclose(fp);
FILE *fh;
fh=fopen("/var/www/current_hyg.csv", "w");
fprintf(fh,"%d\n",dht11_val);
fclose(fh);
FILE *ft;
ft=fopen("/var/www/current_temp.csv", "w");
fprintf(ft,"%d.%d\n",dht11_val,dht11_val);
fclose(ft);
exit(1);
}
else
printf("Invalid Data!!\n");
}
int main(void)
{
printf("Interfacing Temperature and Humidity Sensor (DHT11) With Banana Pi\n");
if(wiringPiSetup()==-1)
exit(1);
while(1)
{
dht11_read_val();
delay(3000);
}
return 0;
}
页:
[1]