Unable to set line 4 to input
See original GitHub issueI’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:
- Created 4 years ago
- Reactions:2
- Comments:46 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…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…
Not even using Flask - just this script, is enough to make the RPI4 hang: