10

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?

user3797758
  • 281
  • 1
  • 4
  • 14
  • 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 Jul 14 '16 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 – user3797758 Jul 15 '16 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 Jul 15 '16 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 – user3797758 Jul 16 '16 at 15:36
  • 1
    Saw this link, with good reviews by others: http://www.davidhunt.ie/raspberry-pi-zero-with-pi-camera-as-usb-webcam/ He has a video proof of it working as well, hope this helps. – Vitalijs Arkulinskis Jun 07 '20 at 19:41

7 Answers7

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

Raatje
  • 174
  • 1
  • 1
  • 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 Feb 10 '19 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 https://www.raspberrypi.org/blog/new-product-raspberry-pi-high-quality-camera-on-sale-now-at-50/ – user3797758 May 02 '20 at 10:31
4

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.

jdonald
  • 2,904
  • 12
  • 39
  • 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... :) – user3797758 Sep 02 '18 at 12:17
  • On second thought I did start building something which works in a similar way https://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 :) – user3797758 Sep 02 '18 at 12:29
1

Use showmewebcam

Janghou
  • 1,446
  • 1
  • 16
  • 20
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

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.

Alan Corey
  • 201
  • 1
  • 6
  • The USB type A cable may be upside down? – user3797758 Oct 11 '17 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 Oct 11 '17 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? – user3797758 Oct 12 '17 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 http://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 Oct 13 '17 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 – user3797758 Oct 13 '17 at 16:05
  • I have doubts about the quality of the image it's possible to get out of the camera and I'm not sure how much time to put into it since I have better cameras. Nothing else is as programmable though, everything else is canned software. One experiment would be to determine optimum exposure time by finding and looking at the brightest pixel in the scene. Procrastinating over rigging a better binocular magnifier so I can get the camera's lens off to see why the pictures are so awful. Maybe there's a residue from the tape they put over the new lens as protection. – Alan Corey Oct 14 '17 at 17:24
  • I looked at that site and the images that I get with the official camera are better than the cheap one that you're using... I'm guessing that the lens assembly isn't as good... – user3797758 Oct 14 '17 at 17:29
  • Which camera version do you have though, this is a 1.3. It is an official camera I think, just 5 years or so old. Maybe it was built for raspberrypi.org but never left China until now, It's been in some warehouse. Or it was returned as defective although the little tape over the lens seemed intact. I'd never tried one outdoors before and I'm comparing it to $400 Nikons. – Alan Corey Oct 14 '17 at 23:24
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.

paj
  • 311
  • 1
  • 6