Tiny 4WD robot

IMG_20170411_184928502_HDR

I was lucky enough to win a Tiny 4WD robot on Pimoroni’s BilgeTank last week, and had great fun putting it together and putting it through its paces over the last couple of days. I thought I’d do a bit of a summary here that might help others putting theirs together.

In particular, I wanted to talk about the breadboard and how to use it, but also some other little tips. The web-based instructions refer to build instructions that appeared in the MagPi (or at least they do at the time of writing this post), but those instructions assume a PiBorg motor controller, whereas the kit comes with an explorer pHAT, and there are other differences too…

First thing to note is that you don’t need to prepare the motors – the board in the kit is slightly modified from the one in the magazine, so the bent pins have a slot to poke through. So the first step is to attach the motors – probably the most fiddly job, and much easier if you have an assistant with small fingers as I did; those nuts and bolts are small!

Next, attach wires to the motors, by getting a pair of jumpers for each and slotting the female end onto the pins of each motor, and attach wheels to the motors (they just slide on, if you get the flat side of the shaft lined up properly).

Now put the base aside for a bit while you put the top together.

I conveniently had a spare zero w and explorer pHAT lying about, so I didn’t need to do any soldering, but if you don’t, you’ll need to solder the headers onto your pi zero and explore pHAT at this stage (or use hammer headers). Remember, the kit doesn’t include a pi, so if you don’t already have one you will need to order one at the same time as the kit!

Also not included in the kit are spacers for attaching the pi and pHAT. I had some spare ones, so that was fine, but you might want to consider purchasing at least some for the pi (that pHAT doesn’t really need them). M2.5 works best, though I made do with M3.

Using the ZeroBorg, as the MagPi instructions do, you put the motor controller on the bottom and the pi on the top, but with the explorer pHAT, it’s the other way around. Then attach the pi zero to the top plate using the appropriate holes. (Actually, probably easier to attach the pi zero to the top plate then put the pHAT on!)

Next, grab your breadboard. My kit came with a blue one – I’m not sure if this is standard – but I felt a black one to match the chassis would be more appropriate, so I made use of a handy spare that I had lying about. If you’ve never used breadboards before, there is a great page over at SparkFun, so I won’t go into great detail here, but what I will do is go through the wiring using a spare white breadboard that I have to make it more clear, as you can see in this photo that the black is a bit hard to distinguish in the photo:

IMG_20170413_143337693

So… start with plugging in the male-male jumpers into the +/- pins of the two motors on the explorer pHAT. Everything will be much neater if you don’t separate the wires, but it will still work if you do. It’s probably a good idea to attach the breadboard to your chassis at this point (it has self-adhesive backing). Then plug the other end of these jumpers from the motor drives into slots on the breadboard. They have to go in to separate rows – each row has five holes (“tie points”), and there are two columns of 17 rows each. The idea here is that anything plugged into tie points on the same row will be wired together. So they need to be in separate rows, but so long as they are each in different ones, it doesn’t matter which ones. It’s probably easiest to keep them all adjacent, in line with the motor pins on the pHAT though, like this:

IMG_20170413_143447381

Now, the whole reason that we need the breadboard is that we have four motors but only two motor controllers. One motor controller will be used to drive both left motors, and the other to drive both right motors. So first, find two sets of jumpers from the wheels on one side, and slot them in to tie points corresponding to a single motor controller, like so:

IMG_20170413_143612091

It doesn’t matter which of the tie points the pins go into, so long as for each motor, one pin goes into a tie point in the same row as controller +, and the other pin goes into one in the same row as controller -.

Then do the same for the motors from the other side of the robot, and the other controller:

You can see here that I’ve used adjacent rows for all the pins, but not adjacent tie points within the rows. Actually on my robot I do use adjacent tie points, to keep it neater; I just spaced them out here for clarity. The point is that it does matter which row you put the pins in, but it doesn’t matter which tie point within the row. Note that you may need to do some adjustment of these pins once you have code running on your robot, as I will explain below.

If you’re going to use a camera, you’ll want to attach it now, but I didn’t use one. Then it’s time to put the final bits together. This is simply a matter of using the provided spacers to   attach top to bottom, with the camera plate as well on the front ones. (I attached this plate despite not using a camera; I like the look.) You need a power supply too. I had a handy little lipstick-sized power bank but unfortunately it was slightly too big to fit between the body plates… so I added some extra spaces to enlarge the gap slightly. Now ready to rock and roll… almost!

IMG_20170413_143317085

Now we need to drive it. First things first, you need the explorer pHAT library. The easiest way to do that is through the Pimoroni dashboard. What’s that? Well, to install it on your pi, use

sudo apt-get install pimoroni

Once installed, run

pimoroni-dashboard

and use the menu-driven system to install the explorer pHAT library. That will also install examples in the Pimoroni/explorerhat/examples/ directory, and once that’s done, it’s a good idea to hold your robot off the ground and run test.py. Why hold it off the ground? Well, the main reason for doing this is to check that all the motors are turning in the same direction. If they are not all running forwards, identify the cables associated with the rogue motor(s), turn off the pi and switch the +/- connections. (That is, take that pair of pins out of their current tie slots, and reinsert them the other way round.) Then run the test again to make sure (and keep repeating until you get it right).

Brian Corteil has provided code on GitHub that works with the RockCandy PS3 controller, but unfortunately the RockCandy controller I ordered had to be sent back as it was faulty. So instead I used a genuine PS3 controller, modifying Brian’s code to make use of the approxeng.inputs library. If you’d like a copy of my very basic code, you can grab it here. (You’ll need to install the approxeng.inputs libraries before you can use it – see https://approxeng.github.io/approxeng.input/index.html – these excellent libraries support other controller types too, so if you have something else, see if it’s supported.)

Hope you have as much fun with your tiny robot as we are!

 

Addendum: Don’t get my very basic code, go instead for the greatly enhanced code at https://approxeng.github.io/approxeng.input/examples/tiny4wd.html by Tom Oinn. This works with a whole range of controllers, including both the genuine PS3 controller I started with, and the rock candy controller I ended up buying. (You might spot evidence of it in the picture below. I need the genuine PS3 for another robot!)

In the end I wanted a more sleek tiny, so I got rid of the breadboard and spliced my motor wires instead, also removing the breakout header for my explorer hat. Now it looks like this:

IMG_20170505_182706230

And here are the guts:

IMG_20170505_192800242.jpg

Advertisements

4 thoughts on “Tiny 4WD robot

Add yours

  1. Thank you for posting this! The pimoroni kit comes with a LiPo shim to connect the battery and provide power. How do you connect the Pi Zero, LiPo Shim and Explorer PHat? Do you add a male header to the PiZero, then slide the LiPo shim on the 1st six prongs and then slide the Explorer PHat on the 40 prongs of the header and the power is then provided to the Pi Zero and Explorer PHat?

    Like

    1. Ugh sorry, somehow I missed your query! I’m sure you’ve solved it by now, but feel I should respond in case anyone else has the same question.
      The version I got didn’t come with the LiPo shim (and I just used a lipstick battery bank), however I’ve used one in other contexts. In these cases, I’ve added the header to the pi zero, then soldered the shim onto the first six prongs, then added the pHAT on top of that. The pHAT doesn’t sit quite so neatly (how much depends on your soldering skill), but it will work this way.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: