pi-webcam icon indicating copy to clipboard operation
pi-webcam copied to clipboard

Feature Request: GPIO LED when camera is in use

Open pmottram opened this issue 4 years ago • 13 comments

Like most webcams, I'd like to have a LED that illuminates when the camera is recording video, and goes out once it is not.

Ideally a configurable GPIO pin - how easy is this?

pmottram avatar Jan 19 '21 23:01 pmottram

That's actually a great idea, not sure why I didn't even think of it. It doesn't seem impossible, but it would probably need to be part of the uvc-webcam project that this project sets up/clones.

geerlingguy avatar Jan 20 '21 03:01 geerlingguy

Looking a bit upstream suggests it is an option (-p) in the uvc-gadget package:

Usage: ./uvc-gadget [options]

Available options are
    -b value       Blink X times on startup (b/w 1 and 20 with led0 or GPIO pin if defined)
    -f device      Framebuffer device
    -h             Print this help screen and exit
    -l             Use onboard led0 for streaming status indication
    -n value       Number of Video buffers (b/w 2 and 32)
    -p value       GPIO pin number for streaming status indication
    -r value       Framerate for framebuffer (b/w 1 and 30)
    -u device      UVC Video Output device
    -v device      V4L2 Video Capture device
    -x             show fps information

pmottram avatar Jan 20 '21 12:01 pmottram

A little further digging leads to 'piwebcam' file being the source of the run command for the uvc-gadget, so I think I should be able to configure the options on the line: sudo /home/pi/uvc-gadget/uvc-gadget -u /dev/video1 -v /dev/video0 to sudo /home/pi/uvc-gadget/uvc-gadget -u /dev/video1 -v /dev/video0 -p 23

Now to go find myself a LED to test with....

pmottram avatar Jan 20 '21 12:01 pmottram

OK, so I repaced the uvc-gadet with the one from https://github.com/peterbay/uvc-gadget and then I could use the -p flag to enable the LED on a GPIO pin of my choice. I also added the -b flag so it blinks at me once it has booted up anbd is ready to go :)

Not sure of the differences to the version forked uvc-gadget, but it seems to run fine with my v2.1 camera module.

pmottram avatar Jan 20 '21 22:01 pmottram

Let's leave this issue open, just so if someone wants to dig in a little further and add a PR to document how to do it, or modify the uvc-gadget fork (or help make sure upstreams/downstreams get synced so it works) to make it work out of the box.

geerlingguy avatar Jan 20 '21 23:01 geerlingguy

I eventually stumbled across https://github.com/showmewebcam/showmewebcam/releases which is a super uptimised Pi webcam. Now got it up and running:

led_blink

Posted the case stl here: https://www.thingiverse.com/thing:4731152

pmottram avatar Jan 27 '21 13:01 pmottram

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Apr 30 '21 02:04 stale[bot]

This issue is no longer marked for closure.

stale[bot] avatar Apr 30 '21 16:04 stale[bot]

So I have a pimoroni blinkt (url below) sitting on top of my zero w cam (Thanks BTW! It's been rock solid for months!). What would I look for to assess the status of the camera (i.e being on or off?). I figure i'll just use their python lib to do all the led commands and look somewhere to see the on/off flag to set the leds like every 5 seconds or something. Thoughts?

https://shop.pimoroni.com/products/blinkt

plj5003 avatar Sep 21 '21 19:09 plj5003

Did something similar but worked my way around over the serial port, lol. neopixelRingSerialCom

would be great to be able to use the usb connection.

wytr avatar Nov 14 '21 14:11 wytr

just following up here - is there not a way to run a command to see if it's on or not?

plj5003 avatar Dec 14 '21 17:12 plj5003

Answer #2 shows how to test for a GPIO pin status (on/off-high/low) Is that what you are looking for? https://raspberrypi.stackexchange.com/questions/53778/how-to-detect-state-of-gpio-pin-in-python

starbasessd avatar Dec 14 '21 17:12 starbasessd

sorry to see if the webcam is streaming / recording vs idle

plj5003 avatar Dec 14 '21 17:12 plj5003