A robot rover using a PiZero – Part 3

Yorkshire versus Lancashire PiWars gets a step closer!

The next stage in making the robot rover I’m constructing (with massive help from the Cam Jam people and their EduKit3) is to incorporate ‘power on the move’ for the PiZero.

As you read before in A robot rover using a PiZero – Part 1 the two powered wheels use 4 x AA batteries. However no independent power source for the Pi is included with the kit. You therefore have to choose and buy the one that suits you. Because I am using a piZero rather than a full-sized Pi, I can get away with a lower power battery source (which adds less weight) than you would need for the full-sized Pi. I therefore chose a 2200 mAh (milli Amp hours) DC 5V portable powerbank. These are meant for powering smartphones on the move.  They are often called lipstick battery packs (because they’re like a large lipstick) and can be bought at high street discount stores.


I went to a trusted online Pi provider though, because I can’t afford to get it wrong and damage the rest of the set-up.  Also, the Pi provider’s powerbank came with the micro USB cable to charge it up with (and link it to the PiZero).


Anyway, the powerbank came immediately and, after a charge-up of about 4 hours (using the plug from my smartphone), its light went out to show it was fully charged and it is working brilliantly.  You just disconnect the cable and turn it around so the standard USB goes in the ‘OUTPUT’ on the powerbank and the micro USB goes into the Pi.

You can see my very rough video on YouTube here:Moving Robot

It cost £8.34 so I have now spent:

£48.64 + 4 AA batteries

on this project and I shouldn’t need to spend any more because the line following and the obstacle avoiding sensors are included in the kit.

The next job is to fit and code the ‘Line follower‘, so that the robot can follow a black line on a mat, and that will be in part 4.

Happy Raspberry Pi tinkering!

A robot rover using a PiZero – Part 2

Yorkshire versus Lancashire Pi Wars here we come! 

I’ve been working on getting my PiZero robot rover to start-up automatically when switching on the battery pack. Here are the instructions:


Get your robot running on start-up with a Raspberry Pi (I was using a PiZero)

Open the LXTerminal to amend the Cron table


sudo apt-get update


sudo apt-get install gnome-schedule

(I ignored some stuff that said I hadn’t got everything). When done type:

crontab -e

then choose the nano editor (usually no. 2)

and at the end of the document add:

@reboot python3 /home/pi/EduKitRobotics/4-driving.py

or your particular file (with path) instead of the part in red,

then choose Ctrl and X together, then (when you’re asked whether to save) Y and enter.

Then, when you reboot, your python code will start automatically. Shutdown and detach your robot from its monitor, etc.

Your robot will now start automatically when you attach a suitable power supply to your PiZero. (Don’t forget to switch on the battery that runs the wheels too!)

Getting Scratch2 for a Raspberry Pi3


Scratch2 is a great upgrade to the Scratch programming language, Scratch1.4, that comes with your Raspberry Pi. If you have an R Pi3 you can now get a Scratch2 offline version.

To upgrade your version of Raspbian, so you can use Scratch2 offline:

Open the LXTerminal (see What I wish I’d known about Raspberry Pi if you’re not sure what the LXTerminal is) and type:

sudo apt-get update

and press Enter.

Let this do everything until you get pi@raspberrypi:~ $ back.

Now type:

sudo apt-get upgrade

and press Enter.

Let this complete itself, as before, then type in:

sudo apt-get install scratch2

and when you look in the Programming menu Scratch 2 will be there!

Da, dah!

A robot rover using a PiZero – Part 1

PiWars is an event like Robot Wars, which you may have seen on TV, but without the destruction.  If you think that sounds boring you need to find out about the great courses the PiWars team put the robots through.  I particularly enjoyed the ‘balloon popping’ one.


After visiting PiWars, I decided I had to have a go at making a robot rover myself.  Not being that clever and allergic to soldering, I decided to buy a kit.  (Well not literally allergic but absolutely useless at it!)

Here are my costings:

This assumes you’ve got some sort of Raspberry Pi already. So you’ve got a power supply, keyboard, mouse, screen and powered USB hub – all with cables.

What you need                                               £

Pi Zero                                                                4.80

SD card with NOOBS                                       6.50

Adapter Kit                                                        4.20                     (Can be used for other projects)

This is:   {HDMI -> mini HDMI adapter

               {Female USB A -> micro-B USB cable

Hammer heading kit with Male Header     6.00    (Can be used again, new male header £2)

Robot CamJam EduKit #3                              18.00

Old Tupperware box                                        0.00                     (or the CamJam box or similar)

Total                   £40.30

I am pleased to say that the wheels turned when I tried it, so I must have done all the electronics correctly, and Michael & Tim’s instructions are excellent!  It’s the first time I’ve understood everything in a project’s materials.


Here’s the Python code I used (The indenting hasn’t come out here):

import RPi.GPIO as GPIO

import time

# Set the GPIO modes



# Set variables for GPIO pins

pinMotorAForwards = 9

pinMotorABackwards = 10

pinMotorBForwards = 7

pinMotorBBackwards = 8

# Set the GPIO Pin mode

GPIO.setup(pinMotorAForwards, GPIO.OUT)

GPIO.setup(pinMotorABackwards, GPIO.OUT)

GPIO.setup(pinMotorBForwards, GPIO.OUT)

GPIO.setup(pinMotorBBackwards, GPIO.OUT)

# Turn all motors off

def StopMotors():

GPIO.output(pinMotorAForwards, 0)

GPIO.output(pinMotorABackwards, 0)

GPIO.output(pinMotorBForwards, 0)

GPIO.output(pinMotorBBackwards, 0)

# Turn both motors forwards

def Forwards():

GPIO.output(pinMotorAForwards, 1)

GPIO.output(pinMotorABackwards, 0)

GPIO.output(pinMotorBForwards, 1)

GPIO.output(pinMotorBBackwards, 0)

# Turn both motors backwards

def Backwards():

GPIO.output(pinMotorAForwards, 0)

GPIO.output(pinMotorABackwards, 1)

GPIO.output(pinMotorBForwards, 0)

GPIO.output(pinMotorBBackwards, 1)







The only bit I was stuck on was finding instructions to start the code working automatically, once I’d separated the PiZero from it’s cables and switched on the battery box.  I expect you have to use some sudo commands in the LX Terminal.  Apparently I need to use this post: Raspberry Pi’s Linux Documentation which explains the correct commands to start up the PiZero and run my python code automatically.

Well, I feel I’ve made great progress today – so separating PiZero from it’s cables, and getting it to start the code (which moves the wheels) automatically, will be in Part 2.

Happy R Pi tinkering!


PS You can now buy PiZeros, with the male header already soldered on, from Pi-Supply .

York Raspberry Jam – our 2nd

York W Raspberry Jam No. 2 will be held on Monday 24th April from 5.15 to 7.15 pm.


The session will be suitable for complete beginners but I’ll be providing new materials for those who’ve been before.

I’m thinking that some attendees might like to look at ‘Lists’. These are a way, in Scratch, of making a very basic database, e.g. of your CD/music download collection.

I’ll bring some BBC micro:bits too – and we can have a try at coding them. We’ll use a form of the Python programming language called Micro Python or Mu Python.

Look forward to seeing you there!


York W Raspberry Jam

The aim of this first Raspberry Jam was to get beginners coding.


These two were animating a cat and dog and learnt how to resize and move their cat and dog sprites- getting their sprites to turn around at the edge of the screen. They also worked out the basic control blocks you need to make your code work.

Some attendees had some prior learning so borrowed MagPi’s ‘Learn to code with Scratch’ book: https://www.raspberrypi.org/magpi/issues/essentials-scratch-v1/


and used it to go further into Scratch.  A variation of the Boat Race game, which is explained in the book, resulted in a maze game that we enjoyed.

Boat Race game


Next time we need to get involved in physical computing, perhaps, using BBC micro:bits or the Pibrella. However I’m looking forward to seeing some more complete beginners because the more adults and children who know what coding is all about, the better!