Skip to main content

Setting up a Raspberry Pi without a monitor

· 2 min read

This guide explains how to set up a Raspberry Pi without needing a monitor.

  • Requires a Raspberry Pi device that can connect an Ethernet cable for a wired connection.
  • A computer is needed to operate the Raspberry Pi.

Install Raspberry Pi Imager, select the OS. Choose the micro SD card to write to, and click WRITE.

Raspberry Pi Imager

Configuration

Enable SSH

Enabling SSH allows you to operate the Raspberry Pi remotely.

Reinsert the micro SD card and create a text file named ssh directly in the root directory. No extension is needed.

Raspberry Pi enable SSH

Enable VNC

Open config.txt and uncomment and save the following lines:

framebuffer_width=1280
framebuffer_height=720

Raspberry Pi enable VNC

Boot Up

Insert the micro SD card into the Raspberry Pi, connect the power, and boot it up.

Connect via SSH

Connect using hostname raspberrypi, username pi, and password raspberry.

Raspberry Pi connect SSH

Update Packages

sudo apt update
sudo apt upgrade -y

Enable VNC

sudo raspi-config

Raspberry Pi config

Select 3 Interface Options, then P3 VNC, and select YES. Close with Finish.

Connect via VNC

Raspberry Pi VNC viewer

Use the same username and password as for SSH.

Raspberry Pi VNC connected

Enable Wi-Fi

Enabling Wi-Fi via VNC eliminates the need for a wired connection, allowing you to operate the Raspberry Pi with only power.

Troubleshooting CGI not working with Ruby installed via rbenv on Webrick

· One min read

When executing CGI in the browser, an error occurs stating: /usr/bin/env: 'ruby': No such file or directory

#!/usr/bin/env ruby

# ...

Cause

The $PATH is not set.

#!/usr/bin/env bash

echo -ne "Content-type: text/html\n\n"
echo $PATH

Running this will display:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This shows that the directory containing Ruby is not present.

Solution

Set the Ruby path using :CGIPathEnv.

srv = WEBrick::HTTPServer.new({
:DocumentRoot => "./site/",
:Port => 8080,
:CGIPathEnv => ENV["PATH"]
})

How to create a gem

· One min read

Creating a Template

bundle gem <GEM Name> -t
cd <GEM Name>

Editing the Gemspec

  1. Open <GEM Name>.gemspec.
  2. Edit spec.summary, spec.description, spec.homepage,
  3. Write the homepage URL to spec.metadata["allowed_push_host"]
  4. Write the Gem's page to spec.homepage
  5. Write the repository URL to spec.metadata["source_code_uri"]
  6. Write the URL of changelog.md to spec.metadata["changelog_uri"]

Set at least this much.

Push to GitHub and Install

git init
git add .
git commit -m First Commit
git remote add origin [email protected]:<username>/<GEM Name>.git
git push -u origin master

Install

gem install specific_instal
gem specific_install -l "git://github.com/<username>/<GEM Name>.git"

Gemfile

gem "<GEM Name>", github: "<username>/<GEM Name>.git", branch: :main

Displaying Images in the Terminal

· One min read

Introducing the tiv command for displaying images in the terminal.

tiv

It's convenient when you don't want to open a file explorer.

git clone https://github.com/stefanhaustein/TerminalImageViewer.git
cd TerminalImageViewer/src/main/cpp
make -j
sudo make install

Euclidean Algorithm in Bash

· One min read
  1. Let C be the remainder when A is divided by B.

  2. Let D be the remainder when B is divided by C.

  3. Let E be the remainder when C is divided by D.

    ...

  4. Let Y be the remainder when X is divided by 0.

    Then Y is the greatest common divisor.

Bash Script

#!/usr/bin/env bash

function gcd(){
test $2 -eq 0 && echo $1 || gcd $2 $(( $1 % $2 ))
}

gcd 1071 1029
# 21

Installing ImageMagick (Ubuntu)

· One min read
wget https://download.imagemagick.org/ImageMagick/download/ImageMagick-7.0.11-14.tar.xz

Extract

tar xf ImageMagick-7.0.11-14.tar.xz

Make

sudo apt update
cd ImageMagick-7.0.11-14.tar.xz
./configure
make -j
sudo make install
sudo ldconfig /usr/local/lib

Denoising with a Gaussian Filter (Python / Scipy)

· One min read

As an example, let's use a 1[Hz] sine wave as the signal. Add noise generated from random numbers following a normal distribution with a mean of 0 and a standard deviation of 0.5 to the signal.

import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter1d

t = np.arange(1000) / 100
s = np.sin(2*np.pi*t)
noise = np.random.normal(0, 0.5, size=len(t))
x = s + noise

plt.plot(t, x, label="+noise")
plt.plot(t, s, label="signal")
plt.legend(loc=1)
plt.show()

pyplot

Apply a Gaussian filter with a standard deviation of 5. The larger the standard deviation, the smoother the result, but the more it deviates from the original signal.

y = gaussian_filter1d(x, 5)
plt.plot(t, y, label="filtered")
plt.plot(t, s, label="signal")
plt.legend(loc=1)
plt.show()

pyplot

Installing and Configuring Pyenv

· 2 min read
  1. Clone Pyenv Clone the Pyenv repository. The recommended directory is ~/ .pyenv.

git clone https://github.com/pyenv/pyenv ~/.pyenv


0. Compile Bash extensions for speed
You can compile Bash extensions for speed.
It will still work correctly if the compilation fails.

```sh
cd ~/.pyenv && src/configure && make -C src
  1. Configuration (bash) Path and other settings.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile echo 'eval "$(pyenv init --path)"' >> ~/.profile export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" echo -e 'if shopt -q login_shell; then'
'\n export PYENV_ROOT="$HOME/.pyenv"'
'\n export PATH="$PYENV_ROOT/bin:$PATH"'
'\n eval "$(pyenv init --path)"'
'\nfi' >> /.bashrc echo -e 'if [ -z "$BASH_VERSION" ]; then'
'\n export PYENV_ROOT="$HOME/.pyenv"'
'\n export PATH="$PYENV_ROOT/bin:$PATH"'
'\n eval "$(pyenv init --path)"'
'\nfi' >>
/.profile


# Installing Python Environments

## Installing Dependencies
```sh
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblemgma-dev -y

Checking Installable Environments

pyenv install -l

Installing

It takes a long time to compile, so please wait.

CONFIGURE_OPTS= "--enable-shared" pyenv install 3.9.5

Verifying Version

pyenv versions

Switching Version

pyenv global 3.9.5