Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How set GPIO Pin for DHT22 over ENV Variable? #57

Closed
Tob1as opened this issue Jan 5, 2021 · 2 comments
Closed

How set GPIO Pin for DHT22 over ENV Variable? #57

Tob1as opened this issue Jan 5, 2021 · 2 comments

Comments

@Tob1as
Copy link

Tob1as commented Jan 5, 2021

Hello,

i use the example file dht_simpletest.py and replace D18 with D4 for use on Raspberry Pi 3.

But now I would like to set the pin over an enviroment variable. I add this to the script:

import os

DHT_DATA_PIN = int(os.environ.get('GPIO_PIN_DHT22', 4))

But now I have problem to replace the number 4 in this line:

dhtDevice = adafruit_dht.DHT22(board.D4)

This:

dhtDevice = adafruit_dht.DHT22(DHT_DATA_PIN)
# or
dhtDevice = adafruit_dht.DHT22(4)

works local on Raspberry, but not in Docker Container... error: self._pin = Pin(pin.id) AttributeError: 'int' object has no attribute 'id'. So i think i must use it with "board".

Can anyone help or have an idea? :-)

(My complete Code if it helps.)

@jposada202020
Copy link

@Tob1as Hello are you still need to solve this, I think this is maybe this is more a question than an issue. You could ask in the discord channel for Adafruit. However:

  1. Yes you need to pass the object in this case, meaning board.D4. I do not use docker but normally when I need to pass arguments, objects or other things between libraries I used a dictionary, something like this
    import board
    boardspins = {'D0': board.D0, 'D1': board.D1, 'D2': board.D2, 'D3': board.D3, 'D4': board.D4, 'D5': board.D5,
    'D6': board.D6, 'D7': board.D7, 'D8': board.D8, 'D9': board.D9, 'D10': board.D10,
    'D13': board.D13}
    pin4 = boardspins['D4']
    and then you will call them using dhtDevice = adafruit_dht.DHT22(pin4)

@Tob1as
Copy link
Author

Tob1as commented Feb 24, 2021

@jposada202020
Hello, thank you, that works. :-)

Now I hope for a solution for "A full buffer was not returned. Try again." also and then I am happy.

@Tob1as Tob1as closed this as completed Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants