Sunday, 19 March 2017

Getting Started with the Raspberry Pi Zero

The Raspberry Pi zero is a great low cost bare bones board. Costing only £4 (GBP) it is incredible value. A complete computer for just £4? Well not quite, as you really do just get a bare bones board.


It can be a bit of a challenge to work out just how to get started with one of these for the first time. Here we will look at what you need to actually get up and running, and the steps I took with my first Pi zero to get it booted up and connected to to internet in order to use it in our first robot. You need a few additional items to get one of these boards up and running.

First, the computer needs some sort of data storage to read and write files from, and to hold the operating system (OS). These boards use a micro SD card for this purpose. You need at least 8GB of space to install the Raspbian OS. If you need more space to hold lots of files (maybe video files recorded on a Pi camera?) then you might decide to use a larger card.

In order to power the computer, you need some sort of power supply. The Pi Zero will run off the USB chargers which come with most tablets (chargers which can output 2A). Smaller phone chargers may not be able to provide enough power for the board to run reliably. If you don't already have a suitable charger then you can buy a power supply specifically for the Raspberry Pi, or if you are looking to built a robot which is not connected by wires at all then a USB charger battery can be used.

You will need to be able to see the computer output on a screen. To get started, this is most easily done using an HDMI cable to connect it to a TV or computer monitor which has an HDMI input. But you also need an adaptor to connect the HDMI cable to the mini HDMI port on the Pi Zero. Later this can be replaced with a remote computer connecting over a wireless network, but we need to set that up first, so a screen connected directly to the Pi using a cable is needed initially.

You need a keyboard to send commands to the Pi too. This should be a USB keyboard, but you also need another adaptor to enable you to plug the USB keyboard into the micro USB port on the Pi Zero board. If you are using the graphical desktop in the full Raspbian OS then you'll also need a USB mouse. The Pi Zero only has one USB port, so you will need a USB hub of some sort to plug in both the keyboard and the mouse. In my case I had a USB keyboard which had a built-in hub, so I could plug the keyboard into the Pi (via an adaptor cable) and plug the mouse into the USB port on the keyboard.

Finally, in order to connect to your Pi over a wireless network, you will need a USB WiFi dongle. You don't need to plug this in just yet though.

Optional, but recommended is a case for the Pi. Otherwise you have to be careful with a powered on bare circuit board as any contact with metal objects could cause a short circuit and damage it. You can see my assembled set up below (apart from the screen which the other end of the HDMI cable would plug into).


Before you can boot up the Pi Zero you will need to install an OS on the SD card. For our robot we used Raspbian Jessie Lite. You can buy micro SD cards with NOOBS pre-installed if you want to be guided through the OS set up. Or you can save a small amount of money by purchasing a cheap micro SD card (I would recommend getting at least a class 10 card or reading and writing from it will be a little slow). Next download a Raspbian image from the Raspbian website and write the image to the SD card on a computer using an imaging program (I used Win32 Disk Imager on a Windows 10 laptop to do this). Once you have an OS image written to the SD card you can connect everything up and power on the Pi Zero for the first time.

Note that the WiFi dongle is not connected yet. I tried plugging mine into the spare USB port on my keyboard, but the port did not supply enough power and the dongle was not visible to the Pi. However, once we have got the Pi zero booted up and configured to connect to our Wireless network we can shut it down, unplug the keyboard and plug in the USB dongle instead. Then when we boot it up and it has connected to the network, we can connect to it from a laptop to control it. From this point in time we no longer need a keyboard (or a screen) connected to the Pi. See the link at the end of this article for how to configure the Pi Zero to connect to your WiFi network.

If you plan to connect any add-on boards or other electronics to the Pi, then you will also need to solder a 40 pin header onto the Pi Zero board. The full size Raspberry Pi boards come with these already attached.

Below you can see all these essential components laid out with the bare Pi Zero board. In this case a small adaptor shim is shown instead of the micro USB to full size USB adaptor cable. It does the same job as the cable but is much smaller. Most importantly, it must be inserted into the larger USB plug the right way up or you will short circuit the power on your Pi Zero board!


Most of these items can be purchased along with the Pi Zero as an 'essentials' kit from the Pi suppliers. If you are not sure where to buy all the things you might need for your Pi adventures, then take a look at the links page where I maintain links to the websites for anything I have found useful for my adventures with the Pi.

Once everything is up and running, the bare bones Pi Zero only needs the USB wireless dongle and a power supply connected. If something goes wrong with the configuration then having a screen connected is a great help though. Here is my Pi Zero with the header soldered on, the SD card inserted and the whole thing protected with a Pibow Zero case from Pimoroni. The USB WiFi dongle is connected using a shim adaptor. The HDMI adaptor is still connected in case I need to connect a screen, but once it is all working that could also be removed.


In the next article we will walk through how to configure Raspbian to get the Pi Zero connected to the internet over the wireless network, and connect to it remotely from a laptop.

Sunday, 5 March 2017

How it All Began

Back in November 2016 I came across an article in Computer Shopper Magazine on how to build your own robot. That sounded like a fun project for me, and also a way to engage with my children on electronics, computers and coding. I had already introduced the kids to coding through the excellent code.org website and their 'Hour of Code' tutorials, and this looked like a great project to tackle with them next. So that was how I was introduced to the Raspberry Pi.

The article was based around the CamJam Edukit #3: Robotics. The parts cost in the article was around £70 (UK Pounds Sterling), but when I looked at what was needed I discovered you could get a Raspberry Pi Zero for just £4 rather than buying the Pi model 3 for around £30. This had the advantage that the robot would not draw as much power from the battery, but meant that some soldering would be required (the CamJam kit used with any of the full size Raspberry Pi models does not require any soldering to build). Doing a bit of soldering was not a problem for me, as I already build electronics as a hobby. So I managed to put together everything I needed for around £56. I already had AA batteries, a soldering iron and tools, and HDMI cable and micro USB lead and charger from various phone and tablet devices.

Here is the robot after my first session assembling it with the kids:

Friday, 3 March 2017

Links scratchpad

This is where I am collecting notes and links to resources which I plan to follow up as I explore new ideas and hardware I have ordered. As I make use of these items I will post about these adventures and move the resource links into their own posts.

Suppliers of Raspberry Pi's and hardware to use with them:
Pimoroni: http://shop.pimoroni.com/
The Pi Hut: https://thepihut.com/

Other suppliers I have come across but not used yet:
https://www.modmypi.com/

Books I am learning from:
The Python Apprentice: https://leanpub.com/python-apprentice
Raspberry Pi Cookbook for Python Programmers


LCD Display driving: http://www.raspberrypi-spy.co.uk/2012/07/16x2-lcd-module-control-using-python/

Using the I2C interface: http://www.raspberry-projects.com/pi/programming-in-python/i2c-programming-in-python/using-the-i2c-interface-2

Pinouts for all the HATs I have bought: https://pinout.xyz/

Information on what HATs can be used together can be found on the Pimoroni Forums:
http://forums.pimoroni.com/t/stacking-different-hat-or-phats-on-same-unit/3393


Ideas and Information on Pi Robots
https://www.piborg.org/ 

Learning Resources
https://coderdojo.com/resources/

Pi Camera Live Streaming
http://picamera.readthedocs.io/en/release-1.10/recipes2.html#rapid-capture-and-streaming