25

I'd like to find a way to make my Raspberry Pi control some Lego motors, and as a bonus I'd like to make use of one or more optical sensors.

Normally, Lego robotics make use of the Mindstorms "brick" controller - this appears to be expensive and mostly redundant if you have a Raspberry Pi to issue commands. The Mindstorms controller is a processor and a motor-controller which can run without connection to a PC but lacks Ethernet and many features of modern computers.

Is there any alternative platform that will allow me to control and receive data from Lego creations?

FYI, this is for a simple bug alerting machine. The device will monitor the status of a Jenkins test framework and perform an action depending on the number of unit-test cases which are failing. The raspberry pi will poll a web-page which contains some easily parsed XML. If the number of bugs > 0, then we'd like to to make the Raspberry Pi start driving the machine.

Maria Zverina
  • 5,168
  • 5
  • 30
  • 42
Salim Fadhley
  • 2,035
  • 4
  • 19
  • 13
  • Hey, are http://raspberrypi.stackexchange.com/users/390/salim-fadhley and http://raspberrypi.stackexchange.com/users/286/salim-fadhley both your accounts? Edit your profiles on both (if possible), asking for a merge. I've already pinged a community team member for help. – Manishearth Jun 26 '12 at 04:35
  • I'd like to do this with the older Lego Mindstorms motors I have, which are simple dc gear motors. Put +5v on one side, they turn one way, put +5v on the other side, they turn the other way. Too high current for the RPi to drive directly, though, so I'd still need some interface circuitry. –  Apr 21 '13 at 15:57

4 Answers4

14

The standard Lego Mindstorms sensors are analogue (i.e. a voltage between 0-5?V), or digital (I²C or RS-485) (source).

Analogue sensors:

I don't think the Raspberry Pi has a broken out pin in the GPIO for an ADC (analogue to digital converter), so we can't interface with analogue sensors (without an extra microcontroller).

Digital sensors:

The Raspberry Pi does have two pins in the GPIO for I²C, which means that if you connect GND, +V, SDA and SCL to your sensors, you should be able to use an I²C library to talk to them. There's a driver here - if you follow the instructions you should be able to send and receive I²C signals as easily as this (talking to an TI TMP102):

raspberrypi bootc # echo tmp102 0x48 > /sys/class/i2c-adapter/i2c-0/new_device
raspberrypi bootc # sensors
tmp102-i2c-0-48
Adapter: bcm2708_i2c.0
temp1:        +21.6°C  (high = +160.0°C, hyst = +150.0°C)

Examples:

There are a few articles on how to connect sensors and motors on this page, such as connecting a Mindstorm brick controller to an external microcontroller:

Mindstorm with microcontroller

Alex L
  • 7,605
  • 12
  • 42
  • 53
5

There is BrickPi+ helps you connect LEGO sensors and motors to the Raspberry Pi and replaces the MINDSTORMS Brick.

http://www.dexterindustries.com/brickpi/

S Melendy
  • 51
  • 1
  • 2
1

There is an alternative to all this, connect the NXT sensors and motors to the NXT control unit and then pair it via Bluetooth with the Pi, you can then send commands direct to the NXT to control it's motors and read it's sensors. check out the Mindstorms bluetooth developer kit, this allows the NXT to be completely wireless !!!!!

mike
  • 11
  • 1
1

Mindstorms is the only totally LEGO way of controlling more LEGO.

The current NXT 2.0 is quite expensive, but you could pick up an older RCX kit (that is just an example) for something like 1/3 price of the NXT 2.0 on the web.

Otherwise, you're going to have to look to a different motor/sensor kit that you might be able to attach to LEGO. These aren't exactly easy to find, and can be quite expensive; it might be worth trying to find someone who knows more about them if you go down this route.

If you are going to get an older LEGO product off ebay, I would suggest browsing brickpicker.com to get a snapshot of the market. (I discovered it a month or two ago. It's a great place to find info on the current market value of LEGO sets on ebay.)

ACarter
  • 2,350
  • 6
  • 25
  • 39
  • 2
    Sorry about that. I should have suggested that you somehow include the RPi in your answer, because this is a site about the RPi, and the question was about the RPi. If you edit your question, I can remove my downvote. By the way, http://www1.cbsd.org/sites/teachers/hs/MHAYDEN/Science%20Fair/Sample%20Abstracts.pdf Search for "Larsson" in that PDF and you'll find my project abstract from the Intel International Science Fair a few years back. It was a Lego Mindstorm that learned to win at Tic Tac Toe. – Andrew Larsson Jun 27 '12 at 17:48
  • No worries, I didn't take a perfect attitude either. I know the RPi thing, but an answer doesn't have to directly relate to it - we have loads of linux/distro specific questions, and I'm sure you could run RCX with the Pi. – ACarter Jun 27 '12 at 19:57
  • @Andrew wel I've delete my comment, so we can start a fresh. That sounds really interesting. I've made a python script that can play tic tac toe, but making it so it learns how to play it, well, that sounds brilliant. – ACarter Jun 28 '12 at 10:08
  • It used a modified/optimized implementation of Donald Michie's MENACE machine. The robot was controlled by a C++ program that pushed/pulled commands/data for/from the motors/sensors to/from the NXT. The calculations were performed on the computer, but I had a version of the program that ran on the NXT itself. It would run out of memory quite quickly, though, and arrays aren't supported by the standard firmware, so I had to replace it with a modified one. I'm thinking I just might use my RPi to make a new version of the program. It would be fun! – Andrew Larsson Jun 28 '12 at 16:44
  • Ever since I got my NXT, I've wondered how you can control it using a higher-level language on a computer. There's things like leJOS and stuff, but what did you use? – ACarter Jun 28 '12 at 16:47
  • I used this Bluetooth NXT communication library for C++. It's pretty easy to use once you get all the drivers set up. I almost wonder if I should join the Lego SE beta site. – Andrew Larsson Jun 28 '12 at 16:50