Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Adafruit_DHT from Python

by jack2333 on Sat Dec 01, 2012 7:04 pm

I have mixed and matched Adafruit WEBIDE python code to read some ds18 sensors and a DHT22 sensor. I can successfully read and printout ds18 temps. But I am getting consistent errors while trying to read the DHT22 sensor.
(Because I am using gpio4 for the ds18, I am connecting the DHT to gpio22. After much mussing around, I am able to operate a command line Adafruit_DHT 22 22 and get good results.)

After discovering the error, I have copied the Adafruit_DHT_googledocs.ex.py python code to my home - Adafruit_DHT directory, and 'hacked-remarked' out all the code segments to talk to the googlespreadsheet' in an attempt to isolate the problem. Again, from my home-adafruit directory, I can operate a command line Adafruit_DHT 22 22 and get good results.

If I execute my modified code - dht1.py program or the official Adafruit_DHT_googledocs.ex.py code in either the webide directory or my home-adafruit directory, I get the following error;

jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ sudo python dht1.py
Traceback (most recent call last):
File "dht1.py", line 44, in <module>
output = subprocess.check_output(["sudo ./Adafruit_DHT", "22", "22"]);
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory


the python2.7 folder and the subprocess.py file exist. I have performed a update/upgrade cycle.

Can anyone help with this problem?
jack2333
 
Posts: 4
Joined: Wed Nov 28, 2012 2:22 pm

Re: Adafruit_DHT from Python

by adafruit on Sat Dec 01, 2012 9:12 pm

it cant find the "Adafruit_DHT" file - it must be in the same directory
User avatar
adafruit
 
Posts: 11509
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Adafruit_DHT from Python

by jack2333 on Sun Dec 02, 2012 1:47 am

Wow, that should be simple. So I post the following commands and responses;

(I putty/SSH into my terminal home directory)
jack@jacksrpi31 ~ $ ls
Adafruit-Raspberry-Pi-Python-Code bcm2835-1.8 Desktop hello_.txt
arduino-1.0.2 bcm2835-1.8.tar.gz gspread sketchbook
jack@jacksrpi31 ~ $ sudo ./Adafruit_DHT 22 22
[sudo] password for jack:
sudo: ./Adafruit_DHT: command not found

(I expected this to fail, so I go to the directory that Adafruit created (http://learn.adafruit.com/dht-humidity- ... cs-logging)
jack@jacksrpi31 ~ $ cd Adafruit-Raspberry-Pi-Python-Code
jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code $ sudo ./Adafruit_DHT 22 22
sudo: ./Adafruit_DHT: command not found (again I expected this to fail)
jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code $ ls
Adafruit_ADS1x15 Adafruit_I2C Adafruit_MCP4725
Adafruit_BMP085 Adafruit_LEDBackpack Adafruit_PWM_Servo_Driver
Adafruit_CharLCD Adafruit_LEDpixels README.md
Adafruit_CharLCDPlate Adafruit_MCP230xx
Adafruit_DHT_Driver Adafruit_MCP3008

jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code $ cd Adafruit_DHT_Driver ( so I went here...)
jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ ls
Adafruit_DHT Adafruit_DHT.c Adafruit_DHT_googledocs.ex.py dht1.py Makefile
jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ sudo ./Adafruit_DHT 22 22
Using pin #22
Data (40): 0x1 0x68 0x0 0xf3 0x5c
Temp = 24.3 *C, Hum = 36.0 % (and this works)
jack@jacksrpi31 ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ python dht1.py (and I try my test code and it fails the same way.)
Traceback (most recent call last):
File "dht1.py", line 44, in <module>
output = subprocess.check_output(["sudo ./Adafruit_DHT", "22", "22"]);
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

What directory should I expect output = subprocess.check_output(["sudo ./Adafruit_DHT", "22", "22"]); to work from?
Is it possible to make the "sudo ./Adafruit_DHT", "22", "22"]) from my home directory?

This is the code that fails in WebIDE, as well as from my home-Adafruit directory.
Code: Select all

import subprocess
import re
import sys
import time
import datetime
import gspread

# ===========================================================================
# Google Account Details
# ===========================================================================

# Account details for google docs
#email       = 'xxx'
#password    = 'xxxx'
#spreadsheet = 'xxxxxx'

# ===========================================================================
# 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", "22", "17"]);
  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)

jack2333
 
Posts: 4
Joined: Wed Nov 28, 2012 2:22 pm

Re: Adafruit_DHT from Python

by adafruit on Mon Dec 03, 2012 8:57 pm

remove the "./" from the command list in python, its probably confusing it
User avatar
adafruit
 
Posts: 11509
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Adafruit_DHT from Python

by alfonso82 on Tue Feb 26, 2013 9:33 pm

Hi, I´m new here but I´m getting the same problem and removing the "./" did not resolve the problem, I don´t know if jack2333 got pass this or not, if you did please post your solution, and thank you.
alfonso82
 
Posts: 1
Joined: Sun Feb 17, 2013 5:56 am

Re: Adafruit_DHT from Python

by andrewbo on Wed Mar 06, 2013 5:30 am

I am having the exact same issue.

The problem first occurred when I switched from Raspbian to XBian.

I've tried the above suggestions but it is still throwing the following error.

Code: Select all
Traceback (most recent call last):
  File "DHT_googledocs.py", line 44, in <module>
    output = subprocess.check_output("sudo /home/scripts/dht/Adafruit_DHT", "2302", "4", shell=True);
  File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 629, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer


I notice that the last line is different to that in OPs first post. Has anyone managed to solve this issue?
andrewbo
 
Posts: 6
Joined: Tue Oct 23, 2012 4:08 am