Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

DHT 22 Temperature and Humidity sensor with adafruit code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Fri Jan 02, 2015 4:59 am

Oh to convert the units you can actually just use the formula for converting from C to F:

F = (C - 32.0)*5.0/9.0

You can actually put it right in the print statement, so it would look like:

print 'Temperature: {0:0.1f} F'.format((temp-32.0)*5.0/9.0)

It might seem odd to have the numbers with a decimal point and zero at the end, but that's just a quick way to guarantee python does floating point math instead of integer math. It's a subtle difference but if python does integer math then you'll only get integer values (like 1, 2, 3, etc.) which will cut off values like 1.25, 2.33, etc.

Give that a shot to modify the print statement, and any other statement that uses the temp variable (like writing the data to google sheets).

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by dcrand on Fri Jan 02, 2015 10:39 am

Shouldn't;t the formula be F = C * 9.0 / 5.0 + 32 yours give a - reading when it should be + reading ? or am I missing something?. The google sheet stopped updating correctly also, how ever I'll sort that out once I get units right.

dcrand
 
Posts: 4
Joined: Wed Jul 13, 2011 1:13 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Mon Jan 05, 2015 6:10 pm

Oh sorry you're right, basic math failed me and the C to F conversion is really F = (C+32.0)*(9.0/5.0). Try changing the formula in your code to use that formula and it should give the right value.

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by dcrand on Tue Jan 06, 2015 10:55 am

When using your formula I get:
Traceback (most recent call last):
File "google_spreadsheet.py", line 82, in <module>
print 'Temperature: {0:0.1f} F'.format(temp + 32.0) * (9.0 / 5.0)
TypeError: can't multiply sequence by non-int of type 'float'

When using: print 'Temperature: {0:0.1f} F'.format(temp * 9.0 / 5.0 + 32.0) it gives correct value. However the googlesheet is still updating with the Celsius reading. Do I have to change the formula somewhere else in the code?

dcrand
 
Posts: 4
Joined: Wed Jul 13, 2011 1:13 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Tue Jan 06, 2015 6:01 pm

Yeah make sure to include all the parenthesis. This line is telling python to print something and then try to multiply it by (9.0/5.0), but math operations on a print statement don't make sense to python:
Code: Select all | TOGGLE FULL SIZE
print 'Temperature: {0:0.1f} F'.format(temp + 32.0) * (9.0 / 5.0)


If you put the equation in parenthesis then python will first compute the value inside the parens, and then send that to the print statement. The line would look like:
Code: Select all | TOGGLE FULL SIZE
print 'Temperature: {0:0.1f} F'.format((temp + 32.0) * (9.0 / 5.0))


Be careful the line you have that multiplies and then adds is little bit wrong, since addition needs to happen before the multiplication.

Yep you're this modification only changes the line that's printed to the console because it's only changing the print statement there. There's another place where the temp is used to write to the spreadsheet. Check out this line a little further down:
Code: Select all | TOGGLE FULL SIZE
worksheet.append_row((datetime.datetime.now(), temp, humidity))


You'll want to modify the temp value there in the same way, like:
Code: Select all | TOGGLE FULL SIZE
worksheet.append_row((datetime.datetime.now(), ((temp + 32.0) * (9.0 / 5.0)), humidity))

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by dcrand on Tue Jan 06, 2015 8:53 pm

Thanks for your help, this formula <print 'Temperature: {0:0.1f} F'.format((temp * 9.0) / (5.0)+ 32)> is giving the correct values your formula didn't. However due to the frustration to my senior braincells I'm abandoning this project and moving on to others things.

dcrand
 
Posts: 4
Joined: Wed Jul 13, 2011 1:13 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by ayushkhemka on Fri Jan 23, 2015 12:03 am

How does the BBB transmit data to Google Docs? Does it use WiFi to do that?

ayushkhemka
 
Posts: 2
Joined: Fri Jan 23, 2015 12:02 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_mike on Fri Jan 23, 2015 4:51 pm

The BBB communicates with Google Docs through some kind of internet connection. It could be Wifi, a wired Ethernet connection, or the USB TCP/IP connection.

adafruit_support_mike
 
Posts: 61118
Joined: Thu Feb 11, 2010 2:51 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdude on Mon Feb 02, 2015 3:13 pm

Hi, i have been following this tutorial but i have a few questions.
How can i modify the code so that it will print to a different sheet within the spreadsheet? Is it possible to make the code print to the top of the sheet instead of right at the bottom? And also the pi seems to stop printing its readings after a random amount of time which i don't want, any ideas?
Thanks in advanced!

tdude
 
Posts: 4
Joined: Mon Feb 02, 2015 3:06 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_mike on Tue Feb 03, 2015 1:05 am

tdude wrote:How can i modify the code so that it will print to a different sheet within the spreadsheet?
Is it possible to make the code print to the top of the sheet instead of right at the bottom?

Those would both be Google Docs API issues, and those change fast enough that it's best to check the official source:
https://developers.google.com/drive/web/migration

(Apparently the Google Docs API is being phased out by April 2015 and Google Drive is the replacement)

tdude wrote:And also the pi seems to stop printing its readings after a random amount of time which i don't want, any ideas?

Where does it stop printing, Google or the local display?

adafruit_support_mike
 
Posts: 61118
Joined: Thu Feb 11, 2010 2:51 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdude on Tue Feb 03, 2015 3:14 pm

Where does it stop printing, Google or the local display?

On google. It seems odd but it looks like it stops printing the after you check the spreadsheet for the first time since the script was ran?

tdude
 
Posts: 4
Joined: Mon Feb 02, 2015 3:06 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Tue Feb 03, 2015 6:08 pm

Are there any errors displayed in the console that's running the DHT google spreadsheet code? If a measurement can't be sent to the sheet it should fail with an error. If there aren't errors you might try reloading the Google Spreadsheet page to see if it's a connection issue with the browser and webpage. Also try scrolling down a bit just to check measurements aren't being inserted after cell 10000 (an annoying thing Google sheets does by default, it's why the tutorial mentions deleting the first 10k rows in the sheet).

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdude on Sat Feb 07, 2015 9:46 am

tdicola wrote:Are there any errors displayed in the console that's running the DHT google spreadsheet code? If a measurement can't be sent to the sheet it should fail with an error. If there aren't errors you might try reloading the Google Spreadsheet page to see if it's a connection issue with the browser and webpage. Also try scrolling down a bit just to check measurements aren't being inserted after cell 10000 (an annoying thing Google sheets does by default, it's why the tutorial mentions deleting the first 10k rows in the sheet).

Sorry I'm a complete novice, but how do i see the console where the errors could be?

tdude
 
Posts: 4
Joined: Mon Feb 02, 2015 3:06 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by thonka on Tue Feb 10, 2015 4:42 pm

Hi,

All is working properly, the only problem is that the data that is assigned to the entrance (In the google doc) of the reading has only DD/MM/YYYY and not the hour.. Any idea what's the problem?, it's not confortable to have all the data and not the hour.. I get lost then.

there's a screenshot in the attachment.

Best regards,
Attachments
Captura.PNG
Captura.PNG (8.9 KiB) Viewed 1231 times

thonka
 
Posts: 4
Joined: Tue Feb 10, 2015 4:37 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_rick on Wed Feb 11, 2015 11:07 am

Make sure you have the Date/Time column in the spreadsheet formatted to display the time as well as the date

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.