OC
OceanRemote
Low-code IoT platform
← Back to Tutorials
← Previous Next →

Tutorial 14: Raspberry Pi 4 / Zero 2W - Setup Guide

📖 What You'll Learn in This Tutorial:
  • ✓ Setting up Raspberry Pi OS on Pi 4 / Zero 2W
  • ✓ Installing Python and required libraries
  • ✓ Connecting relays and sensors to GPIO
  • ✓ Running OceanRemote Python firmware
  • ✓ Troubleshooting common Raspberry Pi issues
⚠️ Coming Soon!

OceanRemote firmware for Raspberry Pi 4 and Zero 2W is currently under development. This tutorial will be fully updated when the firmware is released. Estimated release: Q2 2026.

In the meantime, you can use ESP8266, ESP32, or Pico W boards with OceanRemote.

Raspberry Pi 4 vs Zero 2W Overview

OceanRemote will support two Raspberry Pi models for IoT control:

📊 Raspberry Pi Comparison:
Feature Raspberry Pi 4 Raspberry Pi Zero 2 W
Processor Quad-core Cortex-A72 1.5GHz Quad-core Cortex-A53 1GHz
RAM 2/4/8 GB 512 MB
WiFi Dual-band 802.11ac 2.4GHz 802.11n
Bluetooth Bluetooth 5.0 Bluetooth 4.2
GPIO Pins 40-pin (standard) 40-pin (unpopulated)
Ethernet Gigabit No
USB Ports 4x USB 3.0 / 2.0 1x USB 2.0 (OTG)
Price $35-75 $15

What Makes Raspberry Pi Different

Unlike ESP8266, ESP32, and Pico W (microcontrollers), the Raspberry Pi 4 and Zero 2W are full Linux computers. This means:

  • Full Operating System - Runs Raspberry Pi OS (Linux)
  • Python Native - OceanRemote firmware runs as a Python script, not compiled C++
  • Multi-tasking - Can run multiple programs simultaneously
  • Storage - Uses SD card for storage (GBs, not MBs)
  • Networking - Full TCP/IP stack, SSH access, web server capabilities
  • USB Ports - Can connect USB devices (cameras, storage, etc.)
🔧 When to Use Raspberry Pi:
  • Choose Raspberry Pi for: Complex logic, data logging, camera integration, web interfaces, or when you need a full computer
  • Choose ESP32/Pico W for: Simple relay control, battery-powered projects, low-cost deployments

Prerequisites

  • Raspberry Pi 4 (2GB+ recommended) or Raspberry Pi Zero 2 W
  • MicroSD card (16GB minimum, 32GB recommended)
  • 5V 3A USB-C power supply (Pi 4) or 5V 2.5A (Zero 2W)
  • Micro HDMI cable (Pi 4) or mini HDMI (Zero 2W) - optional for headless setup
  • USB keyboard and mouse (for initial setup)
  • Ethernet cable (optional, for faster setup)
  • Relay module (5V, active LOW recommended)
  • Dupont jumper wires (female-female)
  • Optional: DHT22, DS18B20, or NTC sensor

Step 1: Install Raspberry Pi OS

Download Raspberry Pi Imager

  1. Go to https://www.raspberrypi.com/software/
  2. Download Raspberry Pi Imager for your operating system
  3. Install and run the Imager

Flash the SD Card

  1. Insert your microSD card into your computer
  2. In Raspberry Pi Imager, click Choose Device and select your model (Pi 4 or Zero 2 W)
  3. Click Choose OSRaspberry Pi OS (other)Raspberry Pi OS Lite (32-bit) (headless) or Raspberry Pi OS (32-bit) (with desktop)
  4. Click Choose Storage and select your SD card
  5. Click the gear icon (⚙️) to configure advanced options:
    • Set hostname: oceanremote-pi or your choice
    • Enable SSH: Check "Enable SSH" and "Use password authentication"
    • Set username/password: Default pi/raspberry (change for security)
    • Configure WiFi: Enter your SSID and password
    • Set locale settings: Timezone, keyboard layout
  6. Click Write and wait for the process to complete
💡 Headless Setup Tip:

Enable SSH and configure WiFi in the Imager's advanced options. This allows you to run your Pi without a monitor or keyboard.

Step 2: Boot and Connect to Your Pi

Option A: With Monitor (Desktop)

  1. Insert the SD card into your Pi
  2. Connect HDMI cable to monitor
  3. Connect USB keyboard and mouse
  4. Connect power supply
  5. Wait for boot (30-60 seconds)
  6. Log in with your username/password
  7. Open Terminal (Ctrl+Alt+T)

Option B: Headless (SSH)

  1. Insert the SD card into your Pi
  2. Connect power supply
  3. Wait 1-2 minutes for boot
  4. Find your Pi's IP address:
    • Check your router's DHCP client list
    • Use ping raspberrypi.local (Mac/Linux)
    • Use arp -a (Windows)
  5. Connect via SSH:
    ssh pi@[IP_ADDRESS]
⚠️ Default Credentials:

Default username: pi
Default password: raspberry
Change these immediately for security!

Step 3: Update Raspberry Pi OS

Once connected, run these commands to update your system:

sudo apt update
sudo apt upgrade -y
sudo apt install python3-pip python3-venv git -y

Step 4: Install Python Libraries

OceanRemote firmware for Raspberry Pi requires these Python libraries:

# Install required packages
sudo pip3 install requests
sudo pip3 install RPi.GPIO
sudo pip3 install adafruit-circuitpython-dht
sudo apt install python3-libgpiod -y

# For DS18B20 sensor (optional)
sudo modprobe w1-gpio
sudo modprobe w1-therm
📚 Library Notes:
  • requests - HTTP client for API calls
  • RPi.GPIO - GPIO control library
  • adafruit-circuitpython-dht - DHT22/DHT11 sensor library
  • w1-gpio, w1-therm - Kernel modules for DS18B20

Step 5: Enable GPIO Access

To control GPIO pins without sudo, add your user to the gpio group:

sudo usermod -a -G gpio pi
sudo reboot

Step 6: Raspberry Pi GPIO Pinout

The 40-pin GPIO header is identical on Pi 4 and Zero 2W:

                    Raspberry Pi 40-Pin GPIO Header
            ┌─────────────────────────────────────────────┐
            │  3.3V  │ 1 │ 2 │ 5V                       │
            │  GPIO2 │ 3 │ 4 │ 5V                       │
            │  GPIO3 │ 5 │ 6 │ GND                      │
            │  GPIO4 │ 7 │ 8 │ GPIO14 (TXD)             │
            │  GND   │ 9 │10 │ GPIO15 (RXD)             │
            │  GPIO17│11 │12 │ GPIO18                   │
            │  GPIO27│13 │14 │ GND                      │
            │  GPIO22│15 │16 │ GPIO23                   │
            │  3.3V  │17 │18 │ GPIO24                   │
            │  GPIO10│19 │20 │ GND                      │
            │  GPIO9 │21 │22 │ GPIO25                   │
            │  GPIO11│23 │24 │ GPIO8                    │
            │  GND   │25 │26 │ GPIO7                    │
            │  GPIO0 │27 │28 │ GPIO1                    │
            │  GPIO5 │29 │30 │ GND                      │
            │  GPIO6 │31 │32 │ GPIO12                   │
            │  GPIO13│33 │34 │ GND                      │
            │  GPIO19│35 │36 │ GPIO16                   │
            │  GPIO26│37 │38 │ GPIO20                   │
            │  GND   │39 │40 │ GPIO21                   │
            └─────────────────────────────────────────────┘

OceanRemote Default GPIO Assignments (Coming Soon)

Component GPIO (BCM) Physical Pin Notes
Relay 1 GPIO17 Pin 11 ✅ Safe
Relay 2 GPIO27 Pin 13 ✅ Safe
Relay 3 GPIO22 Pin 15 ✅ Safe
Relay 4 GPIO23 Pin 16 ✅ Safe
Relay 5 GPIO24 Pin 18 ✅ Safe
DHT22 Sensor GPIO4 Pin 7 Pull-up recommended
DS18B20 Sensor GPIO4 Pin 7 4.7kΩ pull-up to 3.3V
NTC Thermistor N/A Analog (ADC not directly available) Requires external ADC (e.g., MCP3008)
🔌 Raspberry Pi GPIO Notes:
  • BCM Numbering - OceanRemote uses BCM (Broadcom) pin numbering, not physical pin numbers
  • 3.3V Logic - GPIO pins are 3.3V only. Do NOT connect 5V signals directly
  • No Built-in ADC - Raspberry Pi does NOT have analog inputs. For NTC sensors, use an external ADC like MCP3008 or ADS1115
  • Pull-up Resistors - Some pins have internal pull-ups that can be enabled in software
⚠️ Important Raspberry Pi GPIO Warnings:
  • GPIO14 (TXD) and GPIO15 (RXD) - Used for serial console. Avoid if using Serial.
  • GPIO2 and GPIO3 - Have fixed 1.8kΩ pull-up resistors (I2C). May affect relays.
  • GPIO0 and GPIO1 - Reserved for EEPROM (HAT ID). Avoid using.
  • All GPIOs are 3.3V - 5V will damage the Pi!

Step 7: Wiring Relays to Raspberry Pi

Relay Pi GPIO Physical Pin Relay Module Connection
Relay 1 GPIO17 Pin 11 IN1 → GPIO17, VCC → 5V, GND → GND
Relay 2 GPIO27 Pin 13 IN2 → GPIO27, VCC → 5V, GND → GND
Relay 3 GPIO22 Pin 15 IN3 → GPIO22, VCC → 5V, GND → GND
Relay 4 GPIO23 Pin 16 IN4 → GPIO23, VCC → 5V, GND → GND
Relay 5 GPIO24 Pin 18 IN5 → GPIO24, VCC → 5V, GND → GND
Relay Wiring Diagram (Raspberry Pi):
┌─────────────┐                    ┌─────────────────────────────┐
│  Raspberry  │                    │      5-Channel Relay Module  │
│   Pi 4/Zero │                    ├─────────────────────────────┤
├─────────────┤                    │  IN1 │ GPIO17 (Pin 11)       │
│   5V Pin 2  ├────────────────────┤  IN2 │ GPIO27 (Pin 13)       │
│   GND       ├────────────────────┤  IN3 │ GPIO22 (Pin 15)       │
│   GPIO17    ├────────────────────┤  IN4 │ GPIO23 (Pin 16)       │
│   GPIO27    ├────────────────────┤  IN5 │ GPIO24 (Pin 18)       │
│   GPIO22    ├────────────────────┤  VCC │ 5V (Pin 2 or 4)       │
│   GPIO23    ├────────────────────┤  GND │ GND                   │
│   GPIO24    ├────────────────────┘                             │
└─────────────┘                                                  │
                          ┌─────────────────────────────────────┘

Step 8: Wiring Sensors

DHT22 Temperature & Humidity Sensor

DHT22 Pin Connect to Pi
VCC 3.3V (Pin 1 or 17)
DATA GPIO4 (Pin 7)
GND GND

DS18B20 Digital Temperature Sensor

DS18B20 Pin Connect to Pi
VDD 3.3V (Pin 1 or 17)
DATA GPIO4 (Pin 7) + 4.7kΩ pull-up to 3.3V
GND GND
⚠️ Note on Analog Sensors (NTC):

Raspberry Pi does NOT have analog inputs. To use NTC thermistors, you need an external ADC (Analog-to-Digital Converter) like MCP3008 or ADS1115. OceanRemote firmware will support external ADCs in a future update.

Step 9: Power Requirements

Raspberry Pi 4

  • Official Power Supply: 5V 3A USB-C
  • Typical current draw: 600-800mA (idle), 1.2-2A (full load)
  • With relays: Use external 5V supply for relay module (do NOT power from Pi's 5V pin if using many relays)

Raspberry Pi Zero 2 W

  • Power Supply: 5V 2.5A USB micro
  • Typical current draw: 120-150mA (idle), 300-400mA (full load)
  • With relays: Use external 5V supply for relay module
⚠️ Power Warning:

The 5V pin on Raspberry Pi GPIO is directly connected to USB power. Drawing too much current can damage the Pi. For multiple relays, use an external 5V power supply for the relay module and connect the grounds together.

Step 10: Running OceanRemote Firmware (Coming Soon)

Once the firmware is released, you'll:

  1. Generate Python firmware from the OceanRemote dashboard
  2. Copy the code to your Pi
  3. Run the script: python3 oceanremote_firmware.py
  4. Set up auto-start on boot (systemd service)
# Example future commands (when firmware is available)
wget https://www.oceanremote.net/firmware/pi_firmware.py
python3 pi_firmware.py

Troubleshooting

Pi Won't Boot

  • Check power supply (5V 3A for Pi 4, 5V 2.5A for Zero 2W)
  • Re-flash SD card with Raspberry Pi Imager
  • Check activity LED (green LED should blink)
  • Try a different SD card (some are incompatible)

Can't SSH to Pi

  • Enable SSH in Imager's advanced options
  • Create empty ssh file on boot partition
  • Check your router's DHCP client list for IP address
  • Try ping raspberrypi.local

GPIO Permission Denied

  • Run sudo usermod -a -G gpio pi and reboot
  • Or run Python with sudo (not recommended)

Relays Not Responding

  • Verify relay VCC is connected to 5V (external supply recommended)
  • Test GPIO with a simple LED before connecting relay
  • Check that you're using BCM numbering (not physical pin numbers)
🔧 GPIO Test Code:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

while True:
    GPIO.output(17, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(17, GPIO.LOW)
    time.sleep(1)

Next Steps

While waiting for OceanRemote firmware for Raspberry Pi:

  • Tutorial 15: Flashing Firmware to Your Device (for ESP boards)
  • Tutorial 16-20: Working with sensors (applicable to Pi too)
  • Sign up for updates: We'll notify you when Raspberry Pi firmware is ready!
🎯 Stay Tuned!

Raspberry Pi 4 and Zero 2W support is coming soon. Join our mailing list to be notified when the firmware is released!