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!
- Video Preview
- Parts List
- Raspberry Pi 2 W Information
- Raspberry Pi 2 W OS Setup
- MicroSD Card Setup & PC Connection (SSH)
- Increasing Swap Size
- Updating & Upgrading
- Screen Module Setup
- Joystick and Buttons Setup
- Battery Module Setup
- Licensing
- Useful Commands
- Wrapping Up
[ Index ]
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 ]
"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:
-
https://www.raspberrypi.com/documentation/computers/getting-started.html
-
https://datasheets.raspberrypi.com/rpizero2/raspberry-pi-zero-2-w-product-brief.pdf
[ Index ]
-
Download the Raspberry Pi Imager: https://www.raspberrypi.com/software/
-
Plug the microSD card into the computer and open the Raspberry Pi Imager.
-
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:
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 ]
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:
- 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
Comment out or remove everything prefixed with a
dtoverlay=
anddtparam=
.
-
Save and close
config.txt
. -
In the same directory, open the file
cmdline.txt
and addmodules-load=dwc2,g_ether
afterrootwait
. Ensure it remains a single line of text, and has proper spacing. For example:
... rootwait modules-load=dwc2,g_ether ...
-
Save and close
cmdline.txt
. -
Create a new file named
ssh
in the root of the microSD card. This is part of enabling SSH on the Raspberry Pi Zero. -
Remove the microSD card from the computer and insert it into the Raspberry Pi Zero.
-
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. -
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
It may take a minute for the Pi Zero to connect. If you are prompted to accept the host key, type
yes
and pressEnter
. You will then be prompted for the password you set during the installation.
[ Index ]
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:
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 ]
In this section we will update and upgrade the Raspberry Pi Zero to ensure we have the latest software and security updates.
- 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
- Update & upgrade the system (the y flag will automatically answer yes to any prompts)
sudo apt-get update && sudo apt-get full-upgrade -y
- Reboot the Raspberry Pi Zero
sudo reboot
[ Index ]
240x240, 1.3inch IPS LCD display HAT
Purchase:
Documentation:
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
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 &
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 ]
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
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 ]
Uninterruptible Power Supply UPS HAT
Purchase:
Documentation:
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
Then reboot the Pi Zero:
sudo reboot
# Reconnect to the Raspberry Pi Zero
ssh code@pocketpi.local
# 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./
# 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
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 ]
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 ]
Edit the config.txt
file:
sudo nano /boot/config.txt
[ Index ]
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