Skip to content

Instantly share code, notes, and snippets.

@mynameisflorian
Last active October 9, 2023 02:10
Show Gist options
  • Save mynameisflorian/3b1ea0f26d95f27b0deb82d7502a0c58 to your computer and use it in GitHub Desktop.
Save mynameisflorian/3b1ea0f26d95f27b0deb82d7502a0c58 to your computer and use it in GitHub Desktop.
Raspberry Pi Notes
Setting up a SD card for a headless configuration
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
To... In "/boot" place:
⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻ ⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻
Enable SSH --> ssh.txt (empty)
Create User --> userconf.txt (contents: pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0) <-- pi:raspberry
configure wifi --> wpa_supplicant.conf
To generate a userconf.txt file
⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻
Paste this into a bash shell:
(read -p "Username: " username; read -p "Enter password: " password; read -p "Verify password: " password2; [ "$password" = "$password2" ] || { echo "Passwords do not match!"; exit 1; }; printf "%s:%s" "$username" "$(openssl passwd -6 "$password")" > userconf.txt; )
To generate a wpa_supplicant.conf file
⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻
Use the following command on a linux machine (you will be prompted for a password):
wpa_passphrase 'network-ssid' > wpa_suplicant
Running a script on startup without login
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
crontab -e
@reboot <command> &
see: https://www.raspberrypi.org/documentation/linux/usage/cron.md
Overclocking (pi4)
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
In /boot/config.txt
⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻
# uncomment to overclock the arm. 700 MHz is the default.
over_voltage=6
arm_freq=2000
Monitor cpu temp and throttling
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
watch -n 1 vcgencmd measure_clock arm
watch -n 1 vcgencmd measure_temp
watch -n 1 vcgencmd get_throttled
--or--
watch "vcgencmd measure_clock arm; vcgencmd measure_temp; vcgencmd get_throttled"
Prevent Kernel Upgrades
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
sudo apt-mark hold libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0
sudo apt-mark hold raspberrypi-bootloader raspberrypi-kernel raspberrypi-kernel-headers
Create a compressed image from an SD card
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
to create an image:
sudo zstd /dev/mmcblk0 -f -o FILENAME.img.zstd
to restore image:
sudo zstd -df FILENAME.img.zstd -o /dev/mmcblk0
(replace /dev/mmcblk0 with your SD card's device)
note: Use e2image to create sparse disk images
Set status LED pattern
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
echo "<pattern>" | sudo tee /sys/class/leds/led0/trigger
where <pattern> is one of:
actpwr (sold on)
timer (blinking)
heartbeat (heartbeat pattern)
none (off)
a complete list of available patterns is available via:
cat /sys/class/leds/led0/trigger
NOTE: The pi0 uses a act instead of led0
Manipulate PWM output via /sys (from a shell)
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Works for hardware PWM (gpio-18[pwm0], and probably 13[pwm1])
Setup:
# Set these variables to configure PWM
frequency=1000 # is 1000hz
duty_cycle=25 # is 25%
# Do some math and set
period="$((1000000000/$frequency))"
echo "$period" | sudo tee /sys/class/pwm/pwmchip0/pwm0/period > /dev/null
echo "$(($period*$duty_cycle/100))" | sudo tee /sys/class/pwm/pwmchip0/pwm0/duty_cycle > /dev/null
Changing duty cycle:
duty_cycle="30"
period="$(cat /sys/class/pwm/pwmchip0/pwm0/period)"
echo $(($period*$duty_cycle/100)) | sudo tee /sys/class/pwm/pwmchip0/pwm0/duty_cycle > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment