Setting up a Pi Zero - cjus/hydra-cluster GitHub Wiki

The following instructions walk you through setting up a Raspberry Pi Zero using an Apple Mac. Check out Andrew's blog for historical background information. This post is based in part on Andrew's "Setting up Pi Zero OTG - The quick way" and provides detailed before and after steps.

Installing Linux

Visit the Raspberry Pi download site and grab a copy of Raspbian Jesse Lite. Unzip the resulting image file.

Install (flash) onto a microSD card

Insert a microSD card via a card reader or SD adapter on your desktop machine. You can use one of several adapters or card readers.

Find out where the SD card is mounted:

$ diskutil list

Compare the media sizes to find the one that matches your microSD card. Be careful with this step! You don't want to choose the wrong drive and trash your computer hard drive!

Unmount the disk:

$ diskutil unmountDisk /dev/disk2

Write the Raspbian Jesse lite image onto the SD card:

$ sudo dd bs=1m if=./2016-05-27-raspbian-jessie-lite.img of=/dev/disk2

This is time consuming and may take 15 minutes to a half hour to complete.

Updating the disk image for networking over USB

Once the Operating System flash to SD is complete you'll need to update two files in order to enable networking over USB. The flashed Raspbian image contains a FAT disk partition containing boot files you can modify on your PC. In finder (on mac) locate the boot image and associated files:

You'll need to modify two files:

  • Edit config.txt by appending dtoverlay=dwc2 to the end of the file and saving it.
  • Edit cmdline.txt by inserting modules-load=dwc2,g_ether after rootwait. Make sure that the file only contains a single line with no newlines.

Once complete, eject the microSD card and prepare to insert it into your Pi Zero.

Connecting to your Pi Zero

Because the Pi Zero doesn't have built-in Ethernet or Wifi we need to connect it to a machine which can share its Internet access.

Laptop setup

The following instructions are Mac specific, however similar instructions can be found here for machines running Windows machines.

The first thing we need to do is setup "RNDIS/Ethernet Gadget" networking. So in the Preferences dialog select Network to bring up the Networking dialog. There are steps labelled a,b,c. First create a new network type (a). That will launch a list of interfaces, select the "RNDIS/Ethernet Gadget" option (b) and finally press the "Apply" button which should not be clickable.

Next we need to access the "sharing" dialog from the Preferences screen.

In the "sharing" dialog we first select "RNDIS/Ethernet Gadget" (step "a") and then select the "Internet sharing" option on the left side (step "b").

Boot time!

Now we're ready to boot our Pi Zero!

Insert the MicroSD card into your Pi Zero and attach a micro USB cable to your Pi and your PC. You'll want to connect to the center-most microUSB port. That will both power the Pi and allow us to access it via networking.

It can take up to a minute and a half to boot and be recognized as raspberrypi.local

$ ping raspberrypi.local
PING raspberrypi.local (192.168.2.18): 56 data bytes
64 bytes from 192.168.2.18: icmp_seq=0 ttl=64 time=0.365 ms
64 bytes from 192.168.2.18: icmp_seq=1 ttl=64 time=0.370 ms
64 bytes from 192.168.2.18: icmp_seq=2 ttl=64 time=0.566 ms
64 bytes from 192.168.2.18: icmp_seq=3 ttl=64 time=0.507 ms
^C

Once the entry resolves, you can ssh into the Pi using the default username pi and password raspberry.

$ ssh [email protected]
The authenticity of host 'raspberrypi.local (fe80::854b:2ab:d95f:6ff2%en7)' can't be established.
ECDSA key fingerprint is SHA256:dlH/03cQ77GcNYo6pygUl33GHp6698+c+wSlVKUuLBs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'raspberrypi.local,fe80::854b:2ab:d95f:6ff2%en7' (ECDSA) to the list of known hosts.
[email protected]'s password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pi@raspberrypi:~ $

You should now be able to access the Internet from within the Pi.

pi@raspberrypi:~ $ ping google.com
PING google.com (172.217.5.14) 56(84) bytes of data.
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=1 ttl=56 time=4.70 ms
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=2 ttl=56 time=9.80 ms
64 bytes from lga15s49-in-f14.1e100.net (172.217.5.14): icmp_seq=3 ttl=56 time=42.0 ms
^C

If this didn't work for you, make sure to check whether you've connect the microUSB cable to the center-most connection. Also review the steps above to ensure that you haven't missed a set. If it's still not working open up a github issue and describe what you're seeing.

Installing NodeJS on Raspberry Pi Zero

We're now ready to setup NodeJS!

The Pi Zero features an ArmV6 which means we have to download the correct precompiled version of Node.

Head over to the NodeJS download site.

You'll want to right click on the Linux Binaries "ARMv6" link and select "Copy Link Address". The link will be something like this: https://nodejs.org/dist/v6.9.1/node-v6.9.1-linux-armv6l.tar.xz

We'll use the link to download NodeJS from within the Pi Zero.

$ wget https://nodejs.org/dist/v6.9.1/node-v6.9.1-linux-armv6l.tar.xz

Now let's install it.

$ mkdir nodejs
$ cd nodejs/
$ mv ../node-v6.9.1-linux-armv6l.tar.xz .
$ tar -xvf node-v6.9.1-linux-armv6l.tar.xz
$ cd node-v6.9.1-linux-armv6l/
$ sudo cp ./bin/* /usr/local/bin

You should now have NodeJS installed!

$ cd ~
$ node --version
v6.9.1

Next steps

Now that you've configured your Pi Zero, learn how to control an LED light.