Logitech C920S intermittently fails

I bought a new Logitech C920S webcam to replace an 8MP Raspberry Pi camera module. I switched the settings in octopi.txt to:

camera="auto"
camera_usb_options="-r 1920x1080 -f 30"
camera_http_webroot="./www"
camera_http_options=""

The camera shows up in the Control tab of OctoPrint and works beautifully. I'm also using OctoLapse, which recognizes it and gives me all the nice controls. Everything looks good until I try to print something. Sometimes the camera fails as soon as the printer starts moving. Other times it'll print for a few hours and then the stream goes dead.

Sometimes I can restart it by SSHing to the server and restarting webcamd:
sudo service webcamd restart
but sometimes this fails. If I check webcamd status right after restarting it, I get this:

Jan 04 10:53:40 octopi webcamd[1032]: i: TV-Norm...........: DEFAULT
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: Using V4L2 device.: /dev/video10
Jan 04 10:53:40 octopi webcamd[1032]: Error opening device /dev/video10: video capture not supported.
Jan 04 10:53:40 octopi webcamd[1032]: Init v4L2 failed !! exit fatal
Jan 04 10:53:40 octopi webcamd[1032]: i: init_VideoIn failed
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: Desired Resolution: 1920 x 1080
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: Frames Per Second.: 10
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: Format............: JPEG
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: TV-Norm...........: DEFAULT
Jan 04 10:53:40 octopi mjpg_streamer[1056]: MJPG-streamer [1056]: init_VideoIn failed

Then if I check it again a couple of seconds later:

Jan 04 10:53:43 octopi systemd[1]: webcamd.service: Service RestartSec=100ms expired, scheduling restart.
Jan 04 10:53:43 octopi systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 5.
Jan 04 10:53:43 octopi systemd[1]: Stopped the OctoPi webcam daemon with the user specified config.
Jan 04 10:53:43 octopi systemd[1]: webcamd.service: Start request repeated too quickly.
Jan 04 10:53:43 octopi systemd[1]: webcamd.service: Failed with result 'start-limit-hit'.
Jan 04 10:53:43 octopi systemd[1]: Failed to start the OctoPi webcam daemon with the user specified config.

Once this error shows up, restarting webcamd no longer fixes the camera. In fact, rebooting the machine no longer fixes it! What ultimately works is to power down the machine, unplug the camera from the USB port, start it up, wait a minute, shut it down, plug the camera back in, and boot again. Crazy I know. But then the camera shows up and works fine until I try to print.

My Raspberry Pi 3B+ is using a Canakit 2.5A power supply. I also tried swapping it for a 3A power supply just in case, but it made no difference.

I have a second Ender 3 Pro, identically configured except that its webcam is an Aukey FHD. Swapping the camera over to that machine made no difference; the Aukey works fine, and the Logitech fails intermittently on either machine.

Restarting Octopi in safe mode made no difference.

I'm not sure what else to try or check. Could it be a bad camera? Is this a solvable issue? Thanks for any help.

Hi boogul, Have you found some solution for this issue? I am having the same problem

Setup: Prusa MK3S+MMU2S+Raspberry4+Logitech c920+Octoprint+Octolapse.

Hi Jakub, unfortunately I have not. I was planning to switch to a clean install on a Pi 4 this weekend, hoping that maybe it was a power issue and the Pi 4 would be able to handle it. But if you're experiencing the same issue with a Pi 4, that's probably not the case.

I'm still going to try a fresh install on the off chance it's some software issue that apt-get update isn't fixing. Not sure what else to do. I'll post results here either way. Please let me know if you figure something out.

Just an update without a solution: I tried a fresh install of Octoprint on a brand new Pi 4 with no plugins and had the same issue. I also tried a burlier 3A power supply for the Pi 3s, just in case that was the problem. It was not.

The camera seems to only lose its connection in specific circumstances: The camera fails when I hit "stabilize extruder" in Octolapse, and also every time I start a new print. Once the print is underway if I restart the camera in SSH, it usually hangs on all the way to the end of the print. But not always.

Both of those circumstances involve large fast movements of the axes, so I suspect that that has something to do with why the camera loses its connection, although I have no idea why that would be.

I think you mean OctoPi:

Take in consideration that the camera might be faulty.
Also check the temperature of the USB chip on the Pi. Maybe it deserves a heat sink.

Thank you for your suggestions. You are correct that I installed Octoprint via the current (0.18.0) image of OctoPi, including MJPG-Streamer and whatever else it comes with. Sorry if I did not make this clear. I'm not sure what Home Assistant is and I don't understand the relevance.

I'm having this issue with two separate C920S cameras connected to two separate Ender 3s, so I think it's unlikely to be a faulty camera (unless it's a whole bad batch).

The Pi is in a Flirc aluminum case with a thermal pad that acts as a heatsink for the CPU. It hasn't shown any temperature warnings, but I'm not sure if it would for the USB hub chip. I haven't the faintest idea how to check the USB chip's temperature (or even where it is). Can you point me in the right direction there? Thanks!

It's the little chip behind/between the USB connectors. If you touch it with your finger and it burns, it's quite too hot.
A good heat sink case also has pads for the other chips on the board. The only chip with temperature watch is the CPU, the others are left on their own.

Thank you for the help here. Sorry it took me a while to fully dig into it. I took the Pi out of the case and touched the LAN7515 chip. It gets pretty warm to the touch, especially when there's a lot of USB activity. I wouldn't say it burns, but pretty warm.

I stuck a heatsink on the chip (the Pi apparently came with one for the CPU and one for the USB/ethernet chip that I never bothered to install). Unfortunately it doesn't seem to make any difference. The camera still drops, intermittently, in a way that seems to be connected to USB/printer activity.

I thought it might be an issue of insufficient available power (or too much power going through the USB hub), so I hooked up a powered external hub. I tried running just the camera through it, and also tried both camera and Ender 3. Neither helped.

Fixed it! I still don't know what's causing the problem, but here's the workaround:

Add the "-y" flag to the camera options in octopi.txt:
camera_usb_options="-r 1920x1080 -f 3 -y"

Apparently this puts the camera in YUYV mode, so it sends the raw image to the Pi instead of compressing it to MJPEG first. The Pi then has to work a lot harder, since it has to do the compression itself before streaming it out. Normally it's preferable to have that done on the camera's dedicated hardware rather than troubling the Pi. But for some reason that was causing my Pi to drop the camera. Once I added the -y flag, the problem went away completely.

However, it is a lot more processing for the Pi. Since i'm doing time-lapses that don't require a high framerate, I dropped it to 3fps, which it seems to be able to maintain just fine.