Sometimes it’s useful to have one Raspberry talk via IP to a second RaspberryPiZero. Maybe one it’s acting as a slave to the second, or they need to synchronize some data or operations.. anyway, we would like for them to be able to communicate, but we don’t want to mess with another wifi or an ethernet dongle.
It’s really easy, basically it boils down to enable the so-called USB OTG mode on both Raspberries, even the non Zero, and configure the
usb0 interface with a static, comaptible IP address, on both machines. Then it’s possible for them to talk via IP over the USB cable.
Here is a detailed description. To proceed you need:
- one RaspberryPi3 and a PiZero (or two Zero). Let’s call ‘em A (master) and B (slave)
- be able to access
Aeither via serial console or wifi/ethernet with ssh
- an USB / USB micro (the one usually used to connect Android to a PC). The cable must be able to carry data, not only power.
- a micro SD reader
- a “real” working computer, best if connected to the internet
First of all, configure the two Raspberries to have a working ethernet-over-USB. There are many tutorials on line on the USB OTG configuration, one is: Serial Gadget Adafruit.
You will need just a PC/MAC and a microSD card reader. Please note that you have to configure also the RaspberryPi3 that way,
Once done, we suggest to set up a fixed IP address on both. Maybe it will also work with the Bonjour (Avahi) name, if thei both have a different one, but we haven’t tried.
So, first we configure the
A Raspberry. If it’s a Pi3 it could be even more complicated to congiure it :)
To access it you have various ways:
1) a USB/serial TTY cable. Handy, but not everybody has one.
2) using Ethernet on a Pi3 or Wifi, if either is configured
3) taking the SD card and inserting it into the RaspberryPi Zero.
We choose number 3). Stick the SD card in the Zero, and connect it to the PC/MAC with the USB/MicroUSB cable. Use the micro port labeled “USB” on the Zero. Then do ssh to enter it.
ssh email@example.com (password is
raspberry if you haven’t changed it)
then we configure the raspberry to have a fixed IP over USB.
sudo su -
this file must have, at the end, a section for the interface
iface lo inet loopback
iface eth0 inet static
iface wlan0 inet manual
iface wlan1 inet manual
iface usb0 inet static
The important part is the last USB block (with
allow-hotplug usb0). This is the static IP address used to link the wto Raspberries. Write it down somewhere, we just need any address in the
192.168.x.x subnetworks (or the like, just be careful they not overlap with the one for
reboot. To check the address is correct, connect the PiZero to your PC/Mac after having configured its RNDIS interface to have a static IP on the same subnetwork.
Or use a Bonjour Browser that will display the IP addresses also, for example Bonjour Browser per Mac OSX.
To connect via SSH to the above IP, first configure the PC/MAC with a static address, then try:
Now we can configure the second Raspberry, the
B one. It’s very similar. Since it’s a Zero, it won’t have a
eth0 section. Just copy the
usb0 section and edit the
/etc/network/interfaces like that:
iface usb0 inet static
Now we can finally connect the two Raspberry. Get the OTG USB cable, connect the big USB plug into one USB socket on the
A Raspberry, and plug the small end into the PiZero, in the port labeled ‘USB’.
Then power up the
A via TTY, or USB power, and log into it via SSH or console.
Once inside, type
ifconfig usb0, we should see something similar
usb0 Link encap:Ethernet HWaddr ba:18:cc:c1:1f:82
inet addr:192.168.42.43 Bcast:192.168.42.255 Mask:255.255.255.0
inet6 addr: fe80::182d:a64b:9b94:9809/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:98 errors:0 dropped:0 overruns:0 frame:0
TX packets:141 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:12185 (11.8 KiB) TX bytes:18791 (18.3 KiB)
Then we can
ssh firstname.lastname@example.org and we should log onto Raspberry
A, just using the USB cable .
A we can do a fouble check:
ping 192.168.42.43 should work.
From now on the two systems can talk to each other via an off-the shelf USB OTG cable.