This gist contains a very minimal Python script that shows how to set the analogue and digital gains of the Raspberry Pi camera module from within Python. It is a trivial thing, all the actual work was done by the developers of userland in particular 6by9, and of course the developers of picamera. It does require the latest version of the userland libraries in order to be able to send the gain-setting commands. These are not yet (as of January 2018) in the main Raspbian distribution, but it is not scary to build this yourself:
sudo apt-get install cmake
git clone https://github.com/raspberrypi/userland.git
cd userland
./buildme
sudo shutdown -r now
After you've got the latest version of the userland libraries, you should be able to run
python set_gain.py
This will open a preview window and then freeze the analogue and digital gains at 1. Look at the code to see how it's done - it is not complicated. To use this in your own code, just do:
import picamera
from set_picamera_gain import set_analog_gain, set_digital_gain
with picamera.PiCamera() as cam:
set_analog_gain(cam, 2)
set_digital_gain(cam, 1)
Hopefully I will get round to making a pull request to picamera - but of course that's only really useful once the userland code is updated in the distribution.
Hi,
I don't really have much programming knowledge. I'm trying to understand everything that's written here but I'm struggling. All I want is full manual control over my camera. Apparently, the manual control of analog and digital gain is not yet possible in the picamera that comes with the Raspberry OS. (As of 2020-11)
I found your solution. Will this still work, is this still needed? Is there an easier way to solve this, or is that already in an available "beta" version of picamera I'm not aware of? I don't really get the userland concept, and I have a feeling that the answer is lying there. So please forgive me if I overlooked something.
And thank you very much in advance!