-
Notifications
You must be signed in to change notification settings - Fork 64
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
Unable to set line 4 to input #27
Comments
maybe you have to run as root? not sure - the code works as you said, just not in Flask |
..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.... |
try killing any 'libgpiod_pulsein' processes |
Same issue occurring here - not using Flask at all though. Worked on the first try when on fresh boot, but then subsequent executions would fail. Changing the pin and running the program had the same effect, worked the first time and subsequent attempts would fail with example:
Locating the process Thanks!!! |
Works, thank you! |
In my case, Fortunately, changing the PIN to Still no idea what is blocking GPIO4 though. |
Short answerRemove What was going on?This problem drove me nuts but I think I found the root cause! In my case, I was encapsulating the DHT22 object in another object, like so:
My
And look what an interesting output I got:
The MainThread was initializing my object twice! How was that? Well, if you look at the documentation of Flask's
So, it seems that Flask just relaunches the application or something like this. Not clear to me, to be honest. But well, if you just remove
I hope this helps. Happy coding! |
This is a temporary solution right? It happens every time I stop the code and re-run it. Any solution? |
In my case, Pi 3 A+, only pin 11 (aka GPIO17/board.D17) worked. Neither of the other pins suggested here worked. ¯_(ツ)_/¯ |
Also seeing the same problem! |
Their old library worked for me. https://github.com/adafruit/Adafruit_Python_DHT |
I'm also seeing this problem on a RPi4. Also, the libgpio_pulsein task uses 25% of my CPU throughput! The old library worked fine for me too. I'm going to revert and see what happens. |
Did you guys try to remove |
Not even using Flask - just this script, is enough to make the RPI4 hang:
|
Yeah it is happening even to their sample code. Just try to run the code. Stop it. They run it again.
…On May 3, 2020, 7:50 AM +0530, Alexandre Lemaire ***@***.***>, wrote:
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)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Reverted to the old lib just now, that one's working a treat. |
First of all, if you don't have the I'm also affected by this bug as my temperature logger script (5min cronjob) suddenly stopped working after 23 hours, so I did some analysis: Following the stringThe output string // set to an input
if (gpiod_line_request_input(line, consumername) != 0) {
printf("Unable to set line %d to input\n", offset);
exit(1);
} adafruit/libgpiod_pulsein:/src/libgpiod_pulsein.c#L237-L241. This executable is called in PulseIn ?A quick look into PulseIn.py reveals that def deinit(self):
"""Deinitialises the PulseIn and releases any hardware and software
resources for reuse."""
# Clean up after ourselves
self._process.terminate()
procs.remove(self._process)
self._mq.remove()
queues.remove(self._mq)
def __enter__(self):
"""No-op used by Context Managers."""
return self
def __exit__(self, exc_type, exc_value, tb):
"""Automatically deinitializes the hardware when exiting a context."""
self.deinit() PulseIn usage in adafruit_dhtAs Best wishes, PS: # We don't use a context because linux-based systems are sluggish
# and we're better off having a running process
if _USE_PULSEIO:
self.pulse_in = PulseIn(self._pin, 81, True) adafruit/Adafruit_CircuitPython_DHT:adafruit_dht.py#L66-L67 |
@kerel-fs thanks for your explain. I've a case with two call in the same py script. The First is OK and the second failed with "Unable to set line xxx to input" My script like that : _def lecture_temp_DHT (type_capteur, pin):
And i wan't to be sure that the libgpiod_pulsein process will be kill before exiting this function |
I find an unclean solution with this code to kill process |
I agree with you. Why not solving the problem instead of patching it? I got fed up dealing with stack of problems just to read this device. I wrote a simple python program that sends the start signal via the GPIO output, and then reads the 40 bits from the dth22, and get the result in humidity and temperature. It is a very simple process that uses only the gpio and time libraries. What else should we really need? |
@guytas Would you mind sharing this script? I've been fighting multiple issues with libgpoid and would love to just leave it behind. |
Yes no problem. Let me figure out how to make it public on github. I hope you have a pi4. I do not check or validate the os. I’ll probably do that tonight. |
So this is a super hacky work around to this problem, all I've done is force an ImportError when the adafruit_dht.py script attempts to import PulseIn. Once it fails to import PulseIn it will attempt to use bitbang instead, this works for me but I guess it depends on your specific use case whether or not it will work for you Anyway, I modified line 37 in the adafruit_dht.py file located in dist-packages (remember to sudo here as this file is protected). I changed "from pulseio import PulseIn" to "from pulseio import PulseIn1" this then causes an ImportError and then PulseIo is not used which means the pin won't be blocked after exiting the code As I said, it's hacky but for now it's a work around to this problem I tried using the old repo but for some strange reason it wouldn't work on my RPi 4, it kept trying to run the BeagleBone code which obviously does not work. Hopefully the Adafruit team can solve this properly in a future release |
@brocktucker , I have it ready for you to try amd let me know how it works for you. How do we send personal message in here? |
Same issue here with
|
I revert back to the old library, everything works fine. |
This issue will be fixed by Pull Request #46 with implementing what is described in #27 (comment). |
I didn't see the PR, thanks. The |
Yes! Thank you!
|
I aint using flask, i dont even know what it is, just a basic board layout using the DHT11 as per many tutorials, i switched to circuit python and find it's quite rubbish giving me the input and pulse errors frequently documented elsewhere as well which i cant resolve via code. rebooting/killing process's every time to make buggy code run is just no solution at all, so i changed back to use the old library as per the link here: (i added the following to the file described) elif match.group(1) == 'BCM2711': c'mon adafruit developers, fix it or at least tell us how to reset everything when your script is launched |
Did you enabled 1-wire interface when using GPIO4? |
I thought i'd retry this today, i'm using D18 and 1-wire interface has never been enabled. i found that by killing the libgpiod process it all worked, but came back the next time the program was run (same as others found). i also tried using dht.exit() when my program closed, but no luck here either. I'm shocked at how bad the circuit python code is, with no support from the developers. i just cant see how anyone can run the published circuit python code using the standard instructions and sample code, as id consider my pi pretty standard, with the old deprecated code seemingly working fine (which i'm still forced to stick with). - anyone any new ideas? thanks |
In my case, a program executes a python script parallels.
It works for me. |
I am getting this error , i am using raspi4b pin GPIO21 ( pin -40 ) |
Hello for everyone, im already using raspi w zero, my sensor works really good with old version, but with the new one, i am stock after this step, bc i get this response, when : import time Traceback (most recent call last): apparently it fails for some buffer, but i dont know what should i do next. thanks for any help |
I also tried to install on my venv "python 3.7" the oldest version, but it doesnt works, it says that this requirement is already satisfaid, so i check using pip list on venv , and i realize that i cant install correctly. i really apreciate any help. |
CONSIDERATION 1)I think the line that would prevent the 504 Error page is this: CONSIDERATION 2)For the 502 Bad Gateway Error, I discovered when running the above dht_simpletest.py and watching, that every few lines, the sensor would not be read and it would throw an Runtime Error...it would read like this:
The So, I implemented this same principal in my Flask python setup, and the HTML page has been running for 15 minutes without crashing :) The try portion is the original code, but see in the except, I catch the RuntimeError, and then I just hard-coded 99 for both temperature and humidity. This could probably be setup better for the database just to ignore this reading...or to get really fancy, use linear interpolation and get a value of the prior and next :)
Hope this helps some of the Raspberry Pi / Flask users on this issue...and maybe give similar ideas to the rest. |
It works for me to. But I don't know why. |
The solution that I found was: Acording to the group comments, this declaration |
adding dhtDevice.exit() at the end of the code apparently kills the obstinate system process from within the program. I just see that this has been pointed out before. I had to replace the While statement by a finite "range" loop, however, as the last line must be reached naturally, I guess. |
Everytime the programs stops without reaching ' dhtDevice.exit()', the offending process must be killed manually. |
resolved & closed. |
for proc in psutil.process_iter():
if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei':
proc.kill() it works for me |
Thank you, ropering! |
my problems mysteriously went away, could have just been loose jumper cables or something? |
so I too was having this issue. I found that if you set use_Pulseio=False when you declare the pin# then the issue clears up. didnt see this anywhere commented above. Just wanting to help out. |
I'm trying to make a Raspberry Pi 3 REST API that provides temperature and humidity with DHT22. The whole code:
However, when I start server, it shows message
and temperature and humidity is always None. If I don't run flask app but just DHT code, it works.
The text was updated successfully, but these errors were encountered: