Some tips and tricks about Raspberry Pi that I always search! Or things that took me too much time to find when I needed to go fast................
On the latest Raspbian releases, I have been unpleasantly surprised by the fact that SSH is disable by default as well as... serial console... So without screen, we can't do anything...
To enable serial console (to be able to enable SSH later), SD card boot partition must be mounted on a computer. Then you need to add enable_uart=1 at the end of /boot/config.txt file:
echo "enable_uart=1" >> /media/$USER/boot/config.txt
Copy/paste of an old fstab config, in the mean time fstab syntax has changed and BOOOOOOMMM! Raspberry can't mount correctly its SD card anymore... In short, big hard time. I have found a smart solution to automatically mount any USB hard drive when stating the Raspberry. Or simply, when it is plugged in during Raspberry operation.
We will start by installing pmount:
sudo apt update && sudo apt install pmount
Then create a script /usr/local/bin/cpmount that will mount disks in /media/usb1, /media/usb2, /media/usb3 and /media/usb4 folders depending of the plugging order:
#!/bin/bash
maxMountPoints="4"
folderNum="1"
while [ "$folderNum" -le "$maxMountPoints" ]
do
if mountpoint -q /media/usb$folderNum
then
((folderNum++))
else
/usr/bin/pmount --umask 000 --noatime -w --sync $1 usb$folderNum
break
fi
done
Don't forget to make this script executable:
sudo chmod +x /usr/local/bin/cpmount
Then create a service /lib/systemd/system/usbstick-handler@.service that will use this script:
[Unit]
Description=Mount USB sticks
BindsTo=dev-%i.device
After=dev-%i.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/cpmount /dev/%I
ExecStop=/usr/bin/pumount /dev/%I
Finally, create a Udev rule /etc/udev/rules.d/usbstick.rules that will launch the service when a USB disk is detected:
echo 'ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"' | sudo tee /etc/udev/rules.d/usbstick.rules
This script will install Adafruit touchscreen PiTFT 3.5" on Raspbian. No need to use the patched image. The problem with this image is that we can't make updates without screwing up the patch.
cd ~
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh
Source: https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi/easy-install-2
This screen remains frozen after Raspberry shutdown.
Create a script /usr/local/bin/screen-off.sh allowing screen power OFF:
#!/usr/bin/env bash
sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
Don't forget to make it executable:
sudo chmod +x /usr/local/bin/screen-off.sh
Then create a service /etc/systemd/system/screen-off.service that will call the script during the shutdown:
[Unit]
Description=TFT Screen Off
Conflicts=reboot.target
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/local/bin/screen-off.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Finally, enable the service:
sudo systemctl enable screen-off
Source: https://willhaley.com/blog/power-off-raspberry-pi-adafruit-tft-screen-shutdown/
The aim is to disable screen saver when raspberry is used in serial mode (so not in desktop mode). After 60s, screen stops functioning. Or strangely, PiTFT display is erased but backlight stays ON (?!?!?).
To disable screen blanking, add consoleblank=0 in /boot/cmdlibe.txt:
sudo sed -i ' 1 s/.*/& consoleblank=0/' /boot/cmdline.txt
Source: https://www.raspberrypi.org/documentation/configuration/screensaver.md