Skip to content

Instantly share code, notes, and snippets.

@blakeNaccarato
Last active January 12, 2024 04:37
Show Gist options
  • Save blakeNaccarato/875bdc93aede21a51ad9d9b36f849a62 to your computer and use it in GitHub Desktop.
Save blakeNaccarato/875bdc93aede21a51ad9d9b36f849a62 to your computer and use it in GitHub Desktop.
Set up Raspberry Pi

Set up Raspberry Pi

Set up SSH with VSCode

Connect to WiFi. In bash, run sudo apt update, then sudo apt full-upgrade. Next, run mousepad /etc/dhcpcd.conf or similar to view the networking configuration file. Find the lines that look similar to below, uncomment them, and input proper addresses. Use eth0 to set a static IP for wired connection, and wlan0 for wireless.

# Example static IP configuration:
interface wlan0
static ip_address=192.168.X.XX/24
static ip6_address=XXXX:XXXX:XXXX:XXXX::ff/64
static routers=192.168.X.1
static domain_name_servers=192.168.X.1 8.8.8.8 XXXX:XXXX:XXXX:XXXX::1

Then add the SSH location to VSCode. If you have accessed multiple Raspberry Pis from the same IP address, SSH will fail unless you clear the entry in %USERPROFILE%\.ssh\known_hosts corresponding to the IP address you wish to access a newly set up device from. You can have multiple entries for the same IP address, with different recognized devices, but VSCode won't ever automatically add a second device on an IP address that it has already seen another device on.

Build Python 3.8 from source and install it

From this source, we can do the following instead:

sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim
wget https://www.python.org/ftp/python/3.<X>.<Y>/Python-3.<X>.<Y>.tgz
sudo tar zxf Python-3.<X>.<Y>.tgz
cd Python-3.<X>.<Y>
sudo ./configure --enable-optimizations
sudo make -j 4
sudo make altinstall

Keyboard shortcuts

/etc/xdg/openbox/lxde-pi-rc.xml

Start menu application clutter

Strangely, applications are only considered "installed" if they are visible in the start menu via the "Main Menu Editor". The right-click context menu and other parts of the OS that list your "Applications" will only list those that are visible in the start menu. This means that you have to clutter your start menu with tools that are mostly executed with a file target, but are uselessly called bare from the start menu. I haven't found a way around this.

Restoring a messed up panel

The "panel" is the taskbar/start menu. For example, the Start menu is a menu widget in the panel given the address start-here. But creating it manually makes an ugly menu that's not configured like the default one. If you delete the start menu, or mess up the panel in some other way, follow the guide found here. For a Raspberry Pi 4 Model B running Raspbian Buster, do the following:

sudo cp /etc/xdg/lxpanel/LXDE-pi/panels/panel /home/pi/.config/lxpanel/LXDE-pi/panels/panel
sudo reboot

Built-in fan control not working

The "Performance" tab of the "Raspberry Pi Configuration" application has a "Fan" option that seems to be temperature-sensitive. This does not work, however. I verified this by manually powering the same GPIO pin indicated by the menu. The fan turns on only when it is manually powered. There is a little whine when the temperature threshold is reached, so I think there must be some messed up logic in the built-in fan control.

Backlight

/sys/class/backlight/rpi_backlight

Remote wake

Short GPIO3 to ground to wake. WAKE_ON_GPIO https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

Could use a TinyPICO to remotely pull the pin low. https://www.tinypico.com/

Or Femto’s ESP32 ModUle (FEMU) https://www.crowdsupply.com/femto/femu

Desktop Shortcuts

Global (all user) menu items are defined in /usr/share/applications. These *.desktop files are INI-like files that specify the name of the option in the Start Menu, what command it performs, its icon, etc. Pay attention to the "categories" of built-in icons to map to the Start Menu category entries (their names differ). Per user menu items are defined in ~/.local/share/applications.

[Desktop Entry]
Type=Application
Name=Kivy Test
Icon=/home/pi/.kivy/icon/kivy-icon-128.png
Exec=bash
Exec=/home/pi/kivy-test/.venv/bin/python /home/pi/kivy-test/main.py
Categories=Utility;

Startup and shutdown with GPIO3

https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

wake_on_gpio is set by default.

Add dtoverlay=gpio-shutdown to /boot/config.txt.

Unsorted

There are many boards that implement the ESP8266 microcontroller. Standouts are the NodeMCU DEVKIT, Adafruit's Feather HUZZAH ESP8266 breakout, and the ACROBOTIC ESP8266 ESP-12E. All of these have a 2x15 DIP/DIL form factor (dual in-line, dual in-line package). These boards seem to implement the ESP-12E modules. The Adafruit HUZZAH 8266 breakout (not the Feather) is a slightly different implementation, that of the "ESP-12F" module instead.

NodeMCU has an open-source board specification, and thus has many clones. Their documentation, like this or this is thorough, but overwhelming. It details hardware and software. The ACROBOTIC board mentioned earlier has an informative and good-looking pinout. It looks so good, in fact, that this particular pinout image appears on most other no-name Amazon clones.

The successor to the ESP8266 implementations discussed above is the https://en.wikipedia.org/wiki/ESP32. Maybe I should seek out a board under this umbrella for better future-proofing and more active development.

Whatever I choose, I will probably use MicroPython documentation to accomplish my goal of remote power-on of the Raspberry Pi.

Back up Raspberry Pi

Install gparted. Plug in two flash drives. Format Flash Drive #2 as FAT32. Use the SD card copier to copy the SD card to Flash Drive #1. Shrink the rootfs partition with gparted. Use Info in gparted to find the last sector of the rootfs partition now that it has been shrunk. Then, use dd as follows:

dd if=/dev/sda of=<MOUNT POINT>/pi.img bs=<BS> count=<COUNT>

where sda is Flash Drive #1, <MOUNT POINT> is the mount point of Flash Drive #2, <BS> is probably 512 or 1M (check with fdisk -l -u=sectors /dev/sdc), and <COUNT> is whatever the last sector of rootfs is plus one. The final pi.img file can be saved in the cloud or flashed onto an SD card using the Raspberry Pi Imager on Windows.

The OS that is recovered by flashing the image will be just as you left it. You should be able to sudo raspi-config --expand-rootfs to expand the root filesystem to fill the whole SD card.

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