question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to set line 4 to input

See original GitHub issue

I’m trying to make a Raspberry Pi 3 REST API that provides temperature and humidity with DHT22. The whole code:

from flask import Flask, jsonify, request
from sds011 import SDS011
from adafruit_dht import DHT22
import board
import os
import time

app = Flask(__name__)
dht = DHT22(board.D4)

def get_dht_data():
    while True:
        try:
            temperature, humidity = dht.temperature, dht.humidity
            print(temperature, humidity)
            if temperature is not None and humidity is not None:
                return temperature, humidity
            else:
                raise
        except:
            time.sleep(0.5)

@app.route('/', methods=['GET'])
def status():
    temperature, humidity = get_dht_data()

    return jsonify({
        'temperature': temperature,
        'humidity': humidity
    })

if __name__ == '__main__':
    app.run(debug=True)

However, when I start server, it shows message

Unable to set line 4 to input

and temperature and humidity is always None. If I don’t run flask app but just DHT code, it works.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:46 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
monkeywirecommented, Jan 24, 2020

…it seems to work fine when I first boot up the raspberry pi and I can run the test code once and it works… After that if I try to run to the test code a second time I get the same error…

6reactions
Saevencommented, May 3, 2020

Not even using Flask - just this script, is enough to make the RPI4 hang:

import time
import board
import adafruit_dht

dhtDevice = adafruit_dht.DHT22(board.D4)
Read more comments on GitHub >

github_iconTop Results From Across the Web

DHT22 sensor Unable to set line 4 to input - Adafruit forums
I have been trying to get a DHT22 (actually an AM2302) sensor to read on Pi zero. I used the latest circuit python...
Read more >
unable to set line to input - Stack Overflow
I found a solution, by writing use_pulseio=False solves the problem: dhtDevice = adafruit_dht.DHT22(board.D17, use_pulseio=False).
Read more >
Unable to set line 6 to input. DHT11 - Raspberry Pi Forums
Hello! I'm just a beginner with raspberry. I'm building a greenhouse for micro greens. Plan is to monitor temperature and humidity.
Read more >
DHT11 Sensor With Raspberry PI and Python - peppe8o
To configure the DHT11 humidity sensor on a Raspberry Pi you need to connect ... Insert the following code: ... Gives error "unable...
Read more >
Pi4 and adafruit_dht.py intermittent read failure of dht22 sensor
pigrow reports Unable to set line XX to input read failure. I think i have followed it to this bug/ thread in adafruit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found