Log data with a DHT22 temp sensor & a Pi to Google Spreadsheet
Vložit
- čas přidán 4. 09. 2024
- Hey there!
In this video I'll connect a DHT 22 sensor to a Raspberry Pi. We'll read the temperature & humidity out of it, write the data to a Google Spreadsheet and display it in a nice look line chart.
Preparations
All you need is a Raspberry Pi and the DHT 22 sensor I used in the video. You'll find for around 5 Euro/Dollar at your favorite dealer. With these little preassembled sensor boards you are ready to go. If you only buy the sensor it self you may need some resistor to get it working.
Libraries/Links
We're using the Adafruit DHT lib. In the meantime it's declared deprecated. This means the vendor doesn't actively support it. I created an unmodified fork of it so that you can still use it in the future like in this video.
AdafruitDHT lib: github.com/dat...
Temperature Chart lib: github.com/dat...
Google Developer Console: console.develo...
Google Docs: docs.google.com
Feel free to comment if you have any questions or suggestions.
Thanks for watching!
I enjoyed following this video and getting my Google Sheet set up with its accompanying chart in my browser - thanks for sharing this, Datort.
I noticed that the chart X-axis increments the same amount for each reading so that a reading taken eight hours ago is spaced the same as one taken a minute ago if it was the one taken before the current reading. This is because the X-axis values written to the sheet are strings and not date-time values. So the sheet looks nice but the chart derived from it does not necessarily reflect the slopes of the temperature changes as the time between each reading is not necessarily the same (though it will be fine if the pi runs continuously with no breaks).
After a bit of experimentation, I got the app.js file to write a date-time value, not a string, by adding valueInputOption="USER_ENTERED" into the original insert_rows statement that uses isoformat. This meant that the Sheet stored the date and time in the first column, the temperature in the second and the humidity in the third. I had to fiddle with the index file too to plot columns A and B (I didn’t plot humidity) and to remove the reverse direction statement as the values are plotted in time order now with the latest being at the far right.
I think it gives a truer representation of the rate of change of temperature and just thought I’d share it here. Cheers!
Excellent video!
GOOD and cool job DATORT.👌👍👌..liked it too.....as we share the same intrests and channel
content... i will encourage and suppourt you as much as i can....and i SUBSCRIBED yours tooo. IAM YOUR 54TH SUBSCRIBER...anyways...let this be
good begiining and All the very best from Electrical coder.👍
What about a history tab? That'd all I'm looking for... Looked for hoouuuurs
Great project!! I got it up and working, i was wondering if there is anyway to do 2 separate charts, i live in Costa Rica and we have such humidity that the temperature is always a flat line😅
great video. thank you!
Very interesting. Thank a lot !
Is there a way to just overwrite one row of cells ever update?
Neat idea
Is there a limit now far the cable to sensor can push 5v and data ? Might be interesting to put a sensor in the ceiling cavity and other places
Nice nice nice, thank you
Hi. I connected the DH22. Getting "failed to get reading, try again!" Any idea what the issue is? Thanks!
Error accessing GPIO. Make sure program is run as root with sudo! help me please
Is this still working? I triple checked everything.
I'm getting this error:
Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!
Google sheet login failed with error: Invalid control character at: line 1 column 160 (char 159)
When I ran "sudo pip install gspread oauth2client", I got the error message "google-auth 1.19.2 has requirement rsa
good method. very happy to be able to log to online spreadsheet. that's exactly what I was wanting. I have a problem trying to run my python script at boot up on a raspberry pi 3. The script works fine in Thoney and from the terminal window. However, I have tried numerous times to configure /etc/rc.local to run my script at startup and am unable. it appears that it does not locate the *.json file. Although, my .json file is in the very same subdirectory as the script. Or could be another problem. idk. Could you help with runny this as a startup script?
did you find a solution for this problem because i'm having troublke with it too
Why not set up a cron job to do it? There's an option to run things at startup
hy! very helpful video! How can I implement two or more temperature sensors?
Hi can you help me with this problem Please:
json.decoder.JSONDecodeError: Invalid control character at: line 3 column 38 (char 165)
I have done everything you did but I face that Error. It drives me crazy
Excellent tutorial, worked like a charm thank you!
Do you know how to edit the script so that I can take readings from 2 DHT22 sensors?
Hey and thanks for your feedback! There is for sure a way to extend the script for this. Unforunately I can‘t code something down right now, cause I‘m sitting here with a broken shoulder after an accident 😔 For a „quick fix“ you could copy the script, change the parameters and run it twice. Should work...
I did just that, works for now. Thanks again :)
Nice work Dear 👍 All the very best from #E2Esolutions .
How's your shoulder now Dear .. Wishing you a speedy recovery ☺
Thanks very much! Can‘t use one of my arms for another 3 weeks. That‘s annoying but it could be worse. Slowly but surely recovering. 💪🏻😊
@@datort Take care Buddy, will discuss your new Post. till then support my posts☺
Is there a way to make it so you get a text or email if it goes above a certain temp?
Followed this and it all worked great except for the chart right at the end. The spreadsheet is updating fine and the raspberrypi.local tab is entitled Temperature Monitor but it just times out saying "Error in query: request timed out". Any suggestions? Thanks for the video!
Just found that I hadn't added 'spreadsheets/d' in front of the Google Sheets ID so all working well now - thanks again!
Sir can you help me how to configure moisture sensor to raspberry Pi
Hi, so I have one question. I had no issues in the video up until I did ./google_spreadsheet.py right before the sensor actually input readings into the spreadsheet. When it tried to run this script, I got an ImportError: No module named gspread. I did the sudo pip install gpread oauth2client line, and it says gspread is installed. Why does it say the module gspread is not installed though? Do you know how to fix this issue? Thank you for any help you could give me!
Nevermind, fixed the error. Really good video!
@@taylorkissinger5004 i have same error, what can i do?
@@tonygun77 import gspread in your python file
whats the exact model of the DHT22 sensor that you used?
Whats this error I recd when installing google auth.. "google-auth 1.18.0 has requirement rsa
Hey, what type of Linux Distribution and Python version are you using? I was on the default Raspian/RaspberryPi OS with it's Python 2.7 (for that time). Maybe it has something todo with this. The tutorial was based on plain and clean installation of that distribution.
@@datort But, all worked inspite of that. Thanx for the video. Very helpful.
Can anyone help me?
I don't know why after "./google_spreadsheet.py" I have as answers "sudo: unable to execute ./google_spreadsheet.py: No such file or directory".
Obviously the file is present and I modified the code as in the video.
I have installed Python 3.7.3
(
sudo apt-get install python3
&
sudo apt-get install python3-pip
)
Please help me
I managed to solve by changing google_spreadsheet.py in the first few lines of code from usr/bin /python to usr/bin/python3. Now I have another problem:
pi@raspberrypi001:~/Adafruit_Python_DHT/examples $ ./google_spreadsheet.py
File "./google_spreadsheet.py", line 119
worksheet.insert_row((datetime.datetime.now().strftime('%Y-%m-%d'), datetime.datetime.now().strftime('%H:%M')temp, humidity), 1)
^
TabError: inconsistent use of tabs and spaces in indentation
@@giuseppe.buccheri Did you ever get the error that gspread was not defined? After running "./google_spreadsheet.py"
I just tried changing the first line of google_spreadsheet.py to the usr/bin/python3 like you did, and now Im not getting the gspread error. I'm getting the same TabError you are getting. I have no idea if you ever found a solution, but I'll let you know if I figure something out
When I tried running the program, there was an error :ImportError: cannot import name Beaglebone_Black_Driver. Can anyone help me?