/Pocket-Pi

Run a full Raspberry Pi OS in the palm of your hand! A simple guide to setting up a Raspberry Pi Zero 2 W with a 1.3inch IPS LCD display HAT, joystick, buttons, and battery module.

Apache License 2.0Apache-2.0

Pocket Pi

A simple guide to setting up a Raspberry Pi Zero 2 W with a 1.3inch IPS LCD display HAT, joystick, buttons, and battery module.

Run a full Raspberry Pi OS in the palm of your hand!

Index

Video Preview

Demo Video

[ Index ]

Parts List

Part Price (USD)
Raspberry Pi Zero 2 W $15.00
240x240, 1.3inch IPS LCD display HAT $14.95
Uninterruptible Power Supply UPS HAT $27.95
3D Printed Case (coming soon!) ...

[ Index ]

Raspberry Pi Zero 2 W Information

"Building on the success of the current Zero family, Raspberry Pi Zero 2 W is built around a Raspberry Pi-designed System-in-Package, which integrates the BCM2710A1 die used in Raspberry Pi 3 with 512MB of RAM."

Features:

  • 1GHz quad-core, 64-bit ARM Cortex-A53 CPU
  • VideoCore IV GPU
  • 512MB LPDDR2 DRAM
  • 802.11b/g/n wireless LAN
  • Bluetooth 4.2 / Bluetooth Low Energy (BLE)
  • MicroSD card slot
  • Mini HDMI and USB 2.0 OTG ports
  • Micro USB power
  • HAT-compatible 40-pin header
  • Composite video and reset pins via solder test points
  • CSI camera connector

Purchase:

Documents:

Infographics (click to expand)

Info Images courtesy of pi3g

[ Index ]

Raspberry Pi Zero 2 W OS Setup

  1. Download the Raspberry Pi Imager: https://www.raspberrypi.com/software/

  2. Plug the microSD card into the computer and open the Raspberry Pi Imager.

  3. We'll install the full Raspberry Pi Legacy OS (Bullseye, not Bookworm, 32-bit) in this example so we can take advantage of our massive 1.3inch IPS LCD display HAT:

Info Before installation enable SSH, take note of the hostname, set the username and password for the Raspberry Pi Zero, and set up your connection to the Wi-Fi network.

Installation Images (click to expand)




Select "Raspberry Pi Zero 2 W" from the list of devices.

Select "Raspberry Pi OS (Legacy, 32-bit)" from the list of operating systems.
Or the "Use custom" if you download the OS image from the Raspberry Pi website directly from above.

Choose your storage device.

Click "Next" to start the installation process.

When the installer asks if you want to customize the installation, click "Yes". Enter your custom hostname, username, and password if you'd like, you'll use these later so take note of them.

The second customization screen allows you to set up SSH. Enable SSH and press "Save".



The installation is completed, but keep your microSD card in the computer for the next few steps.

[ Index ]

MicroSD Card Setup & PC Connection (SSH)

Copy the files from the bootfs folder at the root of this repository onto the newly created microSD card bootfs partition. This will enable SSH, Ethernet over USB, and configure the display settings for the 1.3inch IPS LCD display HAT. Be sure to overwrite any existing files on the microSD card. If you would like to do this manually, follow the steps below:

  1. With the microSD card still in your computer, open the config.txt file and modify to match the following settings:
[all]
hdmi_force_hotplug=1
hdmi_cvt=300 300 60 1 0 0 0
hdmi_group=2
hdmi_mode=87
display_rotate=0
gpio=6,19,5,26,13,21,20,16=pu

Info Comment out or remove everything prefixed with a dtoverlay= and dtparam=.

  1. Save and close config.txt.

  2. In the same directory, open the file cmdline.txt and add modules-load=dwc2,g_ether after rootwait. Ensure it remains a single line of text, and has proper spacing. For example:

... rootwait modules-load=dwc2,g_ether ...

Info This is part of enabling SSH and Ethernet over USB.

  1. Save and close cmdline.txt.

  2. Create a new file named ssh in the root of the microSD card. This is part of enabling SSH on the Raspberry Pi Zero.

  3. Remove the microSD card from the computer and insert it into the Raspberry Pi Zero.

  4. Plug the Raspberry Pi Zero into the computer using a USB cable. Connect the cable to the USB port in the center of the Raspberry Pi Zero labeled USB. The green LED will light up, indicating the Raspberry Pi Zero is powered on.

  5. You should now be able to connect to your Pi using SSH in a CLI:

# Replace "code@pocketpi.local" with your own `hostname` and `username`.
ssh code@pocketpi.local

Info It may take a minute for the Pi Zero to connect. If you are prompted to accept the host key, type yes and press Enter. You will then be prompted for the password you set during the installation.

[ Index ]

Increasing Swap Size

Increasing the swap size can help speed up the installation process and various other things. This is especially useful when installing software that requires a lot of memory, such as the Raspberry Pi OS update and upgrade process. The default swap size is 100MiB, which is not enough for some installations. Below we will change this to 2GiB (2048MiB). To do this, follow these steps:

Info You can revert this at a later point if you wish or keep it. See "Reverting back to 100MiB" below.

# Check current swap size (you should see 100MiB or 99MiB for "Swap total")
free -h
# Disable current swap
sudo dphys-swapfile swapoff
# Set the swap file size to 2048MiB, or 2GiB
sudo sed -i 's/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/' /etc/dphys-swapfile
# Recreate the swap file with the new size
sudo dphys-swapfile setup
# Enable the new swap size
sudo dphys-swapfile swapon
# Reboot
sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local
# Verify the new swap size (should be 2048MiB, or 2GiB)
free -h
Reverting back to 100MiB (click to expand)
# Disable current swap
sudo dphys-swapfile swapoff
# Set the swap file size back to 100MiB
sudo sed -i 's/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=100/' /etc/dphys-swapfile
# Recreate the swap file with the original size
sudo dphys-swapfile setup
# Enable the original swap size
sudo dphys-swapfile swapon
# Reboot
sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local
# Verify the reverted swap size (you should be 100MiB or 99MiB)
free -h

[ Index ]

Updating & Upgrading

In this section we will update and upgrade the Raspberry Pi Zero to ensure we have the latest software and security updates.

  1. Open the terminal and run the following command to access the Raspberry Pi Zero. Using the hostname and the username and password you set during the installation:
ssh code@pocketpi.local
  1. Update & upgrade the system (the y flag will automatically answer yes to any prompts)
sudo apt-get update && sudo apt-get full-upgrade -y
  1. Reboot the Raspberry Pi Zero
sudo reboot

[ Index ]

Screen Module Setup

240x240, 1.3inch IPS LCD display HAT

Purchase:

Documentation:

Pi OS Configuration

Connect to the Raspberry Pi Zero via SSH:

ssh code@pocketpi.local

Run the following commands to enable the SPI interface. It should already be enabled if you followed the SD card setup, but it's good to make sure.

sudo raspi-config
Choose Interface Options -> SPI -> Yes
Config setup Images (click to expand)

Ensure your user has the necessary permissions to access the SPI device:

sudo usermod -aG spi,gpio $(whoami)

Install fbcp driver for the screen:

cd ~
sudo apt-get install cmake -y
git clone https://github.com/juj/fbcp-ili9341.git
cd fbcp-ili9341
mkdir build
cd build
cmake -DSPI_BUS_CLOCK_DIVISOR=6 -DWAVESHARE_ST7789VW_HAT=ON -DBACKLIGHT_CONTROL=ON ..
make -j

Reboot Raspberry Pi:

sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local

To auto-start when powered on, open the /etc/rc.local file for edit:

sudo nano /etc/rc.local

And add the following line just above and before exit 0:

sudo /home/code/fbcp-ili9341/build/fbcp-ili9341 &

Info Replace code in the last example with your username.

After you're done making edits press CTRL + O, then ENTER, and then CTRL + X to exit. Reboot the Raspberry Pi Zero:

sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local

[ Index ]

Joystick and Buttons Setup

Install the necessary software to use the joystick and buttons:

sudo apt-get install python3-xlib
sudo pip3 install PyMouse
sudo pip3 install unix
sudo pip3 install PyUserInput
wget http://www.waveshare.net/w/upload/d/d3/Mouse.7z
7z x Mouse.7z
sudo python3 mouse.py

Set the auto-start when power on:

cd ~/.config/
mkdir autostart
cd autostart/
sudo nano local.desktop

Add the following lines at the end of the local.desktop file:

[Desktop Entry]
Type=Application
Exec=python3 /home/code/mouse.py

Info Replace code in the last example with your username.

Press CTRL + O, then ENTER, and then CTRL + X to exit. Reboot the Raspberry Pi Zero:

sudo reboot

You should now be able to use the joystick and buttons to move the mouse cursor and click on the screen.

[ Index ]

Battery Module Setup

Uninterruptible Power Supply UPS HAT

Purchase:

Documentation:

Pi OS Configuration

Run the following commands to enable the I2C interface. It should already be enabled if you followed the SD card setup, but it's good to make sure.

sudo raspi-config 
Choose Interfacing Options -> I2C -> Yes
Config setup Images (click to expand)

Then reboot the Pi Zero:

sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local

Software Installation

# Download the UPS HAT software archive from the Waveshare website
wget https://files.waveshare.com/upload/4/40/UPS_HAT_C.7z

# Extract the downloaded 7z archive to the current directory
7zr x UPS_HAT_C.7z -r -o./

Run the UPS HAT software

# Change directory to the newly created directory containing the extracted files
cd UPS_HAT_C

# Run the Python script named 'INA219.py', which typically handles the monitoring of the UPS
python3 INA219.py

Info If the current value is negative, it means that the batteries are feeding the Raspberry Pi. If the current value is positive, it means that the batteries are charging.

[ Index ]

Licensing

This project is licensed under the Apache License, Version 2.0. See the APACHE_2_LICENSE file for the pertaining license text.

SPDX-License-Identifier: Apache-2.0

[ Index ]

Useful Commands

Edit the config.txt file:

sudo nano /boot/config.txt

[ Index ]

Wrapping Up

Thanks to all the people and projects that made this possible! I hope you enjoy this project as much as I enjoyed working on it. If you have any questions, please let me know by opening an issue here.

Type Info
webmaster@codytolene.com
https://www.buymeacoffee.com/codytolene
bc1qfx3lvspkj0q077u3gnrnxqkqwyvcku2nml86wmudy7yf2u8edmqq0a5vnt

Fin. Happy programming friend!

Cody Tolene