The versatility of the Raspberry Pi means that at some point you’re bound to be using it outdoors, beyond the reach of your wireless network. So how can you communicate with it without plugging in a keyboard and monitor?
It goes without saying that lugging human input devices and displays around with you when isn’t practical. There’s the external power requirements of the display, for a start (unless you use a dedicated, portable Pi touchscreen display, perhaps).
A better solution is to communicate via another device, such as a notebook PC. While Wi-Fi direct is currently unsupported by the Raspberry Pi, you still have two options for a direct SSH connection without a wireless network.
When You Might Use This
Wirelessly connecting to a Raspberry Pi — whether it has wireless networking enabled or is connected via Ethernet to your router — is certainly more convenient. It’s almost certainly the preferred option, whether you’re at home, at school, or at a maker event.
However, it isn’t ideal for every scenario.
For instance, if you’re using your Pi with the camera module, you may like to take it outside, perhaps to capture some time lapse photography. Without a wireless network to connect to your Pi via SSH, you’ll need another solution, something that will work via a PC or perhaps a mobile device.
That’s where a direct connection comes in. You have two reliable options here: Ethernet and USB.
Connect to Your Raspberry Pi via Ethernet
The most obvious option for such a connection is via Ethernet cable. All Raspberry Pi computers (save the Pi Zero) have Ethernet ports, making this the option that works best.
For this, you’ll need:
- Raspberry Pi (Model B, B+, 2, or 3).
- Fresh Raspbian install (for best results).
- Micro USB cable & power supply.
- MicroSD card.
- An Ethernet cable, with RJ45 connectors at each end.
Standard Ethernet cables are fine here, as the Raspberry Pi can reconfigure the port. In times past, a crossover cable would have been used to connect two computers, but that isn’t necessary here.
You’ll need your Pi setup to accept SSH connections. This isn’t enabled by default, but there are two ways around this.
- Boot up with a keyboard and monitor to enable SSH via raspi-config.
- Insert the SD card into your PC, browse to /boot and create an empty file called ssh.
(This file is detected by the Raspbian operating system at boot, and takes it as an instruction to enable SSH.)
Everything you need to connect to the Pi via SSH is now in place. All you need is the device’s IP address. You can find this by connecting to your router (typically 192.168.0.1, but you’ll need to check the router for the correct IP) or by booting the Pi with a keyboard and monitor and entering
You’ll need to check that the Pi boots correctly before proceeding anyway, and that SSH works under normal circumstances. Our guide to connecting with SSH will be useful here.
Once you’re satisfied the Pi boots and normal wireless activity via your router is satisfactory, shut down the device.
Now, connect your Raspberry Pi to your PC with an Ethernet cable.
To get this to work, you’ll need a particular piece of software: Bonjour Zeroconf. This Apple software is a for network device recognition, and comes pre-installed in macOS. Windows users can install Bonjour Print Services v2.0.2 from the Apple website.
With this installed and the direct cable connection with your Pi established, once the little computer is powered on and fully booted, you should be able to connect.
However, patience is advised here. The Pi will first attempt to fetch an IP address from a DHCP server, then when it fails, default to private addressing in the range 169.254.x.x. You may also find it useful to switch to Airplane mode on your PC or laptop to ensure no confusion with other devices on the network. Once the IP is assigned, Bonjour networking establish the .local domain addressing.
After a short while, simply open your SSH tool and connect to raspberrypi.local (or firstname.lastname@example.org), with the default password “raspberry”.
Windows users may need to force the operating system to abandon the router-assigned IP address for this to work, however. This is easy enough to do by opening the Command Prompt and typing:
This will result in a random private IP in the 169.254.x.x range.
Connect Your PC to Raspberry Pi Zero via USB
If you have a Raspberry Pi Zero, you can also connect directly to it via your PC or laptop’s USB port, though this also requires Bonjour on Windows and Mac, or avahi-daemon on Linux (avahi-daemon is pre-installed with Ubuntu).
Begin with a fresh copy of Raspbian Jessie or Raspbian Jessie Lite (May 26th, 2016 or later) flashed to your SD card. Before inserting it into your Pi Zero, use your desktop file explorer to find the boot partition, and find config.txt. Open this in a raw text editor (such as Notepad on Windows) and scroll to the bottom. Right at the end, add:
Once you’ve done this, save and close the file, then find and open cmdline.txt. Find “rootwait” and insert this right after:
Ensure this is on the same line, separated only by a space, like this:
Save and close, then eject the microSD card. You can then insert it into your Raspberry Pi Zero and connect it to your PC before booting the device. The connection should be via USB.
Use raspberrypi.local as the address in your SSH software (again, you might also try email@example.com if using the Linux command line). Note that you may need to disable wireless networking if you have any other Raspberry Pi’s on your home network. This will ensure you connect to the Pi Zero over USB, rather than, say, your Kodi box over Wi-Fi.
If you run into any problems, try switching your USB cables.
Two Reliable Direct Connections
It would be great if it was possible to connect via Bluetooth or wireless from a mobile device — perhaps Android or iOS — and while this is theoretically possible, it currently isn’t supported. While there are some accounts of either of these methods working, neither appears particularly reliable.
But we’ll be happy to hear from you if you have got either of those methods working reliably and can connect via SSH. Tell is in the comments about that, or any problems you run into!
Image Credit: goodcat via Shutterstock