Raspberry Pi Lego Rover

Raspberry Pi Lego Rover

Here is Sir Lancelot, the Lego rover controlled by a Raspberry Pi. I wanted to create an interface between Lego Power Functions and the Raspberry Pi so that the Lego could be controlled from across the internet.

IMAG0118

The Four Wires

Lego provides extension cables which can be cut and soldered to link electrical circuits to Lego parts. The cable has four wires: two provide power all the time and stay on, and the other two (C1 & C2) provide the varying levels of power to drive motors and lights.

lego_wire


The 9V and 0V wires provide power all the time, and C1 & C2 can output a PWM signal. When driving in one direction C1 is at 0V and a PWM signal is output on C2. When driving in the other direction this is reversed: C2 is at 0V and PWM is output on C1. Seven different speed levels are used with duty cycles given below:

Level Duty Cycle
7 100%
6 87.4%
5 74.7%
4 63.2%
3 79.4%
2 39.7%
1 26.4%
0 0%

Measurements from Hack Van De Dam

Control

The circuit I put together uses a PCA9685 PWM signal generator (the same chip as is in some servo controllers) and 4 DRV8833 for controlling 8 motors.

motor driver architecture

Below is a a photo of the control board along with the battery and regulators that provide power to the board and the Raspberry Pi.

IMAG0119

 

Click on the picture to zoom in and see the captions.

Other Hardware

I’ve use the Navio board as I plan to use the GPS and accelerometers on it to provide feedback to the driver about where the rover is and provide an artificial horizon. I may in future adapt an auto pilot to drive the rover too.

IMAG0123

Click on the picture to zoom in and see the captions.

And it wouldn’t be complete without a way to see where it was going with a webcam and headlights.

IMAG0128

 

Click on the picture to zoom in and see the captions.

 

Software

The goal is to remote control the rover from across the internet. I have written a server that runs on the Raspberry Pi and sends commands over the I2C bus to the control board. Another program reads the short commands I type and and converts them into instructions to drive the motors, which are then sent to the server. The software is available on GitHub, though it’s still evolving.

I plan to create another program that uses an infra red sensor to listen for the signals from the Lego remotes and send these to the server. It should also be possible to adapt this to use a games console controller too, but that is project for the future.

Video

An important part of driving the rover is seeing where it is going. For this, there is some excellent software over at the e-linux wiki. It is fairly easy to set up.

Here is the view from the rover:

An finally, this is it driving arround:

One thought on “Raspberry Pi Lego Rover

  1. Pingback: LEGO / Raspberry Pi rover | Raspberry Pi Pod

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>