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/

Python code not working for AM2302 Temp sensor

by svinzant on Mon Oct 08, 2012 9:44 pm

Hi All,
I have a very limited understanding of Linux / Python, so, please bear with me...
I am trying to set up the AM2302 Temperature/Humidity sensor on a Raspberry Pi to monitor the temperature and humidity levels in a green house.
I have everything all set up on the RPi.
I am using Occidentalis v0.1 on a four GB micro SD card, the sensor is connected according to the diagram in the tutorial.
When I run the test, (./Adafruit_DHT 2302 4) I do see sensor data.
When I run ./Adafruit_DHT_googledocs.ex.py , I see in the terminal window a lot of temp/humidity data being output to the screen every second or two.
Also, I am pretty sure that I am "connecting" to the Google spreadsheet I have set up as I saw (at one point) that there was "one other user" connected to it.
I have also tried both connecting to the spreadsheet "name" and the "key". Neither option works as I don't think it is getting that far in the script.
What I don't see is that it "matches" the temp or humidity values in the Python script nor does it write anything to the Google spreadsheet.
I think the line numbers in question are #46 (for Temp) and #53 (for Hum).

Any input or ideas to try would be greatly appreciated.
Would there also be any chance of using this setup with COSM.com? that would provide a much better output format for tracking / trending the data I hope to collect.
Thanks in advance for the help.
Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm

Re: Python code not working for AM2302 Temp sensor

by quantalume on Mon Oct 08, 2012 11:10 pm

Are you seeing any of the error messages from the exception-handling portions of the python code (such as "Unable to open...")? You could insert something like the following at line 38, before the sensor loop, just to make sure you can write to the spreadsheet.

Code: Select all | TOGGLE FULL SIZE
values = [1, 2, 3]
worksheet.append_row(values)


I've used COSM to track sensor data in the past, and it works really well. There's another Adafruit learning module with some python code for connecting the Pi to COSM, but you can also use curl, as described here: https://cosm.com/docs/quickstart/curl.html
quantalume
 
Posts: 8
Joined: Mon Oct 08, 2012 10:22 pm

Re: Python code not working for AM2302 Temp sensor

by svinzant on Tue Oct 09, 2012 11:00 am

Quantalume,
Thanks for the reply.
At this point, I am not seeing any error messages.
Again, I do see valid temperature and humidity data get spit out in the terminal screen window.
So, that tells me that I have at least partially set things up in a somewhat working fashion.
I will test your suggestion for the code at line 38 and see what happens.
I am assuming that it will put 1, 2, 3 into my spreadsheet.
I am at work now, but will report back my finding later this afternoon.
As for the curl stuff, I took a quick look, I don't know that I have the chops to figure that type of coding out. I can build a house (or green house in this case) but I don't have much in the way of coding knowledge.
Thanks again...
Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm

Re: Python code not working for AM2302 Temp sensor

by svinzant on Tue Oct 09, 2012 3:46 pm

Quantalume,
Your suggestion of the little code snippet did confirm that data (1, 2 and 3 in one row) is getting written into my spreadsheet.
It seems that the problem is in the two sections that "search" for matching strings.
I think that needs a little more focus at this point. I will try to do some searches on-line and find how that command works.

I would still rather have the data go to COSM.com. Maybe down the road, somebody will tackle that project.
Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm

Re: Python code not working for AM2302 Temp sensor

by svinzant on Wed Oct 10, 2012 1:29 pm

So, here is what I have discovered...
After line 46 ( matches = re.search("Temp =\s+([0-9.]+)", output) ) I inserted a new line: print matches
I usually see it say "none".
That tells me that the search term is not matching and kicking back a result code that it did not find the string it is looking for.
I feel that is what has been happening the whole time.
Does anybody have any other ideas for me to try?
Thanks!
Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm

Re: Python code not working for AM2302 Temp sensor

by svinzant on Wed Oct 10, 2012 4:22 pm

And here is what I see output from "print matches" :

None
Using pin #4
Data (40): 0x1 0x9a 0x0 0xdc 0x77
Temperature = 22.0, Humidity = 41.0
<_sre.SRE_Match object at 0xf3afa0>
Using pin #4
Data (40): 0x1 0xa1 0x0 0xdc 0x7e
Temperature = 22.0, Humidity = 41.7
<_sre.SRE_Match object at 0xf3af60>

Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm

Re: Python code not working for AM2302 Temp sensor

by svinzant on Thu Oct 11, 2012 9:23 am

Fixed!
And, writing the temp and humidity data to Cosm.com!
Scott
svinzant
 
Posts: 17
Joined: Mon May 16, 2011 1:30 pm