cam_photo.py

Raspberry Pi Model B+ (2014) — Board Sheet · File : cam_photo.py · Language : Python · Use case : Prendre une photo avec le module caméra officiel et Picamera2

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 Model B+ (BCM2835, 40-pin GPIO header, micro-USB power, 3.5 mm 4-pole audio jack). 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). Install gpiozero with sudo apt install python3-gpiozero if missing. The 40-pin pinout is in the official schematic and on the Raspberry Pi website.

Variants

create_video_configuration for clips; capture_request_and_convert to get a NumPy array. No built-in Wi-Fi: use Ethernet or a USB dongle; 5 V/1.2 A micro-USB supply.

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")

← Back to the board