cam_photo.py
Picamera2 is the modern Raspberry Pi OS camera API: the script sets a still configuration, starts the sensor and saves a timestamped JPEG. Enable the camera (raspi-config or config.txt camera_auto_detect) before the first run on this model.
Hardware
A Raspberry Pi 5 (quad-core BCM2712 at 2.4 GHz, RP1 I/O chip, 40-pin GPIO, recommended 5 V/5 A USB-C power, two CSI camera ports). One Pi Camera module (v2 IMX219 or HQ), CSI ribbon cable.
Wiring
CSI ribbon into the camera socket (clip up on the 40-pin side), copper contacts facing the pins; see the official docs for the CSI port location.
How it works
Picamera2 talks to libcamera: still configuration, start, asynchronous capture straight to file, then a clean pipeline stop.
Running it
Copy the script to the board (scp), then run it with python3. On Bookworm, gpiozero 2.x drives the pins through the RP1 chip; keep gpiozero and python3-rpi.gpio updated (sudo apt full-upgrade). A 5 V/5 A supply is advised.
Variants
create_video_configuration for clips; capture_request_and_convert to get a NumPy array. A 27 W (5 V/5 A) supply is recommended; without it USB output is capped at 600 mA total.
cam_photo.py
# cam_photo.py — prend une photo avec la camera officielle (Picamera2).
# Deps: sudo apt install python3-picamera2 ; activer camera en raspi-config
# Sous Bookworm : camera_auto_detect=1 dans /boot/firmware/config.txt.
# Le clip du port CSI se releve, on inserre la nappe, contacts cuivres vers la carte.
from picamera2 import Picamera2
from datetime import datetime
picam2 = Picamera2()
cfg = picam2.create_still_configuration()
picam2.configure(cfg)
picam2.start()
picam2.switch_mode_and_capture_file(
cfg, datetime.now().strftime("photo_%Y%m%d_%H%M%S.jpg")
)
picam2.stop()
print("Photo enregistrée")