Saturday, 9 January 2016

Size Zero Pi




Bare Raspberry Pi Zero

Going Zero

I'm a happy Raspberry Pi 2 owner, but the size of the Pi 2 always means it trails patch, jumper or ribbon leads to external electronics.

The Zero is small enough to be embedded away and can be the beating heart of an electronics project. The price also means that it's not too bad if it becomes a permanent feature with solder, glue and screws. 

What's in the Package?

I still have to put it though its paces to see what it can do but the specs are more than good enough to do the job of the original Pi A. The Zero comes with a Broadcom BCM2835 running a single core up to 1GHz and 512MB of memory. There's no network port and in reality there's just the one USB port for connecting devices as the other is for powering the Zero. 

The USB is an On-The-Go (OTG) port which means it can be a gadget or host connected gadgets. I'll be playing around with this feature in the future. 

HDMI is still on board and this allows the Zero to work like the rest of the Pi range, allowing it to hook straight up to a display in no time and get results. 

Zero Connection

You will need some adapters for the zero unless you have micro USB input devices and mini HDMI display devices. Adapters can be found online. I sourced mine from The Pi Hut which also came with the header pins.

SD Card Setup

First things first is the SD card with the latest Jessie image. I went with the lite image since an X-Windows server isn't needed for the projects I have in mind. You can also go for NOOBs if you want to try out other images and have a recovery tool. 

The following steps are for Windows which I used in my setup.

Whilst you are downloading the image you can also get hold of SDFormatter V4.0 to prepare the SD card. I have had a few problems in the past getting images to work but these steps seem to work every time for me.

1. Enable Full Format and Size Adjustment to On
2. Ensure that the drive letter correctly matches your SD card!
3. Double check the drive letter!
4. Press format and wait for it to complete

Quick format may also do the job but if you can't get it working with that option try the Full Overwrite. 

Extract the IMG file from the ZIP. In theory the zip can be used, but again this is the formula that seems to work.

Fedora ARM image installer works to get the image correctly written to the card. Download and install. Run the application (it may need administration permissions to run).  
1. Select image from your hard drive (select the IMG file)
2. Check the destination drive and double check it really is your SD card
3. Press Install

Eject the SD card from the task bar. This ensures the image data is fully written and not corrupted when you pull out the SD card. 

So now your Zero has an operating system to get it running.

Hooking Up To Keyboard and Monitor

Plug in the newly created SD card into the SD card slot. A USB keyboard or USB wireless dongle can be used. I'm using a wireless Logitech to avoid long leads. 

Use the adapter for the HDMI to connect up to your monitor. You may want to support the mini HDMI socket as the adapter can need a bit of wiggling to slot in.

Add power from a micro USB wall adapter. Depending on the type of USB devices you want to plug into the Zero you will need a wall power adapter which can provide the correct power. I'm reusing the 2A power supply used by the Pi 2 in my setup and this is more than enough.

Power Up

Turn on the power and the Zero should indicate with a flashing light that it's working. 

All being well the Zero should output to the monitor with output from Jessie.

This is the most basic setup you can have for the Zero. From here you can login:
User: pi
Pass: raspberry

From the login prompt run
> sudo raspi-config

This should open up a menu. Select the first option to Expand the file system. This will then prompt you to restart to complete. 









The next section discusses how to drop the need for keyboard and monitor and use remote connections to manage the Pi Zero.

Zero HDMI & Keyboard

With a monitor and keyboard attached all the extra wires seem to miss the point of having the Zero Pi in the first place.

The following steps take away the HDMI connection and replace with a remote SSH over wireless. 

To do this a hub is required because only one USB device can be attached and you will need a keyboard and wireless USB device. Once complete the hub isn't required so it's only temporary for the setup.


Enable SSH

Start up the Zero again and login. Run raspi-config as before.

From the initial menu go to 9. Advanced Options. This will take you to another menu
Select the option to enable SSH. Restart to enable.

To shutdown from the command prompt you can type:
> sudo shutdown -h now

Plug the Pi Zero back in to restart. 

Configure Wireless

This is a little trickier using the command line and should be done after restarting following enabling SSH. 

From the command line run:
> sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

This will open the editor. Scroll to the bottom of the file and add the following

network={
    ssid="Your wireless SSID"
    psk="Your_wifi_password"
}

Replace the text in quotes with your network SSID and your password. 

Save the file (Ctrl-X and press y to save when prompted). In theory the wireless should connect but I found it required some additional work. 

Take down the interface from the command prompt:
> sudo ifdown wlan0

Then bring it back up with:
> sudo ifup wlan0

Wait a while for the DHCP to configure an address and run
> ifconfig

You should see wlan0 configured with a valid IP address. It may be slow so keep trying until you see an address. Check your wireless router if it's not providing an address. Alternatively run 
> dmesg

and see if there's any errors enabling your wireless USB device. 

One final step to prevent the need to guess or require the HDMI to check IP every time is to 
1. Assign a permanent IP to the MAC address for the wireless dongle
2. Disable DHCP and set a fixed IP for the wireless LAN connection

Item 1. depends on your wireless router config. Consult documentation for how to do this.
Item 2. requires some more configuration which is well documented from the Pi Hut website

Going Headless


Linux and Mac

Once the wireless is working test out the SSH connection. SSH packages can be installed to the command prompt for Linux fairly easily and are likely to be enabled in most distributions. Macs also come with SSH that can be run from the terminal. Execute something like
> SSH pi@192.168.0.101

Replace the IP with the address given to your Zero.

Windows

Windows OS users can use PuTTY to access the Pi Zero. 

PuTTY doesn't even need a formal install to run. Just run the binary and the interface will work. 

You will need to know the IP address to login. Username and password will be prompted after selecting Open and a successful connection has been made. 

Removing the hub

Once the connection has been verified issue a shutdown with
> sudo shutdown -h now

Wait for the LED on the Zero to turn off and it's shutdown.
Unplug the HDMI and USB hub. Plug the wireless dongle back in and power the Pi Zero back up.

Try the SSH connection again after the Zero has had time to complete the boot sequence. 








No comments:

Post a Comment