Skip to main content

Setting Up Raspberry Pi 4 with USB-C Connection to iPad/Laptop

 

Introduction

In this guide, we'll configure a Raspberry Pi 4 to be powered and accessed directly through a single USB-C cable connected to an iPad or laptop. This setup creates a portable, headless Raspberry Pi that requires no separate power adapter, HDMI display, keyboard, or Ethernet cable. Perfect for mobile development, testing, or working with your Pi on the go.

Objective

Our goal is to create a fully functional Raspberry Pi 4 setup that can be accessed via a single USB-C connection. We'll accomplish this by:

  • Using Raspberry Pi Imager to customize Pi OS Lite (64-bit) with SSH and WiFi credentials
  • Burning the configured image to an SD card
  • SSH into the Pi via WiFi for initial configuration
  • Updating boot configuration files to enable USB gadget mode
  • Creating a new network connection using nmcli and activating it on boot
  • Connecting the Pi to an iPad or laptop using only a USB-C cable

Hardware Requirements

To complete this setup, you'll need:

  • iPad or laptop with USB-C port capable of providing power
  • Raspberry Pi 4 (any RAM variant)
  • MicroSD card (16GB or larger recommended)
  • USB-C cable that supports both power and data delivery
  • Computer (Windows, Mac, or Linux) to burn the initial image

Detailed Setup Instructions

Step 1: Burn the Image

First, we'll prepare the SD card with Raspberry Pi OS and pre-configure essential settings.

  1. Download and install Raspberry Pi Imager on your computer
  2. Launch Raspberry Pi Imager
  3. Click "Choose Device" and select Raspberry Pi 4
  4. Click "Choose OS" and select Raspberry Pi OS (other) → Raspberry Pi OS Lite (64-bit)
  5. Click "Choose Storage" and select your SD card
  6. Click the gear icon (⚙️) or "Next" to access OS customization settings
  7. Configure the following settings:
    • Hostname: Set a memorable hostname (e.g., rasp.local)
    • Username and password: Create your credentials
    • WiFi: Enter your WiFi network name (SSID) and password
    • Locale settings: Set your country and timezone
    • Enable SSH: Check "Enable SSH" and select "Use password authentication"
  8. Click "Save" and then "Write" to burn the image to the SD card
  9. Once complete, insert the SD card into your Raspberry Pi 4 and power it on

Wait a few minutes for the Pi to boot and connect to your WiFi network.

Step 2: Configure the Pi to Use USB-C Port as a Network Interface

Now we'll configure the Raspberry Pi to act as a USB Ethernet gadget, allowing network communication through the USB-C port.

2.1 Connect via SSH

From your computer (connected to the same WiFi network), SSH into your Pi:

ssh username@rasp.local

Replace username with the username you configured earlier. This assumes the following:

  • You setup the hostname of your Pi as rasp.local when creating an image
  • The laptop and Pi are connected to the same wireless network

2.2 Become Superuser

Switch to root user for the following configuration steps:

sudo su

2.3 Edit cmdline.txt

Open the boot command line configuration file:

nano /boot/firmware/cmdline.txt

Add the following options after rootwait (keep everything on a single line):

modules-load=dwc2,g_ether

The complete line should look similar to this:

console=serial0,115200 console=tty1 root=PARTUUID=c8575274-02 rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_ether cfg80211.ieee80211_regdom=US

Save and exit (Ctrl+X, then Y, then Enter).

2.4 Edit config.txt

Open the boot configuration file:

nano /boot/firmware/config.txt

Find the [cm4] section and ensure that otg_mode=1 is uncommented. Then scroll down to the [all] section and add the following line after it:

dtoverlay=dwc2

The final configuration file should look similar to this:

# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Automatically load initramfs files, if found
auto_initramfs=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1

# Run in 64-bit mode
arm_64bit=1

# Disable compensation for displays with overscan
disable_overscan=1

# Run as fast as firmware / board allows
arm_boost=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[cm5]
dtoverlay=dwc2,dr_mode=host

[all]
dtoverlay=dwc2

Save and exit (Ctrl+X, then Y, then Enter).

Step 3: Create USB Network Connection and Activate on Boot

Now we'll create a persistent network connection for the USB interface that will automatically activate at boot.

3.1 Create USB Connection

Create a new Ethernet connection for the USB interface:

nmcli con add type ethernet con-name ethernet-usb0

3.2 Configure Connection Settings

Edit the connection configuration file:

nano /etc/NetworkManager/system-connections/ethernet-usb0.nmconnection

Update the file to match the following configuration:

[connection]
id=ethernet-usb0
uuid=Will be specific to your env
type=ethernet
autoconnect=true
interface-name=usb0

[ethernet]

[ipv4]
method=shared

[ipv6]
addr-gen-mode=default
method=auto

[proxy] 

The uuid field will already be populated with a unique identifier. The key settings here are:

  • autoconnect=true - Connection starts automatically at boot
  • interface-name=usb0 - Binds to the USB gadget interface
  • method=shared - Enables internet connection sharing

Important Note on Connection Sharing: Setting method=shared makes the Raspberry Pi automatically run a DHCP server that assigns an IP address to your iPad or laptop. The Pi will then NAT (Network Address Translation) all traffic from your device through to the internet via its WiFi connection. This means your iPad can access the internet through the Pi.

If you don't want internet sharing and only need direct device-to-device communication, change the method to link-local:

[ipv4]
method=link-local

With link-local, both devices will self-assign IP addresses in the 169.254.x.x range without running a DHCP server, and no internet traffic will be routed through the Pi.

Save and exit.

3.3 Create USB Gadget Activation Script

Create a script that will bring up the USB connection:

nano /usr/local/sbin/usb-gadget.sh

Paste the following content:

#!/bin/bash
nmcli con up ethernet-usb0

Save and exit, then make the script executable:

chmod a+rx /usr/local/sbin/usb-gadget.sh

3.4 Create Systemd Service

Create a systemd service that will run the script at boot:

nano /lib/systemd/system/usbgadget.service 

Paste the following configuration:

[Unit]
Description=My USB gadget
After=NetworkManager.service
Wants=NetworkManager.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/usb-gadget.sh

[Install]
WantedBy=sysinit.target

Save and exit.

3.5 Enable Service and Reboot

Enable the service to run at boot and restart the Pi:

systemctl enable usbgadget.service
reboot


Step 4: Connect the Pi to the iPad/Laptop via USB-C

Connect your Raspberry Pi 4's USB-C port to your iPad or laptop using a USB-C cable and wait 30-60 seconds for the connection to establish:

  1. The USB-C cable will both power the Pi and create the network connection
  2. On your iPad, navigate to Settings → Ethernet
  3. You should see a new Ethernet connection appear automatically
  4. Your iPad will receive an IP address on the 10.x.x.x network from the Pi's DHCP server
  5. Your iPad will now have internet access through the Raspberry Pi's WiFi connection
  6. Install a terminal application like Terminus or Blink Shell on your iPad
  7. Connect to your Pi using its hostname:

ssh username@rasp.local

The Raspberry Pi will have the gateway IP address (typically 10.42.0.1) on the usb0 interface, and your iPad will be assigned an address like 10.42.0.x.

Conclusion

Congratulations! You've successfully configured your Raspberry Pi 4 to work seamlessly with just a single USB-C cable. This setup provides several advantages: your iPad or laptop powers the Pi while simultaneously providing network connectivity, eliminating cable clutter and making your Pi truly portable. Whether you're developing on the go, demonstrating projects, or simply prefer a minimalist setup, this configuration offers convenience without sacrificing functionality.

The USB gadget mode essentially turns your Raspberry Pi into a plug-and-play device that creates its own network connection whenever you connect it via USB-C. You can still access WiFi for internet connectivity while using the USB connection for direct device-to-device communication. This makes it perfect for scenarios where you need reliable, low-latency access to your Pi without depending on WiFi network availability.

Feel free to expand on this setup by installing additional software, setting up development environments, or creating automated scripts. Your portable Raspberry Pi workstation is now ready for whatever projects you have in mind. Happy tinkering!

Comments

Popular posts from this blog

Securing Traefik with Let's Encrypt

Introduction Building on the previous Traefik setup with an internal domain and applications, this tutorial guides you through using a public domain with trusted certificates. Objective The core objectives of this tutorial are to: Deploy Traefik with Automatic SSL using Docker:  This step covers installing the latest Traefik with Let's Encrypt integration and exposing the container to the internet. Configure DNS for Secure Access:  Set up an A record in your domain provider (e.g., Cloudflare) pointing to your pfSense firewall's public IP address for external access and pfsense's DNS server for internal access. Access Applications with HTTPS:  Access your applications using their fully qualified domain names with trusted certificates externally and internally Topology Lets walk through our topology: pfsense This is our firewall which is directly connected to the Internet and doing the following: NATs all traffic from the internal LAN network (192.168.11.0/24) to the WAN (...

Authenticating Traefik Apps with Authentik

 Introduction In our previous post , we secured the Homer app with trusted Let's Encrypt certificates using Traefik as a reverse proxy. But what if only authorized users should access Homer? In this blog, we'll address this by adding multi-factor authentication to Homer using Authentik as an Identity Provider (IdP). Objective The core objectives of this tutorial are to: Set Up Secure Access with Authentik:  Install Authentik using Docker Compose and create your first user to manage access control. Secure Homer with Authentik:  Configure Authentik to act as a gatekeeper, ensuring only authorized users can access your Homer application. Simplify Logins with Traefik:  Integrate Traefik with Authentik to enable Single Sign-On (SSO) for a seamless login experience across your applications. Connect Homer to Authentik:  Configure Homer to leverage Authentik's authentication system for secure logins. Topology For the topology details please see the previous post ....

Run your Meteor App on a Production Ubuntu 16.04 Server with Nginx

Introduction Meteor enables developers to create apps and quickly test them on a development webserver. Once you have created your app the big question is how to run it on a production server. In this tutorial we will demostrate how to run your Meteor app on Ubuntu 16.04 using Nginx Credits and Acknowledgements This entire post is based off this Digital Ocean article. The article was modified for issues we encountered and adapted for Ubuntu 16.04. The entire credit goes to Daniel Speichert Objective In this tutorial we will: Install and Configure Nginx with HTTPS enabled Install MongoDB Install NodeJS Bundle your Meteor App Create a startup script to automatically start your app on reboot Assumptions We assumue the following: You already have a fresh install of Ubuntu 16.04 Server SSH enabled on your fresh install You have root privelages on your server You have a different server where you can insall meteor and budle your app...