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.
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.
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.
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.
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.
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.
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:
Hi,
Nice build!
Do you have detailed schematic over the electrical wiring between the PC9685 and the DRV8833?
brdgs
Jerker
LikeLike
The outputs of the PC9685 is connected directly to the inputs of the DRV8833. I’ll see if I can find a or create a schematic.
LikeLike
Wow thanks! Thanks for those details.
Just one question: Why would you not connect the motors directly to the pca9685? Thanks pierre
LikeLike
The PCA9685 produces the PWM signal but cannot output enough current to drive a motor. The DRV8833 can output enough current (it’s designed for driving motors), but requires something else to generate the signals.
LikeLike