Raspberry Pi

Unless otherwise stated, these notes relate to running Debian 8 (Jessie) on the Raspberry Pi.

Installing Raspbian to SD card

On macOS:

$ diskutil list

/dev/disk4 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.9 GB     disk4
   1:             Windows_FAT_32 ⁨boot⁩                    58.7 MB    disk4s1
   2:                      Linux ⁨⁩                        7.8 GB     disk4s2

In this case, the old Raspian boot volume is mounted, so unmount:

$ diskutil unmount /dev/disk4s1

Copy the image to the SD card using dd. The rdisk4 is a raw disk mode for disk4 and results in faster transfers:

$ sudo dd if=./2022-01-28-raspios-bullseye-armhf-lite.img of=/dev/rdisk4 bs=1m

See

-- Frank Dean - 24 Sep 2022

Headless Setup

An hard-wired ethernet connection is required to initially run the Rasperry Pi headless from first boot.

Enable SSH by mounting the SD card on computer and create a blank file on the boot partition named ssh:

$ touch /Volumes/boot/ssh

Boot the device using the SD card.

Use your network adminstration tool to determine what IP address was assigned to the device.

You should then be able to login using the default username and password pi/rasberrry. E.g.

$ ssh pi@192.168.1.1

You should then immediately change the password for the default user.

$ passwd

You can then run the raspi-config utility to make any preferred configuration changes. E.g. setting up Wi-Fi.

-- Frank Dean - 24 Sep 2022

Installing Wi-Fi

This sub-section relates to runnning Debian 10 (Buster).

You should be able to enable Wi-Fi just by configuring WPA Supplicant. No entries are needed in /etc/networking/interfaces.

The Wireless CLI Instructions can fundamentally be reduced to the following.

There should already by a wpa_supplicant configuration file:

$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

Replace $SSID with the SSID of the target Wi-Fi network.

$ sudo -v
$ wpa_passphrase $SSID | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf

wpa_passphrase will wait on a new line for password input. Type the password for the SSID followed by the Return or Enter key.

You may need to add your country code to the file for more recent Raspberry Pi models for 5GHz networking. Edit the file as follows using your favourite editor and replace $COUNTRY_CODE with the appropriate 2 letter ISO 3166-1 code.

$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=$COUNTRY_CODE

network={
        ssid="$SSID"
        #psk="$PASSWORD_CLEAR_TEXT"
        psk=$ENCODED_PASSWORD
}

$ export EDITOR=/usr/bin/vi
$ sudoedit /etc/wpa_supplicant/wpa_supplicant.conf

The first line of the configuration file configures wpa_supplicant to create a Unix socket under /var/run/wpa_supplicant and allow users belonging to the netdev group to run wpa_cli without being root. The default pi user belongs to that group as shown with the id command.

If you get an error as follows, it is probably because the socket isn't present, perhaps due to wpa_supplicant being run without being configured to create the Unix socket.

$ /usr/sbin/wpa_cli -i wlan0 reconfigure
Failed to connect to non-global ctrl_ifname: wlan0  error: No such file or directory

After ensuring the configuration file is correct, restart the network with:

$ sudo systemctl restart dhcpcd
$ ls -l /var/run/wpa_supplicant/
total 0
srwxrwx--- 1 root netdev 0 Mar  4 23:04 wlan0

Optionally, restart wpa_supplicant, but restarting dhcpcd should suffice:

$ sudo systemctl restart wpa_supplicant

The wpa_cli command to re-read the configuration file should now work:

$ wpa_cli -i wlan0 reconfigure
OK

-- Frank Dean - 3 Apr 2021

Listing Available SSIDs

$ sudo iwlist wlan0 scan | grep ESSID

-- Frank Dean - 19 Aug 2023

Controlling LEDs

The red LED can be turned on and off with the following commands:

    # echo 1 >/sys/class/leds/led1/brightness
    # echo 0 >/sys/class/leds/led1/brightness

Any value bigger than zero turns it on, zero turns it off.

After turning off the green LED (led0), it is necessary to re-enable the trigger for when the SD card is accessed.

    # cat /sys/class/leds/led0/trigger
    # echo 0 >/sys/class/leds/led0/brightness
    # cat /sys/class/leds/led0/trigger
    # echo 1 >/sys/class/leds/led0/brightness
    # cat /sys/class/leds/led0/trigger
    # echo mmc0 >/sys/class/leds/led0/trigger
    # cat /sys/class/leds/led0/trigger

Linux Kernel

apt-cache show linux-image-rpi-rpfv states:

    Description: This metapackage will pull in the raspbian kernel for the raspberry pi 1
     based on the version currently reccomended by the raspberry pi foundation
     (currently 3.18).

apt-cache show raspberrypi-bootloader states:

    Description: Raspberry Pi bootloader
     This package contains the Raspberry Pi bootloader (plus, temporarily, a
     kernel).

and

    $ dpkg --search /boot/kernel.img
    raspberrypi-bootloader: /boot/kernel.img
    $ dpkg --search /boot/kernel7.img
    raspberrypi-bootloader: /boot/kernel7.img

This page suggests the kernel is updated as one of the Debian packages, which conflicts with the page suggesting use of rpi-update

Understanding kernels on the Raspberry Pi and Raspi-LTSP explains there are two sources of kernels for the Raspberry Pi. 'foundation kernels' and 'team kernels'. My guess is that rpi-update provides foundation kernels, and the linux-image-rpi-rpfv package provides the team kernels, even though the package description for linux-image-rpi-rpfv says "reccomended[sic] by the raspberry pi foundation".

At the time of writing, the Raspbian Downloads page states that Raspian Jessie is kernel version 4.1.

apt-cache show linux-image-rpi-rpfv depends on linux-image-3.18.0-trunk-rpi.

apt-cache show linux-image-3.18.0-trunk-rpi gives its version as 3.18.5-1~exp1+rpi19 and booting into that image uname -r gives 3.18.0-trunk-rpi

Booting kernel.img uname -r gives 4.1.17+.

So I guess rpi-update gets you the latest and greatest and the linux-image-rpi-rpfv package gets you an older, but presumably stable kernel and the foundation expect most people to use rpi-update, but ultimately it will depend on what hardware support you need from the kernel.

Note also that rpi-update doesn't clean up the modules after itself. You will need to manually delete (with care) the kernel modules installed under /lib/modules/.

See also:

Kernel Configuration

If you do not want to use the default kernel.img or kernel7.img, you need to add some entries to config.txt, e.g.:

kernel=vmlinuz-3.18.0-trunk-rpi
initramsfs initrd.img-3.18.0-trunk-rpi followkernel

Installing Java

$ sudo apt-get install oracle-java8-jdk

Installing Eclipse

$ sudo apt-get install eclipse eclipse-jdt

for C/C++

$ sudo apt-get install eclipse-cdt

Upgrading Debian 7 (Wheezy) to Debian 8 (Jessie)

https://linuxconfig.org/raspbian-gnu-linux-upgrade-from-wheezy-to-raspbian-jessie-8

Live Streaming Camera on Local Network

Enable the camera using the raspi-config utility.

Note that there is no security in this method. Anyone who can access the same network can view or capture the stream.

  1. Install VLC on Raspberry Pi.

    $ sudo apt-get install vlc
    
  2. Create stream:

    $ raspivid -o - -t 0 -w 800 -h 600 -fps 12  | \
    cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
    
  3. Open VLC on another device.

  4. Choose File > Open Network... from VLC menu

  5. Enter the URL as rtsp://IP_ADDRESS_OF_PI:8554/

  6. Click Open

  7. The Video should play. Sometimes it fails to connect and it is worth another try or so.

See https://raspberry-projects.com/pi/pi-hardware/raspberry-pi-camera/streaming-video-using-vlc-player

References

Useful Scripts

Take a still shot:

#!/bin/bash
$ raspistill --nopreview --rotation 180 -o ~/photos/img-$(date +"%F-%H%M").jpg

Take a short video clip:

#!/bin/bash
set -e
FILENAME=~/photos/video-$(date +"%F-%H%M")
raspivid -w 800 -h 600 -fps 12 --timeout 10000 -o $FILENAME.h264
MP4Box -add $FILENAME.h264 $FILENAME.mp4
rm $FILENAME.h264

MP4Box used in the above script belongs to the gpac Debian/Raspian package.

See raspicam for all options common to the camera utilities. Other options to consider for video streaming:

-vf         Flip image vertically
-hf         Flip image horizontally
-ex night   Exposure mode

-- Frank Dean - 26 Sep 2022

CPU Temperature

$ vcgencmd measure_temp

-- Frank Dean - 10 Jun 2023


-- Frank Dean - 2 Mar 2015

Related Topics: DebianTips, LinuxDevelopment