We are trying to run an object detection program in a Raspberry Pi 3B+ with Ubuntu Server. We are connecting the following devices to the USB ports:
- USB Camera
- Microphone
- Arduino
This is the Python code that we use to ensure that the USB camera is found:
import cv2, glob
for camera in glob.glob("/dev/video?"):
print(camera)
c = cv2.VideoCapture(camera,cv2.CAP_V4L2)
if(c.read()[0]):
print("Working index")
print(c.get(cv2.CAP_PROP_FRAME_WIDTH),c.get(cv2.CAP_PROP_FRAME_HEIGHT))
If this code succeeds, the rest of the program proceeds with the object detection.
This works well for the first few runs of the program (~ 6-10). Eventually, we get the following error:
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (1004) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
After getting this error, all the USB ports get disabled and the program doesn't run again until we reboot the Raspberry Pi.
Occasionally, we also get the following message:
uvcvideo: Failed to resubmit video URB (-1)
To solve this, we have tried removing the uvcvideo drivers and reapplying them again, as suggested here and on many other sites. However, we have not been successful.
We have also tried:
- Using different power supplies.
- Disabling ethernet and connecting through wifi to save bandwidth.
- Disabling bluetooth.
- Disconnecting every other peripheral except the camera to save more bandwidth.
- Lowering the resolution of the camera.
Does anybody know how to solve this issue?
Alternatively, if we can't get rid of these errors, is the only solution to reboot the Pi? Or is there a workaround to get it working again?