Skip to content

Instantly share code, notes, and snippets.

@0x7d7b
0x7d7b / RPI_SWAP.md
Last active November 28, 2021 10:18
Raspberry Pi Swap File

This is a small howto about changing the swap file size on a Raspberry Pi which runs with a raspbian operating system.

Configuration

The swap file size is configured in the /etc/dphys-swapfile file. By default its size is 100 MB. To change that set the CONF_SWAPSIZE value to something else. Here I chanted it to 500 MB:

CONF_SWAPSIZE=500

Reload

Now the dphys-swapfile.service service needs to be reloaded:

@0x7d7b
0x7d7b / RPI_USB.md
Last active November 28, 2021 10:16
Raspberry Pi Boot from USB

For my recend DIY project I had to configure my Raspberry Pi (3 Model B+) to boot from a USB stick. Here are the configuration instructions.

Configuration

Open the /boot/config.txt file in a text editor. This is the file on the currently used SD card. Add the following two lines:

program_usb_boot_mode=1
program_usb_boot_timeout=1

This enables boot via USB and extends the timeout to wait a little longer for the USB device.

@0x7d7b
0x7d7b / RPI_FAN.md
Last active April 23, 2024 01:26
Raspberry Pi PWM Fan Controller

After mounting the GPIO hammer headers to my RPi Zero I am now ready to do some prototyping. The first thing I wanted to test is controlling a 4 pin PWM fan. So here is a short howto on that.

Prerequisites

Besides a RPi Zero with pin headers you need a 4 pin PWM (Pulse With Modulation) fan. I took a Noctua NF-F12 5V fan. Be aware that when you take a 12V fan it will damage your board!

To easily access the RPi Zero during setup I use an USB to serial adapter cable as described in on of my other posts.

Installation

Prepare the SD card as usually. Usually before mounting an RPi Zero I put it into my Raspberry Pi 3 B+. Since that one has an ethernet connection I can update the system and install required libraries:

@0x7d7b
0x7d7b / RPI_TEMP.md
Last active May 27, 2024 16:21
Raspberry Pi Temperature Sensor

This short article describes how to connect and use a DHT22 temperature and humidity sensor on a Raspberry Pi.

Prerequisites

I bought a sensor kit from AZ-Delivery. It is easy connect as no soldering work is required. In case you need more details they offer a free DHT22 ebook download.

Note that in their ebook they recommend to use the Adafruit_DHT library. Since that one is deprecated you need to use the CircuitPython-DHT library instead. Details below.

DHT22

Wiring

@0x7d7b
0x7d7b / RPI_SERIAL.md
Last active November 28, 2021 09:47
Raspberry Pi Serial Connection Setup

Sometimes it is necessary to access a Raspberry Pi via a serial connection. Especially on a Raspberry Pi Zero which has no ethernet port. This short article explains how to enable a serial connection and how to use it.

Prerequisites

First you need a connection cable. I use a USB to serial cable with a PL-2303 chip (Amazon link).

PL-2303 cable

Driver

If you plan to connect to your Pi from a Mac you probably need to install a driver, first. The guys at mac-usb-serial.com offer a very good PL-2303 driver for a small price. Download and install it. They also offer a Serial Detect tool which you can use to first test whether your USB serial adapter has been found by the system.

@0x7d7b
0x7d7b / RPI_OTG.md
Last active September 19, 2022 22:03
Raspberry Pi Zero - Bridge Network Setup

The goal of this article is to explain how to install one or many Raspberry Pi 3 B+ devices connected with one to four Raspberry Pi Zero 1.3 devices each via USB OTG networking.

Preview

Each device - Pi and Zero - will be connected to the network 192.168.0.0/24. Each Zero will be connected via USB OTG to the Pi. That will establish a network between the two devices. On each Pi a network bridge will be configured to forward the traffic between the Pi ethernet port and the connected USB ports.

Their individual hostname/IP pattern will be:

10.lab | 192.168.0.10 (1st Pi)
20.lab | 192.168.0.20 (2nd Pi)
@0x7d7b
0x7d7b / GPG.md
Last active November 17, 2021 20:48
GnuPG + SSH + YubiKey

GnuPG + SSH Authentication using a YubiKey or Smartcard

This is about how I setup and use GnuPG for signing and encrypting data as well as for authenticating SSH sessions. I use both, a YubiKey (4 and 5 NFC) and a GnuPG smartcard from ZeitControl to have a backup in my wallet. As a smartcard reader I use the uTrust 2700 R which works quite well.
My typical use cases are SSH authentication, secure file exchange via public places and signing Git commits. I rarely use GnuPG for email communication. And I neither sign other GnuPG user IDs nor participate in the WOT.
Since there is no difference between setting up a YubiKey or a smartcard the following description mentions the GnuPG smartcard only.

Preparation

**The following steps should be done on an