Raspberry Pi Zero - Getting Started

From ProjectPages
Jump to: navigation, search

Headless Raspberry Pi Zero setup in twenty minutes

This guide will get the Rasbian operating system running on your Raspberry Pi Zero in less than twenty minutes. It requires no monitor, keyboard or mouse. You just need power for the Pi and, unless it is a Pi Zero W, an approved Wi-Fi adapter. You will also need a Windows PC or Laptop with an SD Card reader / writer and a minimum 8 GByte micro SD Card.

Preparation

1. Download the Raspbian image from here. I generally use the Raspbian Stretch Lite image as I don't use the desktop GUI. If you want to be able to plug in a monitor and use the desktop then download the Raspbian Stretch with desktop image. There is no need to unzip the image.


2. Make a file wpa_supplicant.conf. Edit the value for ssid and psk to be your wifi ssid and password.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid='yourssid'
    psk='yourpassword'
    scan_ssid=1
}


3. Create an empty file called ssh. This is because, for security reasons, Raspbian does not enable SSH by default. If it finds an empty file called SSH in the right folder, this will enable SSH.

You should now have a folder that contains these three items.

Source Folder

This folder can now be used to set up as many Pi Zeroes as you like.

4. Download Etcher for windows from here. Install the file.

Starting up

START THE CLOCK - you should have logged into your fresh operating system within twenty minutes from now!!

1. Insert the SD Card in your windows PC. You will probably need a full size adapter for the micro SD Card.

IMPORTANT: Click cancel on any windows prompt that advises you to format the SD Card.

2. Run the Etcher program.

You should see a screen that looks like the image below. In the centre, you should be able to see that Etcher has discovered your SD Card. If it hasn't, try removing and re-inserting your card.

Title

Click on Select Image and select the zip image you downloaded in the Preparations above.

Etcher2.png

If your screen now looks like the screen below, all you need to do now is click Flash!

Etcher3.png

The first stage is flashing the SD card.

Etcher4.png

The second stage verifies that the contents are all good

Etcher5.png

Now, remove the SD card from the reader / writer and re-insert it.

IMPORTANT: Click cancel on any windows prompt that advises you to format the SD Card.

Navigate to This PC and you should see your SD card with a partition called boot.

Boot.png

Windows can't see the partition that holds your operating system, but, fortunately, Raspbian will copy files from boot into the OS partition. So, copy the two files you made earlier, ssh and wpa_supplicant.conf, into the boot partition.

Now, eject the SD card to ensure Windows has finished writing. Insert the card into the Raspberry Pi, apply power and fingers crossed!

Wait a couple of minutes - no more. The clock is ticking!

Open up the admin page on your router and list the clients. If all is well you will see something like this.

Router.png

Congratulations, if you are here your Pi is connected to your Wi-Fi. You can now connect with SSH

I use Putty on a windows desktop

PuTTY

Click Open and the PuTTY window opens up

PuTTY Terminal

Log in with a user name of pi and the default password of raspberry

You may get a security notice like this. Just click yes and carry on

Security Notice

If you can see a screen like the one below, STOP THE CLOCK! You should be inside the twenty minute mark. If not, I guarantee you will be next time. Just remember, you don't have to repeat the preparation section next time.

Logged In

Make sure you take the advice about changing from the default password!

Setting Up

I like to set my Pis up using the following steps.

These commands will make sure you have the latest version of OS and firmware.

sudo apt-get update && sudo apt-get dist-upgrade -y

Set up some bits.

sudo raspi-config

I like to change the hostname to something relevant to the use of the Pi, and also set the timezone.

You will need a re-boot after this process

sudo reboot

Setting Up File Sharing

Now I install samba so that I can access the Raspberry Pi folders from my PC

$ sudo apt-get install samba -y

Next edit the smb.conf file

$ sudo nano /etc/samba/smb.conf


Change these lines

workgroup = your_workgroup_name
wins support = yes

Make sure you remove the # from in front of wins support = yes because that comments it out.

Add these lines to the end

[pihome]
   comment= Pi Home
   path=/home/pi
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no
[tmp]
   comment= Tmp
   path=/tmp
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no
[etc]
   comment= Etc
   path=/etc
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no
[var]
   comment= var
   path=/var
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no
[lib]
   comment= lib
   path=/lib
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no

[usr]
   comment= usr
   path=/usr
   browseable=Yes
   writeable=Yes
   only guest=no
   create mask=0777
   directory mask=0777
   public=no


Ctrl-x to save this and enter this line and set the password. You have to enter the password twice.

$ sudo smbpasswd -a pi


Restart the Samba service

$ sudo /etc/init.d/smbd restart

You should now be able to browse to your Pi from windows and see the folders

Clock folders.png

I like to create a folder called python in the pihome folder for all my Python projects.

Links

Free Space on Your Raspberry Pi SD Card