dht11/dht11.c

Thu, 08 May 2014 22:36:51 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 08 May 2014 22:36:51 +0200
changeset 31
89dd2b691701
child 35
f3c5ae78b746
permissions
-rw-r--r--

Added library code to read DHT11 temperature/humidity sensor

/*****************************************************************************
 * Copyright (C) 2014
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of the mbsePi-apps
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * mbsePi-apps is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with EC-65K; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

#include "../lib/mbselib.h"
#include "dht11.h"

#ifdef HAVE_WIRINGPI_H

extern int	dht11_valid;
extern int	dht11_temperature;
extern int	dht11_humidity;

int main(int argc, char *argv[]) {
  
    int PIN = 3;
     
    if (wiringPiSetup() == -1)
	return 0;

    dht11Init(PIN, 0, 6);
    dht11Read();
    if (dht11_valid) {
	fprintf(stdout, "DHT11: temperature %d degrees, humidity %d%%\n", dht11_temperature, dht11_humidity);
    } else {
	fprintf(stdout, "DHT11: no valid data or sensor not connected\n");
    }

    exit(0);
}

#else

int main(int argc, char *argv[]) {
    fprintf(stderr, "This program does nothing without the wiringPi library\n");
    return 0;
}

#endif

mercurial