mlx90640_python
mlx90640_python copied to clipboard
Program crashes with PiCameraRuntimeError "Timed out waiting for capture to end"
Hi,
I've tinkered a little bit with your code in order to make it run fullscreen and I placed an instruction in /etc/xdg/lxsession/LXDE-pi/autostart
to make it autostart when the LXDE starts. The rest of the code is pretty much the same original one.
However sometimes when I boot up the raspberry the code crashes and by redirecting stderr on a log file I found out this traceback:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1704, in capture_continuous
'Timed out waiting for capture to end')
picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/mlx90640-library/thermal.py", line 45, in <module>
for frame in camera.capture_continuous(rawCapture, format="rgb", use_video_port=True):
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1710, in capture_continuous
encoder.close()
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 431, in close
self.stop()
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 419, in stop
self._close_output()
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 349, in _close_output
mo.close_stream(output, opened)
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 371, in close_stream
stream.flush()
File "/usr/lib/python3/dist-packages/picamera/array.py", line 238, in flush
self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution)
File "/usr/lib/python3/dist-packages/picamera/array.py", line 127, in bytes_to_rgb
'Incorrect buffer length for resolution %dx%d' % (width, height))
picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 288x368
I'm not expert on the picamera and the odd thing is that other times it works perfectly. If there was an error for the buffer length for resolution, shouldn't the code always fail instantly? Is there a way to fix this issue?
Weird. Looks like it tries to pull a frame form the picam, but the picam isnt ready. Try putting a reasonable delay in the script before starting the picam, then another after initialization and before pulling frames. See if that fixes it. I'm no expert on the picam either, but it can be a bit awkward at times, and seems to need time to settle.
I tried right now putting time.sleep(0.3)
before and after camera = PiCamera()
and before for frame in camera.capture_continuous(rawCapture, format="rgb", use_video_port=True):
.
There's still the same issue: sometimes it works and continues working, other times it works for a couple of seconds and then crashes with the stacktrace previously shown.
I think you need a much bigger delay than that. In some instances I have put in delays as long as 10 seconds to ensure stuff has settled down. When you call the script from autostart is there any significant delay in there? I had a similar issue trying to autostart a chromium session in kisok mode, where the executable was being called before other programs it relied on (and networking) had been loaded. You need to give LXDE a chance to settle down first...
With a 7 seconds delay, the initial crashes occur less frequently. Since for UX reasons I don't want to have too much delay, I coded a monitor that restarts the application when it crashes (and when it crashes, it happens only once during the firsts seconds, so it does not bother me too much).
I have another question that is slightly off-topic, but I don't think it deserves another issue page, so I'm gonna ask it here:
why is there a if(val > 99.99) val = 99.99;
check on line 115 of mlx90640_driver.cpp
?
I tried commenting it in order to register higher temperatures, then tested it on the burners on my stove, it does detect higher temperature without me noticing any problem.
Hi, cool. You asked: why is there a if(val > 99.99) val = 99.99; check on line 115 of mlx90640_driver.cpp? I did it to normalize the colorization of the display for likely temperatures in a room like setting. I figured it was unlikely for my application to come across anything at over 100 deg for the thing I was using it for. Feel free to hack it up for your purpose. The MLX90640 is capable of reading up to 300 Degrees Celcius, and down to -40.
Ok, thanks!
How did you compile the Mlx90649_driver.cpp - do I need the bcm8235 lib installed ? - I have tried Geany on the Pi and I get errors. If I test the circuit with i2cdetect -y 1, I get back the i2c address 33 - but all the compiler in Geany say is that the address is unknown Can anyone offer any help ?