Note: RPi 4B is a legacy platform. The primary platform is RPi 5 — see rpi5.md.
Reason for migration: RPi 4 is too slow for real-time detection. YOLO inference on RPi 4: 2.4 FPS (NCNN, 1 thread) vs 14.9 FPS on RPi 5 (pip ncnn native, 4 OMP threads, with preprocessing) — more than a 6x difference. PyTorch is even worse: 1.1 FPS. The sock-finding task requires at least 10 FPS, which RPi 4 cannot deliver.
Guide for preparing a Raspberry Pi 4B to run the SocksTank robot.
- Raspberry Pi 4B (4 GB RAM) — legacy, for new builds RPi 5 is recommended
- SD card 32 GB+ (Class 10 / A2)
- ov5647 camera (OmniVision) — included in the Freenove Tank Kit
- Freenove Tank Robot Kit — assembled following the included instructions
- Power supply 5V/3A (for RPi 4B) or 5V/5A (for RPi 5)
- Download Raspberry Pi Imager
- Select Raspberry Pi OS (64-bit) — Debian bookworm
- In Imager settings (gear icon) configure:
- Hostname (e.g.,
tank) - Username and password
- WiFi settings (SSID and password)
- Enable SSH
- Hostname (e.g.,
- Flash the image to the SD card
- Insert the card into RPi and power on
Connect via SSH after boot:
ssh user@tank.local
# or by IP if mDNS doesn't work:
ssh user@192.168.x.xUpdate the system before installing dependencies:
sudo rm /var/lib/apt/lists/*.debian.org_*
sudo apt update
sudo apt upgrade -yWithout this step some packages (emacs-nox, libcap-dev) may fail to install.
sudo apt install htop mc emacs-nox git screenRun the setup script from the Freenove kit. It installs all required libraries and configures the camera type (ov5647):
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code
sudo python setup.pyFor LED support:
sudo pip install rpi_ws281x --break-system-packagesFor servo support (hardware PWM):
sudo pip install rpi-hardware-pwm --break-system-packagessudo apt install libcap-dev python3-picamera2Or via pip:
sudo pip install picamera2 --break-system-packagesAdd to the end of the file:
start_x=1
gpu_mem=512
# dtoverlay=vc4-kms-v3d
dtoverlay=cma,cma-320
dtoverlay=dmaheap,size=128M
dtoverlay=ov5647Reboot the RPi after changes (sudo reboot).
v4l2-ctl --device /dev/video0 --allThe camera is mounted upside down, so Transform(vflip=True) is used in the code.
The pigpiod daemon must start automatically on boot for GPIO access.
#!/bin/sh
sleep 5
sudo pigpiodmkdir -p ~/.config/autostart
chmod +x ~/start.shCreate file ~/.config/autostart/start.desktop:
[Desktop Entry]
Type=Application
Name=start
NoDisplay=true
Exec=/home/user/start.shchmod +x ~/.config/autostart/start.desktopIf the RPi is connected via WiFi and you need a fixed IP:
sudo nmcli con modify "YOUR_WIFI_SSID" ipv4.addresses 192.168.x.x/24
sudo nmcli con modify "YOUR_WIFI_SSID" ipv4.gateway 192.168.x.1
sudo nmcli con modify "YOUR_WIFI_SSID" ipv4.dns "8.8.8.8"
sudo nmcli con modify "YOUR_WIFI_SSID" ipv4.method manual
sudo nmcli con up "YOUR_WIFI_SSID"Replace YOUR_WIFI_SSID with your WiFi network name.
After installing all dependencies, verify that components work:
cd ~/Freenove_Tank_Robot_Kit_for_Raspberry_Pi/Code/Server/
# Test LEDs
sudo python test.py Led
# Test servos (claw, lift)
sudo python test.py Servo
# Test motors (movement)
sudo python test.py MotorIf everything works — the tank is ready.
Overclocking can improve inference performance but increases heat. Good cooling is required.
Add to /boot/firmware/config.txt:
arm_freq=2147
gpu_freq=750
over_voltage=6
force_turbo=1
sdram_freq=3200Reboot and verify the frequency:
lscpu | grep "CPU max MHz"Warning: without active cooling (fan or heatsink) overclocking may cause throttling and instability.
pip install ultralytics[extra] --break-system-packagesIf you get a numpy.dtype size changed error after installation:
ValueError: numpy.dtype size changed, may indicate binary incompatibility.
Expected 96 from C header, got 88 from PyObject
Reinstall picamera2 and simplejpeg:
pip install --upgrade picamera2 simplejpeg --break-system-packagesFor remote desktop access to the RPi:
- Enable VNC via
raspi-config:sudo raspi-config # Interface Options → VNC → Enable - Connect from your computer using RealVNC Viewer
| ← Previous | README | Next → |
|---|---|---|
| Infrastructure | Back to README | Raspberry Pi 5 Setup |