Skip to content

Raspberry Pi cheatsheet

Basic usage

Configure Raspberry Pi

sudo raspi-config

Raspberry Pi system information

raspinfo

Disable led

echo 0 | sudo tee /sys/class/leds/ACT/brightness

Taking Photos with Pi camera

Take a photo

rpicam-still -n -o ~/Pictures/photo.jpg

Flip the photo horizontally and vertically

rpicam-still -n -o ~/Pictures/photo.jpg --vflip 1 --hflip 1

List available cameras:

rpicam-still --list-cameras

Timelapse with Pi camera

Take a photo every 5 seconds for 1 minute

rpicam-still -o image%04d.jpg --timeout 60000 --timelapse 5000

Timelapse with crontab

Create timelapse-cron.sh file in ~/bin/ directory:

#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")
rpicam-still -o ~/Pictures/timelapse/$DATE.jpg -n

Edit the crontab: crontab -e, and add our script:

* * * * * ~/bin/timelapse-cron.sh 2>&1

The script will execute every minute.

To take a picture more often use --timelapse option in the bash script, for example take a picture every 10 seconds

#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")
rpicam-still -n -o ~/Pictures/timelapse/${DATE}_%04d.jpg --timeout 50000 --timelapse 10000

Video with Pi camera

Create a 30 seconds video

rpicam-vid -t 30s -o test.h264

Enable watchdog

Enable hardware watchdog

sudo echo 'dtparam=watchdog=on' >> /boot/config.txt

reboot

reboot

Install watchdog service

sudo apt-get update
sudo apt-get install watchdog

Configure watchdog service - set timeout to 15 seconds, monitor wlan0 interface

sudo -i
echo 'watchdog-device = /dev/watchdog' >> /etc/watchdog.conf
echo 'watchdog-timeout = 15' >> /etc/watchdog.conf
echo 'max-load-1 = 24' >> /etc/watchdog.conf
echo 'interface = wlan0' >> /etc/watchdog.conf

Enable the service

systemctl enable watchdog
systemctl start watchdog
systemctl status watchdog

References