Building the Tiny 4WD

This tutorial will guide you through how to build the Tiny 4WD in the basic configuration, and allow you to control it remotely using a choice of controllers (available separately).

Picture of a Tiny 4WD

The Tiny 4WD is a little drive-able robot kit designed by Brian Corteil and produced by Pimoroni. It uses the Explorer pHat to drive four motors, and the in-built Bluetooth on the Pi Zero W to connect to a controller wirelessly. There is some soldering involved for the Explorer pHAT headers, and to put a header onto your Pi Zero W if you haven't already done it. We have some really good guides on soldering which you can find here.

If you get stuck on any bits you can use our forums to get some more help.

Soldering the headers

pieces laid out

The first thing to do is solder the headers to the Explorer pHAT. There is a 2x20 female header to solder above the word "explorer" to connect it to the Pi, and a 1x20 female header to solder on top of the pHAT so that you have something to plug your connections in to. The following photos show the headers soldered on to the correct places.

explorer pHAT explorer pHAT

Connecting the motors

Set the Pi Zero W and the Explorer pHAT to one side for now, and pick up the longer set of jumper jerky wires, the motors, and the black piece of Perspex with lots of square holes in. Pull two wires away from the jerky so you are left with eight joined together. Separate the bottom half of the jerky into pairs of wires as shown in the photo. Each pair of wires will connect to a motor shortly. Poke a pair of wires through the square holes, at the top of each pair on one side, and the bottom of each pair on the other side. This is important because the connectors on the motors hang to one side.

Separated wires

Wires through base

Wires on an individual motor

Push one pair of wires onto each motor. You should be able to tuck the wires back through the square holes so that the motors lie flat against the plastic. Now, find the black motor mounts and the small metal screws and nuts.

Motor mounts

Sit a metal nut in each "leg" of the motor mount. It should fit snugly.

Metal nuts in right place

Place the motor mount over the first motor, and use the screws to push up through the plastic, through the metal nut, and out the top. Repeat for the other side of the mount, and then repeat for each motor until they are all screwed onto the plastic base. The side with the motors on is the underneath of the car.

Fitted motor mount

All four mounts on

Building the bodywork

The next things you will need are the metal spacers and the short plastic screws that fit into them. With the motors facing down, attach one of the spacers to each corner of the plastic base, and then two in the centre of the sides, as shown.

Spacers at the ready

All spacers on

Now, take the top piece and make sure it's the right way around. One end of the base has more holes on - this is where you can add the camera mount, if you want it. Make sure it's on the same end as the top where you attach the Pi Zero W and pHAT. DO NOT ATTACH IT TO THE BASE... yet.

Top and base

Showing where the pi will go

Attaching the Pi Zero W and Explorer pHAT

Take the long small white screws and use them to attach the Pi Zero W to the top layer. Between the Pi Zero W and the top layer, you need to put the small white beads. This is so that you can attach wires later without other parts being in the way.

Bead spacers

Fitted spacers

Push the Explorer pHAT onto the pins of the Pi Zero W.

Now take the remaining six short small white plastic screws and use them to attach the top to the base, as shown. (Please ignore the black screws holding the Zero down in this picture - yours will be white and have spacers!) Make sure you poke the group of motor wires through the hole in the top as shown.

Top now attached

Wiring the motors

You will notice that there are eight wires coming from the motors and only four spaces on the Explorer pHAT for motors.

Eight wires, four spaces

We can use the breadboard to make the connections from the Explorer pHAT to the motors. Take the shorter bunch of jumper jerky and pull off a strip of four wires.

Four new wires

Plug the wires into the motor connections on the Explorer pHAT.

Plug 4 wires into the motor connections

A breadboard is a series of long metal clips with gaps to push wires into them. It allows you to connect wires without soldering, and makes it easy to change them around. You don't need to peel the back off, I've just done it here so that you can see the clips. DO NOT STICK YOUR BREADBOARD DOWN YET!

What's in a breadboard?

Push each of the four wires into a separate row on the breadboard, as shown.

Motor wires to breadboard

Now look back at your motor wires. Gently separate each motor pair. Each pair is going to need a positive and a negative connection. In this photo, the red wire is coming from the motor 1 positive connection, orange from the motor 1 negative connection, yellow from the motor 2 positive connection, and green from the motor 2 negative connection. Lets focus on the motor 1 connections (the red and orange wires in the breadboard). We want the wheels on one side of the car to be connected to these.

Look inside the layers of your car at the wires. Connect one wire from each pair from one side to motor 1 positive (red on mine), and the other wire from each pair to motor 1 negative (orange on mine).

Do the same for motor 2 positive (one wire from each pair on the OPPOSITE side) and motor 2 negative (the remaining wire from each pair).

Completed breadboard wiring

STILL DON'T STICK YOUR BREADBOARD DOWN! It will get in the way.

One more thing in the physical build of the robot... the wheels!

Note the notches

The wheel centres have a little flat side to them, and so do the axles of the motors. These match up. You shouldn't have to force the wheels on.

Push the wheels on

Push them on gently with your thumb behind the motor, supporting it so you don't damage it. Repeat for all of the wheels.

Four wheels on my wagon

Installing the software

Setting the software up

It's probably easiest to start with a NOOBS install for your Pi Zero W. Make sure you are connected to the internet so you can download the code you need. Open a Terminal window (the black and blue icon on the top toolbar) and type:

curl https://get.pimoroni.com/explorerhat | bash

And answer Y (yes) to any prompts. When it's finished it will print All done. Enjoy your Explorer HAT/pHAT! on the screen and you are ready for the next step. If it didn't work, and said 404 not found, it might be that you've typed explorerphat, not explorerhat. The pHAT may be the smaller version, but it uses the same code as the big version.

Next, you need to install the Python inputs library so the robot can recognise your inputs. Still in the Terminal window, you need to type:

sudo pip install inputs

This might sit and look blank for a minute or so, but it's doing something, honest! When it gives you your green and blue prompt again, there is one more thing. You've installed the Explorer pHAT, you've got the inputs library, so now you need to use both of these things together to drive all of your motors:

wget https://raw.githubusercontent.com/Coretec-Robotics/Tiny_4wd/master/TinyPirate.py

So now we have software to do everything with most controllers.

Running the robot

While the Pi is still connected to your keyboard and screen, you can test if the robot works. You need to plug the dongle that came with your Bluetooth gamepad into the Pi Zero W, and make sure the gamepad is switched on.

In the Terminal type:

python TinyPirate.py

Now, hold the robot off the table and push the joystick forwards. When I did this, two wheels were turning forwards, and two were going backwards. Look at the coloured wires that join to the motors going the wrong way. My yellow and orange motor was going backwards, so I needed to swap the places of those two wires so they were the opposite way round. The easiest way to do this is in the breadboard. I also needed to swap my black and white wires, so the white plugged in where the black wire was, and the black wire plugged in where the white wire was.

Try making it go forwards again, and this time it should work. Once you have forwards nailed, you have backwards sorted too.

Running the program automatically

If you want to drive your robot around, you don't want it connected to a keyboard, etc! You need to put an instruction into the startup file so the Pi starts running the robot when it's plugged in.

In the terminal, type:

crontab -e

which will open a little menu. Press 2. Use the arrow keys to scroll down to the bottom of the hashes (it probably says something like m h dom mon dow command). On a new line, type this exactly:

@reboot python /home/Pi/TinyPirate.py &

Then press CTRL and x, then y, then Enter.

You have now saved the instructions. Now you just have to shutdown the Pi, unplug all the peripherals (except the controller dongle, that one's important) and then you can run your robot from a power-bank if you want to drive it round without any wires.

Also, NOW is the time to stick the breadboard down to the car!

Happy driving!

Shopping basket

Need something for this project? You can use the links below to add products to your Pimoroni Shop basket for easy checkout.

Raspberry Pi Zero W
Zero W only £9.60
Raspberry Pi Zero W
Zero W + Adaptors £14.00
Raspberry Pi Zero W
Zero W + Adaptors + Pibow Zero W £19.00
Pi Zero W Starter Kit
£35.00
Official Raspberry Pi Universal Power Supply
£8.00
Coretec 'Tiny 4WD' Robot Rover
£55.00
NOOBS 16GB microSD card (2.4.3)
£9.00
Want to checkout or change something? Click here to view your cart.

Tutorial
Beginner
Raspberry Pi, Pi Zero

Tanya Fish

tanya@pimoroni.com
@tanurai
http://tanyafishmakes.wordpress.com
Formerly, Tanya worked in various Sheffield schools, teaching maths and physics and shouting loudly at paperwork. Now a crew member at Pimoroni - working on learning materials for schools, workshops, and lasering anything she can get her hands on. Gets very giddy at most things STEAM.