Table of Contents

Raspberry Pi

Default login

At first boot on a fresh flash it is good practice to immediately run updates and configure a few options using raspi-config before proceeding to any more tuning.

SSH

$ sudo raspi-config

Go to Interface Options then SSH and activate it. No reboot is required.

It is good practice to have your router assign a static IP address to a RPi if you want to regularly connect to it via ssh

Camera

External wiki information on different cameras

Activating the camera

$ sudo raspi-config

Go to Interface Options then Camera and activate it. Raspi-config will propose a reboot which should be accepted.

Python script to take pictures

Navigate to a folder where you want the script to be located.

$ touch camera.py

Edit this file and copy the following :

#!/usr/bin/env python
 
from picamera import PiCamera
from time import sleep
 
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/picture.jpg')
camera.stop_preview()

Warning, this will save to user pi's desktop, remember to change username if you aren't using user pi

Run the script :

$ python camera.py

You can view the picture by either copying it to another machine with scp or by using a screen and mouse/keyboard on the pi itself.

Creating a Timelapse with Camera

You can use the built-in raspistill tool or make up your own in your choice of code language.

Example with raspistill :

$ raspistill -w 1920 -h 1080 - t 10000 -tl 1000 -o image%04d.jpg

This will take FullHD shots at 1 second interval for 10 seconds, naming them with 4-digit incremental numbers.

If no -w and -h options are provided, the Raspberry Pi will default to taking full sized pictures : 4056 x 3040 which will weigh approx. ~6 MB each. Also note that a Pi 4 will not be able to take these effeciently at an interval ~< 2s.

raspistill has a lot of options and effects that can be activated/parametered, have a look at raspistill –help or man raspistill

Official Documentation

Scripts @ startup

Modify the /etc/rc.local file (requires sudo)

$ sudo nano /etc/rc.local

Before the 'exit 0' line at the end insert lines like this one :

bash /path/to/script.sh

Temperature checks

CPU temp

$ cat /sys/class/thermal/thermal_zone0/temp

Divide by 1000 to get °C format

GPU temp

$ vcgencmd measure_temp
$ /opt/vc/bin/vcgencmd measure_temp (Full Path)

These measures were done on a Rapsberry Pi 4 running Raspbian with no heavy-duty program running, no screen or USB devices attached and at a room temperature around 20°C

GPIO

GPIO Header

Using GPIO through bash

# Exports pin to userspace
$ echo "18" > /sys/class/gpio/export                  
 
# Sets pin 18 as an output
$ echo "out" > /sys/class/gpio/gpio18/direction
 
# Sets pin 18 to high
$ echo "1" > /sys/class/gpio/gpio18/value
 
# Sets pin 18 to low
$ echo "0" > /sys/class/gpio/gpio18/value 
 
# Exports pin to userspace
$ echo "4" > /sys/class/gpio/export
 
# Sets pin 4 as an input
echo "in" > /sys/class/gpio/gpio4/direction
 
# Read value of pin 4
cat /sys/class/gpio/gpio4/value