Tested on:RPi 3B; Raspbian Stretch; Python3.5
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
0

Activate and deactivate Linux USB cameras with Python

When working with a Raspberry Pi, power management becomes crucial when a few USB devices are attached. To manage power-hungry USB cameras, it might be necessary to unmount them to save energy.
This tutorial presents a little script that performs this task dynamically via Python and without any need to reboot.

Installation and Test
Enter in the terminal

Now, all USB cameras are unmounted.

Code explained
First we use the module glob to find all usb devices:

If the device information obtained with cat contains the word camera, the device is unmounted with subprocess:

Full script
Click on Full Script to show all of the code.

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

Comment

Time limit is exhausted. Please reload CAPTCHA.