11

There are lots of guides which tell you how to configure the raspberry Pi Zero as a mass_storage device or Ethernet device, most of these mention the ability to make the Pi act as a webcam but none have explained how to do it.

I've tried following the guide in the documentation in conjunction with the UVC (webcam) documentation to try and figure out how to configure it but so far i can't even get my computer to recognise that there is something plugged in. The only thing I can find on the topic is this thread which makes me think that the is kinda obscure.

How do you set up the camera? Is there a guide? am I fighting a losing battle?

5
  • 1
    "am I fighting a losing battle?" -> I'm thinking you're going to have to end up learning a lot about the system and USB protocol unless you can find some ready-made code for this. Like maybe weeks and months worth of learning...
    – goldilocks
    Commented Jul 14, 2016 at 20:09
  • 1
    I've been reading up on it for a while now the problem is that I don't know what some of the entries for defining the function of the webcam mean or (to put it better) what the host expects. On the second link is the documentation for it but some of the stuff is a bit obfuscated without the correct knowledge. When you look for dumps of commercial webcams USB descriptors some of the fields are empty... The other thing is that i have no idea what language the USB functions are and were to put the code so that it works... Something that I can't find online Commented Jul 15, 2016 at 15:07
  • 1
    My first foray into writing linux device drivers was intended to get an unsupported USB camera working. When I got to where I realized how much backward engineering was required I quit -- it was not a worthwhile pursuit for me. However, USB video is now standardized, meaning most generic standard cameras do not require a special driver beyond that. That should be all publicly available, and that's what you want the zero to mimic -- a UVC standard compliant device. Don't bother trying to reverse engineer a commercial camera!
    – goldilocks
    Commented Jul 15, 2016 at 15:23
  • 1
    Well the problem for me is that I don't know how to get the Raspberry Pi zero to be recognised which is why I went looking for commercial Webcam USB descriptors to shed some light into what the host USB expects from a standard device. The next problem is getting the Pi to take a picture via the board cam on demand Commented Jul 16, 2016 at 15:36
  • 1
    Saw this link, with good reviews by others: davidhunt.ie/raspberry-pi-zero-with-pi-camera-as-usb-webcam He has a video proof of it working as well, hope this helps. Commented Jun 7, 2020 at 19:41

7 Answers 7

5

After searching a lot I finally have this working now

to get it working I used the following script for the configfs setup https://gist.github.com/kbingham/c39c4cc7c20882a104c08df5206e2f9f

and this version of the uvc-gadget tool https://github.com/wlhe/uvc-gadget

2
  • You are just saying "look at this links how it works" but we're looking for long answers that provide some explanation and context. Don't give a short answer just pointing to links; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed or you risk to get down votes.
    – Ingo
    Commented Feb 10, 2019 at 12:30
  • Looks like this is basically the official answer from the Pi foundation as they link to post here which shares the same resources, if you scroll down to a reply from "Gordon Hollingworth" on this blog post raspberrypi.org/blog/… Commented May 2, 2020 at 10:31
5

I have this enumerating and streaming synthetic uncompressed data to FaceTime via my Raspberry Pi Zero W. The ConfigFS example in the kernel gadget documentation works for the most part. It has some typos when it comes to proper ../.. path navigation, the streaming_maxpacket field which no longer exists in ConfigFS, and you'll need to set bDeviceClass=239, bDeviceSubClass=0x02, bDeviceProtocol=0x01. However, for starters it's actually simpler to just run the legacy modprobe g_webcam. I'm assuming you have the required dtoverlay=dwc2 and have tested other gadget modules like g_serial. It sounds like you might already be using g_ether or the ConfigFS equivalent for your workaround networking solution.

When you enable the g_webcam module, it won't enumerate on a typical Mac/Windows/Linux PC until the userspace uvc-gadget program is running. Setting this up has its pitfalls as the required patches were never fully reviewed by Laurent Pinchart and introduce bugs of their own. You can find my patched repo with fixes here. I have run that with ./uvc-gadget -d -u /dev/video0 on both Raspbian 8 Jessie and Raspbian 9 Stretch.

I'm basically describing the same steps as you saw joe60 did on the Raspberry Pi forums, but as it's a very error-prone procedure having another reference point shouldn't hurt.

Note that even once you have the base case working there's a large cross-product of cases for the format (-f), memory type (-o), bulk vs isochronous (-b) and image data source (-d vs -i vs -v), much of which may have limited support in the uvc-gadget application.

2
  • The problem with this is that it requires an internet connection and a fast enough connection to both upload and download it all again. It might work fine for some and with some effort I could build something which is hosted on the target device that it is connected to too get images so no internet is required. At this point I've basically decided that I'm going to build some FPGA device to get images directly from the image sensor. But your right more references the better for someone trying this, maybe at some point this will be possible over just a USB connection but till then... :) Commented Sep 2, 2018 at 12:17
  • On second thought I did start building something which works in a similar way github.com/crener/MultiCapture. It's mostly for still images from multiple cameras but it might help someone who is trying to do just that. It's a bit rough but works and documentation is iffy but make an issue on github and i'll help you out :) Commented Sep 2, 2018 at 12:29
1

There is a g_webcam gadget mode driver. I'd imagine if you played with the source you could redirect a uvc stream to the webcam, although it would likely be slow, it would fulfil your remit.

source: https://github.com/torvalds/linux/blob/master/Documentation/usb/gadget-testing.txt#L656

1

Use showmewebcam

0

If the computer won't recognize the camera the cable may be upside down where it plugs in, there are only contacts on one side. Buying a USB or IP camera is another option, I have some D-links that send over wifi. Lower resolution but meant to be remote cameras with features like motion detection and a built-in web server.

8
  • The USB type A cable may be upside down? Commented Oct 11, 2017 at 12:39
  • No, between the camera and the Pi. Where the camera cable plugs into the Pi the contacts may be on the wrong side. Or the same thing on the other end of the cable, there's no key to prevent you from putting it in backwards. I'm not sure how you stream video off the Pi, V4L somehow probably.
    – Alan Corey
    Commented Oct 11, 2017 at 23:45
  • So your solution to "How do i get the Pi Zero to act as a webcam?" is plug in the camera or buy a new one? Commented Oct 12, 2017 at 10:25
  • Getting the actual camera to work with the Zero is tricky enough without the fancier stuff. I have no interest in video. I just put this page online ab1jx.1apps.com/ham/toys/picam/index.html but I still need to take pictures of the camera to Pi connectors. If even raspistill won't work, that's what I'm covering.
    – Alan Corey
    Commented Oct 13, 2017 at 14:13
  • I also have little interest in video. At the time when i posted this question I wanted to use USB to essentially control the camera from another computer. I have since coded up a networked capture utility that will let me take multiple images at the same time from different cameras on different Pis. It would still be cool to have it all work directly as Webcams but for now I'm using each Pi as an ethernet device with my software running on it Commented Oct 13, 2017 at 16:05
0

To be able to stream and take snapshots you can use this streamer library that basically streams JPEG. It is customisable and straightforward to use. And you don't have to know how it works. It also supports the official RPi Camera apart from USB cameras with a linux driver.

Here is the link to mjpg-streamer.

-1

This guide shows you how to install and run a docker container and live video stream to youtube from a pi zero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.