0

2 DHT11 per RPI Zero W issues
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

2 DHT11 per RPI Zero W issues

by OriginalMrP on Sat Aug 17, 2019 5:27 am

Hello,
I've followed and implemented the Adafruit IO guide and script for the Temperature and Humidity, changing it slightly for the DHT11 rather than the DHT22's.
This works well reporting from 3 RPI Zero W's with a single DHT11 per board.
However, I've been asked to add an additional sensor per rpi and I'm stuck.

I've tried adding the the GPIO pin to the script and addtional feed info without luck.

Can anyone provide a suggestion/guide to how I can modify the script to include two sensors?

Script taken from https://learn.adafruit.com/adafruit-io- ... ython-code

Thank you

OriginalMrP
 
Posts: 5
Joined: Wed Aug 14, 2019 4:38 pm

Re: 2 DHT11 per RPI Zero W issues

by jerryn on Sat Aug 17, 2019 5:52 am

What have you done to add the second sensor -- can you post the code you are using between {CODE} tags?

Did you create a second instance of the sensor
Code: Select all | TOGGLE FULL SIZE
dht22_sensor2 = Adafruit_DHT.DHT22
then assign the new pin to it

Code: Select all | TOGGLE FULL SIZE
 humidity2, temperature2 = Adafruit_DHT.read_retry(dht22_sensor2, DHT_DATA_PIN2)

jerryn
 
Posts: 990
Joined: Sat Sep 14, 2013 9:05 am

Re: 2 DHT11 per RPI Zero W issues

by kflmiami420 on Sat Aug 17, 2019 6:36 pm

can you post up your code

kflmiami420
 
Posts: 93
Joined: Tue Aug 21, 2018 9:43 pm

Re: 2 DHT11 per RPI Zero W issues

by OriginalMrP on Sun Aug 18, 2019 4:34 am

HI,
below is the code being used.
I've tried inserting the additional sensor info below the 'Data Pin Info' without luck. I'm at a loss to wear to input the addtional sensor code.

Thank you


==================================


Dependencies:
- Adafruit IO Python Client
(https://github.com/adafruit/io-client-python)
- Adafruit_Python_DHT
(https://github.com/adafruit/Adafruit_Python_DHT)
"""

# import standard python modules.
import time

# import adafruit dht library.
import Adafruit_DHT

# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed

# Delay in-between sensor readings, in seconds.
DHT_READ_TIMEOUT = 60



# Pin connected to DHT22 data pin
DHT_DATA_PIN = 4


# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = '111-111'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username).
ADAFRUIT_IO_USERNAME = '111-111'

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Set up Adafruit IO Feeds.
temperature_feed = aio.feeds('pi3.temperature')
humidity_feed = aio.feeds('pi3.humidity')


# Set up DHT22 Sensor.
dht11_sensor = Adafruit_DHT.DHT11

while True:
humidity, temperature = Adafruit_DHT.read_retry(dht11_sensor, DHT_DATA_PIN)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
# Send humidity and temperature feeds to Adafruit IO
temperature = '%.2f'%(temperature)
humidity = '%.2f'%(humidity)

aio.send(temperature_feed.key, str(temperature))
aio.send(humidity_feed.key, str(humidity))



else:
print('Failed to get DHT11 Reading, trying again in ', DHT_READ_TIMEOUT, 'seconds')
# Timeout to avoid flooding Adafruit IO
time.sleep(DHT_READ_TIMEOUT)


[/code]

OriginalMrP
 
Posts: 5
Joined: Wed Aug 14, 2019 4:38 pm

Re: 2 DHT11 per RPI Zero W issues

by jerryn on Sun Aug 18, 2019 6:18 am

Sorry, my first suggestions assumed you were using the "Circuitpython" libraries on the Raspberry Pi.
Following your example, I think something like this should do what you want. There are lots of ways to make it clearner and not have so much repeated code, but try this for a start.
Code: Select all | TOGGLE FULL SIZE
# import standard python modules.
import time

# import adafruit dht library.
import Adafruit_DHT

# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed

# Delay in-between sensor readings, in seconds.
DHT_READ_TIMEOUT = 60



# Pin connected to DHT22 data pin
DHT_DATA_PIN = 4
# Pin for second DHT11 ( 5 for example -- use an availalbe GPIO Pin)
DHT_DATA_PIN2 = 5


# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = '111-111'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username).
ADAFRUIT_IO_USERNAME = '111-111'

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Set up Adafruit IO Feeds.
temperature_feed = aio.feeds('pi3.temperature')
humidity_feed = aio.feeds('pi3.humidity')
# additionalal feeds for second DHT11
temperature_feed2 = aio.feeds('pi3.temperature2')
humidity_feed2 = aio.feeds('pi3.humidity2')


# Set up DHT22 Sensor.
dht11_sensor = Adafruit_DHT.DHT11
# setup second sensor
dht11_sensor2 = Adafruit_DHT.DHT11

while True:
    humidity, temperature = Adafruit_DHT.read_retry(dht11_sensor, DHT_DATA_PIN)
    if humidity is not None and temperature is not None:
        print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
        # Send humidity and temperature feeds to Adafruit IO
        temperature = '%.2f'%(temperature)
        humidity = '%.2f'%(humidity)

        aio.send(temperature_feed.key, str(temperature))
        aio.send(humidity_feed.key, str(humidity))
    else:
        print('Failed to get DHT11 Reading, trying again in ', DHT_READ_TIMEOUT, 'seconds')
    humidity2, temperature2 = Adafruit_DHT.read_retry(dht11_sensor2, DHT_DATA_PIN2)
    if humidity2 is not None and temperature2 is not None:
        print('Temp2={0:0.1f}*C Humidity2={1:0.1f}%'.format(temperature2, humidity2))
        # Send humidity and temperature feeds to Adafruit IO
        temperature2 = '%.2f'%(temperature2)
        humidity2 = '%.2f'%(humidity2)

        aio.send(temperature_feed2.key, str(temperature2))
        aio.send(humidity_feed2.key, str(humidity2))
    else:
        print('Failed to get second DHT11 Reading, trying again in ', DHT_READ_TIMEOUT, 'seconds')



    # Timeout to avoid flooding Adafruit IO
    time.sleep(DHT_READ_TIMEOUT)

jerryn
 
Posts: 990
Joined: Sat Sep 14, 2013 9:05 am

Re: 2 DHT11 per RPI Zero W issues

by OriginalMrP on Sun Aug 18, 2019 8:35 am

Jerry, thank you, thank you, thank you!

It works perfectly and more importantly it provides a good base for me to compare the original, what I was trying to do and a working script.
This means I can compare and learn from this.

Cheers

OriginalMrP
 
Posts: 5
Joined: Wed Aug 14, 2019 4:38 pm

Re: 2 DHT11 per RPI Zero W issues

by jerryn on Sun Aug 18, 2019 8:50 am

Great! Glad to help! Good luck with your project!

jerryn
 
Posts: 990
Joined: Sat Sep 14, 2013 9:05 am

Re: 2 DHT11 per RPI Zero W issues

by OriginalMrP on Sun Aug 18, 2019 9:00 am

jerryn wrote:Great! Glad to help! Good luck with your project!

Cheers,
I just have to install the sensors under the floorboards and get them all up and running.
This week it's testing to make sure everything works and thanks to you so far so good.

Annotation 2019-08-18 135205.jpg
Annotation 2019-08-18 135205.jpg (134.05 KiB) Viewed 110 times

OriginalMrP
 
Posts: 5
Joined: Wed Aug 14, 2019 4:38 pm

Re: 2 DHT11 per RPI Zero W issues

by kflmiami420 on Mon Aug 19, 2019 3:06 pm

What rate are you using to upload to th eAdafruit IO with out getting any errors ?
Last edited by kflmiami420 on Mon Aug 19, 2019 3:09 pm, edited 1 time in total.

kflmiami420
 
Posts: 93
Joined: Tue Aug 21, 2018 9:43 pm

Re: 2 DHT11 per RPI Zero W issues

by kflmiami420 on Mon Aug 19, 2019 3:08 pm

Thats a lot of sensors. Also Double up on the sensors and wires .


Two sensors per floor board so you can have redunce and should a sensor fail you dont have to remove floor panels just re wire the back up sensor .

kflmiami420
 
Posts: 93
Joined: Tue Aug 21, 2018 9:43 pm

Re: 2 DHT11 per RPI Zero W issues

by OriginalMrP on Tue Aug 20, 2019 3:53 am

I’ll be using just two DHT11’s per RPI Zero W, locating them at different locations under the floor.
Currently they are set to report every 60seconds which seems reliable.
As Adafruit only allows 10 feeds for free, I’ll be using all 6 humidity feeds and 3 temp feeds.

So far everything seems to be working just fine, but I’ll be installing them in my in-laws house over the weekend (I’m UK based, they are in the Czech Republic).
I’m looking forward to remotely monitoring the system.




kflmiami420 wrote:Thats a lot of sensors. Also Double up on the sensors and wires .


Two sensors per floor board so you can have redunce and should a sensor fail you dont have to remove floor panels just re wire the back up sensor .

OriginalMrP
 
Posts: 5
Joined: Wed Aug 14, 2019 4:38 pm

Please be positive and constructive with your questions and comments.