silvanmelchior / RPi_Cam_Web_Interface

A web interface for the RPi Cam
MIT License
1.54k stars 493 forks source link

Adding an LED to a gpio pin and controlling in RPI CWI #616

Open Woody565 opened 3 years ago

Woody565 commented 3 years ago

Hi all,

I have RPi_Cam_Web_Interface running on a Pi4 as a birdbox cam.

As its always dark in the box I wanted to add 2 - 3 white LEDs to improve the quality.

Can I add them to a GPIO pin with the relevant resistors and turn them on and off in the web interface?

If so, could someone offer some advice please?

Cheers

Dan

roberttidey commented 3 years ago

Several points here.

1) You need to consider how much current you need to drive the LEDs for the level of illumination you need. The current from one GPIO is limited to around 16mA and a total of 50mA across all GPIOs. That may be enough but if you need more then you will need to add a driver like a transistor or mosfet and then use the +5V as the source of current.

2) You can easily control the LEDs using either a bash script or a python program. I would tend to use a bash script to keep it a simple as possible. Note that gpio operations normally need the user to belong to the gpio group so that it has the correct permissions. When a script is run via the web page then the user is www-data so the easiest way is to add that user to the gpio group. ( sudo adduser www-data gpio )

3) You can add buttons to the web interface and use those to run macro commands like a bash script to control the leds. See the user buttons in the wiki additions and tricks. Note that as well as the gpio group mentioned above, the script you use must be owned by www-data and have execute permissions. This is also described in the wiki under job macros.