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 3 Model A+ (compact format, BCM2837B0, 5 GHz Wi-Fi + Bluetooth, a single USB port, 5 V/700 mA power, 40-pin GPIO). 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 (or bash). Raspberry Pi OS ships gpiozero; otherwise sudo apt install python3-gpiozero. Mind the 700 mA power budget for USB peripherals.
Variants
create_video_configuration for clips; capture_request_and_convert to get a NumPy array. Compact board to cool; USB-C 5 V/2.5 A; a single USB port, add a hub if needed.
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")