Multiple DHT22's over 3 channels and a RPi | Raspberry Pi | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Multiple DHT22's over 3 channels and a RPi
No permission to create posts
March 14, 2018
3:49 am
Avatar
thingspeak4matt
New Member
Members
Forum Posts: 2
Member Since:
March 14, 2018
sp_UserOfflineSmall Offline

Hi guys

I have built a circuit with 5 DHT22s there data pins are connected to IO 21 20 16 26 12 respectively and power directly from the psu.

A total of 10 fields 2 each (Temp and humidity) with a max of 8 fields per channel I had to split the channels

unfortunately I have very little coding skills - using the below code I managed to get one sensor to work correctly.

(https://www.hackster.io/adamgarbo/raspberry-pi-2-iot-thingspeak-dht22-sensor-b208f4)

 

<span class="hljs-string">""" </span><span class="hljs-string">dht22.py </span><span class="hljs-string">Temperature/Humidity monitor using Raspberry Pi and DHT22. </span><span class="hljs-string">Data is displayed at thingspeak.com </span><span class="hljs-string">Original author: Mahesh Venkitachalam at electronut.in </span><span class="hljs-string">Modified by Adam Garbo on December 1, 2016 </span><span class="hljs-string">"""</span> <span class="hljs-keyword">import</span> sys <span class="hljs-keyword">import</span> RPi.GPIO <span class="hljs-keyword">as</span> GPIO <span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep <span class="hljs-keyword">import</span> Adafruit_DHT <span class="hljs-keyword">import</span> urllib2 myAPI = <span class="hljs-string">"&lt;your API code here&gt;"</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getSensorData</span><span class="hljs-params">()</span>:</span> RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, <span class="hljs-number">21</span>) <span class="hljs-keyword">return</span> (str(RH), str(T)) <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span> <span class="hljs-keyword">print</span> <span class="hljs-string">'starting...'</span> baseURL = <span class="hljs-string">'https://api.thingspeak.com/update?api_key=%s'</span> % myAPI <span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>: <span class="hljs-keyword">try</span>: RH, T = getSensorData() f = urllib2.urlopen(baseURL + <span class="hljs-string">"&amp;field1=%s&amp;field2=%s"</span> % (RH, T)) <span class="hljs-keyword">print</span> f.read() f.close() sleep(<span class="hljs-number">300</span>) <span class="hljs-comment">#uploads DHT22 sensor values every 5 minutes </span> <span class="hljs-keyword">except</span>: <span class="hljs-keyword">print</span> <span class="hljs-string">'exiting.'</span> <span class="hljs-keyword">break</span> <span class="hljs-comment"># call main </span> <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>: main()

 

I have no idea how to get it more readings to send, and also the fact that I need to send to more than one channel might be tricky..

Any help appreciated, thanks!

March 15, 2018
3:57 pm
Avatar
thingspeak4matt
New Member
Members
Forum Posts: 2
Member Since:
March 14, 2018
sp_UserOfflineSmall Offline

""" baseURL = 'https://api.thingspeak.com/update?api_key=%s'
dht22.py
Temperature/Humidity monitor using Raspberry Pi and DHT22.
Data is displayed at thingspeak.com
Original author: Mahesh Venkitachalam at electronut.in
Modified by Adam Garbo on December 1, 2016
"""
import sys
import RPi.GPIO as GPIO
from time import sleep
import Adafruit_DHT
import urllib2
count = 0
myAPI = "JDYURK8TAGWRZL29"
def getSensorData21():
  RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 21)
  return (str(RH), str(T))
def getSensorData16():
  RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 16)
  return (str(RH), str(T))
def getSensorData26():
  RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 26)
  return (str(RH), str(T))
def getSensorData12():
  RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 12)
  return (str(RH), str(T))
def getSensorData20():
  RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 20)
  return (str(RH), str(T))

print 'starting...'
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % "JDY####"
RH, T = getSensorData21()
f = urllib2.urlopen(baseURL +
                          "&field1=%s&field2=%s" % (RH, T))
print f.read()
f.close()
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % "CYJ####"
RH, T = getSensorData16()
f = urllib2.urlopen(baseURL +
                         "&field1=%s&field2=%s" % (RH, T))
print f.read()
f.close()
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % "CYJ####"
RH, T = getSensorData26()
f = urllib2.urlopen(baseURL +
                        "&field3=%s&field4=%s" % (RH, T))
print f.read()
f.close()
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % "I9Q####"
RH, T = getSensorData12()
f = urllib2.urlopen(baseURL +
                         "&field1=%s&field2=%s" % (RH, T))
print f.read()
f.close()
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % "I9Q####"
RH, T = getSensorData20()
f = urllib2.urlopen(baseURL +
                         "&field3=%s&field4=%s" % (RH, T))
print f.read()
f.close()
print 'end'
sleep(30) #uploads DHT22 sensor values every 5 minutes

 

I have had some luck with the above code above, but the channel fields 3 and 4 of the second sensor do not upload 🙁

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
43 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

gwenbk2, eloisedq3, AEtedesar, RichardWosus, Kellynapse, tejomaya

Administrators: Hans: 387, lee: 457