Image selection
I use the Raspberry Pi OS Lite (64bit) from the Pi Imager. It can be found under Choose OS -> Raspberry Pi OS (Other)
I recommend configuring your wireless network and SSH in the imager to avoid having to plug in screens or keyboards
Upgrading the OS
This is probably resolved, however I had some hardware issues with the latest images so I used the legacy image and then manually upgraded the OS
On a Pi4 I also had to change the wpa_supplicant service
sudo vim /lib/systemd/system/wpa_supplicant.service
ExecStart=/sbin/wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf -u -s
sudo systemctl daemon-reload
sudo systemctl restart wpa_supplicant.service
Then needed to install: sudo apt install dhcpcd5
sudo systemctl enable dhcpcd
sudo systemctl start dhcpcd
sudo vim /etc/avahi/avahi-daemon.conf
allow-interfaces=eth0,wlan0
Resize the primary partition
sudo apt install cloud-guest-utils
# lsblk or fdisk -l to identify partitions.
growpart /dev/mmcblk1 2
resize2fs /dev/mmcblk1p2
df -h
Install dependencies
sudo su
apt update
apt upgrade && apt dist-upgrade
# a decent editor
apt install vim
# IO pin control
apt install gpiod libgpiod-dev
# network utils
apt install dnsutils
# pijuice_cli tool
apt install pijuice-base
- To install docker-compose the apt repository needs to be added
- Then follow the post install instructions to have docker available for your user.
Configure environment
I like vim so I set it up to work without mouse support:
echo "set mouse-=a" >> ~/.vimrc
sudo su
echo "set mouse-=a" >> ~/.vimrc
then I ensure it’s my default editor
- run
select-editor - select vim-basic
add any additional wireless networks
vim /etc/wpa_supplicant/wpa_supplicant.conf
# network={
# ssid="deploy-network"
# psk="password"
# }
limit logging to not use all the disk space
sudo vi /etc/systemd/journald.conf
SystemMaxUse=500M
SystemMaxFileSize=100M
SystemKeepFree=500M
sudo systemctl restart systemd-journald
Reduce power consumption
Disable CPU cores
Run on a single CPU core as this can half the power consumption of the device
- Edit
/boot/cmdline.txtfile and addmaxcpus=1afterconsole=tty1 - Run:
lscputo confirm
Disable the power LED
Add to /boot/config.txt for the PI Zero W
# Disable the ACT LED on the Pi Zero.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=on
For other PIs see: https://www.jeffgeerling.com/blogs/jeff-geerling/controlling-pwr-act-leds-raspberry-pi
Disable HDMI
Use: sudo raspi-config, select Display and blank display
Configure access to GPIO
This will allow your user and the door control service to interact with the GPIO chips on the Pi.
git clone https://github.com/stakach/ladies-first-chicken-door
cd ladies-first-chicken-door
./scripts/setup_gpio.sh
This script does the following:
- creates a gpio-users users group
- adds the current user to the group
- adds a udev rule allowing read and write access
This ensures secure access to the hardware
Configure PiJuice
The PiJuice Power Management HAT requires a schedule to be in place for it to start the Pi if it’s goes offline. This means we really need to ensure the schedule is set and the example scripts can be used to ensure this is done (see the scripts for more details).
Using the pijuice_cli configure the following:
- configure the battery type that is installed
- configure the full path to
pi_juice_poweroff.pyscript asUSER FUNC1 - configure System Events so that Low Charge executes USER FUNC1
- I also disable the physical buttons