Categories
Geekery Raspberry Pi

Controlling Lego motors with the Ryanteck Raspberry Pi board

I’ve reviewed a few Raspberry Pi add on boards before, including the PiFace which includes a multitude of inputs and outputs, and the minimalistic LEDborg which has a very bright single multicoloured LED.

The Ryanteck Raspberry Pi Motor Controller Board Kit is a GPIO add on board that allows you to control 2 motors with your Raspberry Pi. Although it’s much simpler than the PiFace it’s cheaper (about £12) and is easy enough to assemble yourself. In fact it makes a nice introduction to soldering, and is an ideal project if you want to take the plunge and have a go at making your own hardware.

With the motor controller board you can build a simple Raspberry Pi based rover – you just need 2 motors driving side by side sets of wheels or tracks. Driving the motors in opposite directions allows you to turn on the spot. The Ryanteck board can control motors up to 12 volts to you could always re-purpose a toy or build your own.

There’s some documentation available here, but I thought I’d share my build guide. If you’ve never soldered before check out the Soldering is Easy guide, and try to buy some leaded cored solder. Lead has (quite rightly) been removed from the solder used in commercial products to prevent it ending up in landfill when electronics are thrown away. However lead-free solder is much harder to work with (it’s fine if you’re a robot) and for hobbyist applications it’s easier to work with the leaded variety. Just make sure you don’t throw your electronics projects away once you’ve finished with them.

Build guide

In the kit are 3 sets of 2 pin headers, 3 sets of blue terminal blocks, a GPIO connector pin header and a chip carrier and controller chip.

Don't panic.
Don’t panic.

 

Holding everything in place when you’re soldering is tricky – so my tip here is to use the GPIO header block to hold the parts in place while you solder them. So first we have the set of 3 2 pin headers:

The spacing is just right!
The spacing is just right!

Next we’ll solder the chip holder into place, using the GPIO header plugged into one of the sets of 2 pin headers – orientate the cut out to the left hand side of the board:

Chip holder next, held in place with the GPIO header
Chip holder next, held in place with the GPIO header

Next comes the blue terminal pins. These are a tighter fit so easier to just rest the board on the blocks and solder away. Finally comes the GPIO header. Remember to solder this facing down – you’ll need something to rest the board on. Fortunately I discovered this was exactly one lego minifigure knee in height, so I used the lego workman as a rest:

Soldering is Awesome!
Soldering is Awesome!

 

Finally comes connecting it all up and testing. The board is rated for a range of motor voltages. Surprisingly as I seem to have a lot of Lego around I thought I’d test it with a vintage Lego technic motor. Lego motors come in different voltages – the very old ones are 4.5v and the newer ones tend to be 9v. My motor is 9 volts but I’m running it off a 5 volt USB power supply, which I’m using in my Lego rover project. The motor runs a bit slower but is fine for my purposes. Attach the power supply for the motor to the J1 blue terminal with positive on the left hand side.

It lives!
It lives!

There’s a test program included in the instructions to switch the motor on, and change it’s direction for a set period of time.

Create the program with:

sudo nano motortest.py

 

copy the following code:

##Simple motor script for the RTK-000-001
import RPi.GPIO as GPIO
import time
#Set to broadcom pin numbers
GPIO.setmode(GPIO.BCM)
#Motor 1 = Pins 17 and 18
#Motor 2 = Pins 22 and 23
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
#Now loop forever turning one direction for 5 seconds, then the other
while (True):
#Sleep 1 second then turn 17 on
 GPIO.output(18, 0)
 time.sleep(1)
 GPIO.output(17, 1);
 time.sleep(5);
#And now the other way round
 GPIO.output(17, 0)
 time.sleep(1);
 GPIO.output(18, 1);
 time.sleep(5);
 #And loop back around
#And final cleanup
GPIO.cleanup()

 

and then run it using:

sudo python motortest.py

 

You’ll need to use sudo as you’re using the GPIO pins.

Finally here’s a picture of the almost completed Lego Rover: all that’s to do next is to write some software and add a PiCam:

Curiosity killed the cat..
Curiosity killed the cat..

The Ryanteck Raspberry Pi board is a nice kit, easy to put together and get going straight away, and works with Lego motors so there’s quite a range of interesting things you can try. Ryanteck has now launched a complete robot kit that includes a chasis as well. For more info check out their GitHub project page. It’s a bargain way of making your Pi control things.

Categories
Gadgets Geekery Random Raspberry Pi

Geeking out with a Raspberry Pi lego case

I like Lego, and I like miniature ARM based low cost PCs, so I’ve combined both with a Lego Raspberry Pi case:

Lego Raspberry Pi Case
Version 2 – slightly taller

I wanted to mount the Pi vertically to show off the intricately beautiful circuit board (and possibly to take up less space, but this thing is tiny!) and I’ve used window bricks that line up with the Pi logo. For my first attempts I tried designing a case using the lego designer – but beware, many of the bricks aren’t available from the pick-a-brick store. I’ve had to use 1×1 tiles stacked in groups of 3 to make the corners, and 2×1 tiles for the top.

This case is 4 bricks wide as the GPIO pins stick out slightly too far to fit with 2 bricks wide. Windows and arch bricks form the holes for the various plugs, with the USB and Ethernet cables emerging from the top. I’ve used the mini USB power supply from Amazon Kindle combined with a remote controlled socket for power.

The latest version has the coloured bricks at the bottom, and more clear bricks at the top to refract the light from the various power / activity indicators. It also stands a little bit taller to allow for the USB mini power plug and a grip to hold the Pi motherboard in place.

Total cost is about £30, but I do have plenty of bricks left over for other Lego projects…

I’ve now recreated the Raspberry Lego design in the Lego digital designer:

RaspberryLego case
It’s a raspberry pi case in Lego

 

I’ve coloured the bricks on the model above since they were easier to see than transparent bricks. Inside the case there’s a little c-shaped hook that the Raspberry Pi sits in. I was able to find all the bricks with the colour-scheme as used in the transparent version of the model in the pick-a-brick store.

Download the lego designer files.

If you’re building this, you need a Pi to hand to check the alignment of the ports – I have fully tested this with a Pi, but you need to build the Lego around it or it’ll get a bit fiddly.