Skip to content

Instantly share code, notes, and snippets.

@xaratustrah
Last active February 24, 2021 11:18
Show Gist options
  • Save xaratustrah/55bf1f16cd2f682541c92a8b9ea3e1ff to your computer and use it in GitHub Desktop.
Save xaratustrah/55bf1f16cd2f682541c92a8b9ea3e1ff to your computer and use it in GitHub Desktop.
raspbian_hints.md

Raspberry Pi OS hints

Installation of Raspberry Pi OS

It is recommended to download the lite version of Raspberry Pi OS, since the full version may be too big and full of unnecessary packages, from here. You can check the shasum before installation to make sure it is the original file.

After downloading, you can use dd to copy the image. The procedure on OSX would be e.g.: Identify the name of the SD Card:

diskutil list

in my case it was /dev/disk2. The unmount it:

diskutil unmountDisk /dev/disk2

then use the dd to copy:

sudo dd bs=1m if=2015-11-21-raspbian-jessie.img of=/dev/rdiskN

Activation of SSH connection for headless operation

Mount the SD card on a different system and go to the boot directory. Then create a file with the name ssh by using:

touch ssh

Finding the IP address

you can use ctrl-t to check the progress. After booting if you have a HDMI monitor / TV and keyboard attached then you can see your IP address of course, but if you like me are only connected to internet without any display then you need to find out the IP address just by connecting to a router. Open router's own web page and find out the IP or MAC address. There are also other methods available under linux.

Finishing up settings

Do not forget to change your password by passwd. After that you should

sudo apt update
sudo apt full-upgrade

then run raspi-config. There you can activate ssh permanently, expand filesystem and enable boot from USB device in case no SD card is available. This works for Raspberry Pi4 but also for older models, whereas the procedure is a bit different.

USB Ethernet Adapter

I have a cheap USB3 ethernet adapter with the AX88179 chipset. Using the latest Raspberry Pi OS, it was easily detected. You can check the driver version in the deamon messages:

dmesg | grep eth

And see if it is registered. You can also check whether you can see it in the usbu device list:

lsusb

and

lsusb -vd <HEXNUMBER>

finally change the file /etc/network/interfaces:

auto lo eth0 eth1
iface lo inet loopback
iface eth0 inet dhcp
iface eth1 inet static
address 192.168.254.1
network 192.168.254.0
netmask 255.255.255.0
broadcast 192.168.254.255

where eth0 is the onboard ethernet interface and eth1 the usb network interface. In /etc/host.conf you write:

multi on

and in /etc/hosts you can add your own host name, e.g.:

127.0.1.1	raspberrypi
192.168.254.254	some.other.device

finally restart the network as sudo:

/etc/init.d/networking restart

Checking the version of your Pi:

this gives you the model:

cat /sys/firmware/devicetree/base/model

Installation of python on Raspi

After the first boot, you need to install a couple of things for the server part. Please note, that you do not need to install PyQt5 or any other GUI elements on the Raspberry PI, as these are only needed for the GUI on the client machine (OSX, Win, Lin, etc...). The default username and password should be pi and raspberry. Change the password soon. First setup your raspberry using raspi-config: expand file system to allow full SD card access, change locale and timezone, change password and finally allow autologin without console to your user. Then remove any previous python:

sudo apt-get purge python*

Install some other packages:

sudo apt install python3-pip python3-dev screen emacs-nox mc tree ncdu gfortran deborphan mpg123 git

Change the default python:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1

Check the alternative:

update-alternatives --config python

Dowbnload the latest pip from pip web site (not using the apt-get):

sudo python get-pip.py

Install other stuff using pip:

sudo pip install jdcal jdate numpy matplotlib prettyplotlib pyzmq beautifulsoup4 Flask jdcal jdate jupyter fortran-magic fortranformat RPi.GPIO

Autostart scripts

Edit your .bashrc and put the auto start script at the beginning, e.g. playing music:

# autostart script                                                                                                                                                   
if [ $(tty) == /dev/tty1 ]; then                                                                                                                                     
    screen -S autologin_session -d -m mpg123 http://144.76.106.52:7000/progressive.mp3                                                                              
fi 

NTP and Cronjobs

in order to make an hourly readjustment of the time you can do as follows:

create a script called ntpupdater in /etc/cron.hourly

#!/bin/bash
LOG="/tmp/ntpupdater.log"
# update with ntp server
echo >> $LOG
echo "-------------------------" >> $LOG
echo "Date before sync:" >> $LOG
date >> $LOG
/usr/sbin/service ntp stop
/usr/sbin/ntpd -gq >> $LOG
/usr/sbin/service ntp start

change execution permission:

chmod +x /etc/cron.hourly/ntpupdater

run it once for testing and check the results.

You can also change the /etc/ntp.conf and change the preffered NTP servers.

Connection to the box

From then on you can connect using SSH and screen:

ssh -t pi@IP_ADDRESS screen -D -R

if you have more screens and want to find out which screens are available for connections, use the above command with the -ls parameter:

ssh -t pi@IP_ADDRESS screen -ls

Installation of CUPS

sudo apt install cups
sudo usermod -a -G lpadmin pi
sudo apt install samba

change the host name

change the name of the raspberry pi in the network in the following files:

/etc/hostname
/etc/hosts

Bluetooth sound

First install the bluetooth:

sudo apt install pi-bluetooth
sudo systemctl restart bluetooth
sudo apt install pulseaudio-module-bluetooth

You can check:

pactl list sinks short
pactl set-default-sink 1
pactl set-sink-volume 1 60%

Increase sound volume

amixer set PCM -- 100%

Mount USB flash drive

Mounting USB. More info here.

ls -l /dev/disk/by-uuid/
sudo mkdir /media/usb
sudo chown -R pi:pi /media/usb
sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi
umount /media/usb

Change the network interface name

new network interface names: Open the file cmdline.txt, which can be found in the boot directory of the SD Card. Add the following to the line after rootwait quiet:

net.ifnames=0

Automatic WIFI connection

Create a hash of your password:

wpa_passphrase <your_wifi_ssid_here> <your_wifi_password_here>

Add the resulting lines:

network={
        ssid="mywifi"
        #psk="mypasswd"
        psk=175c63e5acd5b9bb66cfe2f89857db9060f2edf3989c89c19e5a54e5044cd2a4
}

to the end of the file /etc/wpa_supplicant/wpa_supplicant.conf. In a headless configuration, you have to mount the SD card on a different linux machine and put the password there. This gets a bit messy under Win or OSX.

Local

Setting the set local to enUS usually keeps some warnings away. At least for me it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment