diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9fa60435 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Adafruit_DHT +*.o diff --git a/Adafruit_DHT_Driver/.gitignore b/Adafruit_DHT_Driver/.gitignore new file mode 100644 index 00000000..9c595a6f --- /dev/null +++ b/Adafruit_DHT_Driver/.gitignore @@ -0,0 +1 @@ +temp diff --git a/Adafruit_DHT_Driver/Adafruit_DHT.c b/Adafruit_DHT_Driver/Adafruit_DHT.c index 9d1746be..5ebab1f6 100644 --- a/Adafruit_DHT_Driver/Adafruit_DHT.c +++ b/Adafruit_DHT_Driver/Adafruit_DHT.c @@ -27,12 +27,6 @@ #define MAXTIMINGS 100 -//#define DEBUG - -#define DHT11 11 -#define DHT22 22 -#define AM2302 22 - int readDHT(int type, int pin); int main(int argc, char **argv) @@ -40,29 +34,20 @@ int main(int argc, char **argv) if (!bcm2835_init()) return 1; - if (argc != 3) { - printf("usage: %s [11|22|2302] GPIOpin#\n", argv[0]); - printf("example: %s 2302 4 - Read from an AM2302 connected to GPIO #4\n", argv[0]); + if (argc != 2) { + printf("usage: %s GPIOpin#\n", argv[0]); + printf("example: %s 4 - Read from an AM2302 connected to GPIO #4\n", argv[0]); return 2; } - int type = 0; - if (strcmp(argv[1], "11") == 0) type = DHT11; - if (strcmp(argv[1], "22") == 0) type = DHT22; - if (strcmp(argv[1], "2302") == 0) type = AM2302; - if (type == 0) { - printf("Select 11, 22, 2302 as type!\n"); - return 3; - } - - int dhtpin = atoi(argv[2]); + int type = 22; + + int dhtpin = atoi(argv[1]); if (dhtpin <= 0) { printf("Please select a valid GPIO pin #\n"); return 3; } - - printf("Using pin #%d\n", dhtpin); readDHT(type, dhtpin); return 0; @@ -116,22 +101,9 @@ int readDHT(int type, int pin) { } } - -#ifdef DEBUG - for (int i=3; i 200); - } -#endif - - printf("Data (%d): 0x%x 0x%x 0x%x 0x%x 0x%x\n", j, data[0], data[1], data[2], data[3], data[4]); - if ((j >= 39) && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) { // yay! - if (type == DHT11) - printf("Temp = %d *C, Hum = %d \%\n", data[2], data[0]); - if (type == DHT22) { float f, h; h = data[0] * 256 + data[1]; h /= 10; @@ -139,8 +111,8 @@ int readDHT(int type, int pin) { f = (data[2] & 0x7F)* 256 + data[3]; f /= 10.0; if (data[2] & 0x80) f *= -1; - printf("Temp = %.1f *C, Hum = %.1f \%\n", f, h); - } + printf("%.1f\n", f); + printf("%.1f\n", h); return 1; } diff --git a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py b/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py deleted file mode 100755 index c13d3033..00000000 --- a/Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python - -import subprocess -import re -import sys -import time -import datetime -import gspread - -# =========================================================================== -# Google Account Details -# =========================================================================== - -# Account details for google docs -email = 'you@somewhere.com' -password = '$hhh!' -spreadsheet = 'SpreadsheetName' - -# =========================================================================== -# Example Code -# =========================================================================== - - -# Login with your Google account -try: - gc = gspread.login(email, password) -except: - print "Unable to log in. Check your email address/password" - sys.exit() - -# Open a worksheet from your spreadsheet using the filename -try: - worksheet = gc.open(spreadsheet).sheet1 - # Alternatively, open a spreadsheet using the spreadsheet's key - # worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE') -except: - print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet - sys.exit() - -# Continuously append data -while(True): - # Run the DHT program to get the humidity and temperature readings! - - output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]); - print output - matches = re.search("Temp =\s+([0-9.]+)", output) - if (not matches): - time.sleep(3) - continue - temp = float(matches.group(1)) - - # search for humidity printout - matches = re.search("Hum =\s+([0-9.]+)", output) - if (not matches): - time.sleep(3) - continue - humidity = float(matches.group(1)) - - print "Temperature: %.1f C" % temp - print "Humidity: %.1f %%" % humidity - - # Append the data in the spreadsheet, including a timestamp - try: - values = [datetime.datetime.now(), temp, humidity] - worksheet.append_row(values) - except: - print "Unable to append data. Check your connection?" - sys.exit() - - # Wait 30 seconds before continuing - print "Wrote a row to %s" % spreadsheet - time.sleep(30) diff --git a/Adafruit_DHT_Driver/Makefile b/Adafruit_DHT_Driver/Makefile index 5a91e391..a094255f 100644 --- a/Adafruit_DHT_Driver/Makefile +++ b/Adafruit_DHT_Driver/Makefile @@ -6,5 +6,5 @@ OBJ = Adafruit_DHT.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) -Adafruit_DHT: $(OBJ) +temp: $(OBJ) gcc -o $@ $^ $(CFLAGS)