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,188
  • 5
  • 32
  • 42
Salim Fadhley
  • 2,035
  • 4
  • 19
  • 13

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,615
  • 12
  • 44
  • 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
  • 40