Lego and Raspberry Pi controlled missile launcher

Scratch program

Scratch program for the Missile Launcher

My son has had his eye on these things called “spring shooters” for a while… and so have I. I picked up a few from BrickLink and managed to incorporate them into a little experiment I wanted to try.

This little build uses four spring shooters and two servos controlled by the Raspberry Pi. The program, written in Scratch and interfaced using CympleCy’s ScratchGPIO7 allows rapid firing of the spring shooters by dislodging each in turn. The servo has been set to nudge the end of the dart and then return to the centre position so that the dart isn’t gripped by the actuator. This seems to work well, although I had a few problems with not initially allowing enough time for the servo to travel to its full extent.
The program allows control of the panning with the arrow keys, as well as individual control of the darts by pressing 1,2,3 or 4. Alternatively, press [f] – “fire!” for a rapid salvo directed at your target. I’ve also added a couple of warning LEDs to the base. Green is safe… and Red Flashing warns people to duck. The next step is to add a PIR sensor and let Scratch handle our security needs…

I’m sure that those with experience of OpenCV will use it to track targets and deal with them automatically.

Remote monitoring with a Raspberry Pi camera

RPi Camera and Light Source

Raspberry Pi, NOIR camera and home-hacked Infra-red light source.

I’ve used USB cameras with the Raspberry Pi in the past for capturing events – either in response to movement or as a timelapse. I also recently acquired a PI-NOIR camera which works really well with an infrared light source as a baby cam. I’ve installed tinyCAM on my Android phone so that I can use the camera as a baby monitor, but recently I came across “Raspicam” for Android. Looks interesting as it allows control of more functions.

Should be worth a try. I bought an infrared light source from that well-known auction site and it provides a powerful beam of invisible illumination which lights the whole room, especially if it’s bounced off the ceiling. It’s powered by a 12v wall-wart. I’ve encased it in a modified camping light case so that the PCB is a bit more robust. Plenty of hot glue holds the thing together nicely.

The Raspicam App is available on the Google Play store and is demonstrated on Mike Redrobe’s Youtube video.

Hanging wall plotter

I’m posting another project in my “dreaming” category – Bookmarked things that I’d like to have a go at in future. The hanging wall plotter looks amazing and was featured on the Raspberry Pi blog a while back.

The simplicity of this project is obvious – just two stepper motors and a pen-lift servo. It eliminates the hassle of x-y axis mechanisms and sliders, instead using two thin strings or something like fishing line.

Here, the complexity is hidden within the software. Plenty of trigonometry and Pythagoras at work.

Lego compatible add-on pieces

Just a quick post today, but something seems to be happening in the Plastic Construction brick and Raspberry Pi world!

Within a space of two days, I received information about these two:

  • Micrometal gear motor to Lego axle Adaptor which allows geared 6v motors to connect to Lego axles and wheels. I can see that this is going to result in a lot more Lego being automated by Raspberry Pi computers.
  • The PiBlox case for the Raspberry Pi is the second surprise. This is, apparently, a Lego compatible Raspberry Pi case. It features slots in all of the right places. including space for a camera mount.

I can see that I’m going to have to get some! It would be interesting to see if a battery pack, motor driver and servo buffer could be fitted into a second PiBlox case allowing for an all-in-one design.

Raspberry Pi controlled Lego model

Lego Space base

Lego Space base using two servos and LEDs.

Here’s a simple creation to illustrate the kind of things possible using the Lego interface I’ve built along with servos and LEDs.

I’ve put some kind of radar antenna on top of a large servo. Scratch can be easily programmed to make the servo sweep backwards and forwards, scanning for distant incoming spacecraft. I’ve put a green LED into the top of the radar which flashes constantly. The light projects down the transparent green antenna, making for quite an attractive show.

Getting into your spaceship is quite tricky given that the crew compartment is at the top. There’s a miniature servo connected to a lift arm. Pressing the Spacebar triggers a Scratch routine to lift the arm, wait enough time to transfer the crew and then lower to the ground.

I suppose the next step would be to add a flashing red LED to simulate thrusters along with sound effects played from Scratch.

Lego – Raspberry Pi interface

Lego interface

Lego interface – a L298 H-bridge motor controller with a servo buffer board.

Here’s the current version of my Lego interface for the Raspberry Pi. It uses an L298 H-bridge motor controller (covered in a previous post) combined with another of my 74HC541 buffers to protect the Raspberry Pi when connecting LEDs and servos.

The whole thing runs from a 5v plug-top power supply which is adequate for driving the 4.5v Lego motors along with a bunch of servos.

There’s a bit of scope here for making the whole thing more compact but that’s another step once I’m happy with the design. I need to add input connections so that the Lego creations can be fully interactive.

It would be also interesting to see if I could make this into a Lego case, perhaps with a bunch of plates combined with 1 x 4 x 3 Panels.

Lego and Raspberry Pi working together

In a small way, I consider the Raspberry Pi almost like a Lego brick. On its own, it’s an interesting device, but it becomes more useful when combined with other components. What would be more natural then, than combining it with other Lego devices along with a few of my own devising.

In previous posts, I’ve shown how servos can be used to create some pretty whacky Lego devices, but equally I feel that individual bricks are open to hacking. Note… this is pretty gruesome stuff – drilling, cutting and filing Lego bricks. Even something rather similar to “The Kragle” ends up being used!

Rather than steal my son’s Lego, I’ve been using Bricklink as a place to buy specific parts. I’ll try to list their code numbers here so that they’re easy to find on the Bricklink website. Bricklink serves as a market place for people to sell their bricks.

In a follow-up post, I’ll show the current version of my Lego interface.

Lego LEDs

Lego LED

Lego LED in 2×2 brick

I’ve debated at length in my own head how to wire these. Essentially all the device needs is a resistor and LED to be mounted into some kind of transparent brick, or for the LED to be poking out of the top.

A standard 5mm LED can be fitted inside a 2×2 brick if it’s allowed to shine through the top. This does mean that other bricks can’t be stacked with it, but it is a neat solution. These 2×2 bricks are also available in clear (I bought Trans-clear, Trans-Dark blue, Trans-Green, Trans-Red).

To make this, you will need:

  • 2×2 Brick (Part No:3003)
  • 2×2 Plate (Part No: )
  • 0.1″ Female connector cables
  • LED
  • 100 Ω resistor (1/8 Watt is easier to fit in)

Lego switches

Lego tactile switch

Lego tactile switch

These are easily made with a 6mm tactile switch with a long actuator. A blob of hot glue can be used to keep the whole switch central while the rest of the brick and plate is assembled around it.

The switch is connected to a short cable with 0.1″ Female connectors on the end.

To make this, you will need:

  • 2×2 Brick (Part No:3003)
  • 2×2 Plate (Part No: )
  • 0.1″ Female connector cables
  • 6mm tactile switch
4-way tactile switch

4-way tactile switch on a PCB in a Lego frame

I’ve also had success with using 4 tactile switches on a PCB. The spacing between studs is 8mm, therefore it’s a fairly simple job to create a PCB which matches. I’ve linked one side of each switch to a common line to reduce the amount of cables required.


Lego large servo

A Large servo in a Lego framework

Connecting servos into a Lego system remains the biggest challenge. I tried a number of ideas before I settled with two possible solutions.

The micro servos seem to work best glued to a tile. It needs to be something that’s compatible with the plastic of both the servo and plate. Hot glue seems to work well here, although I have had success with some solvent-based cements. Polystyrene cement worked well for a bit, but surprisingly I did have on piece fall apart.

Larger servos require a different approach. I build a framework out of bricks and plates and that seemed to work well, but it does mean that right-angle parts are needed to mount it if the axis of rotation needs to be vertical. The egg-drawing robot used a large servo resting on a tile, with some small axles to centre the spindle within the Lego grid system.

To make a framework that supports a servo on its side, I used:

  • 2 bricks – 1 x 6 (Part no: 3009)
  • 1 plate – 1 x 6 (Part no: 3666)
  • 2 plates – 4 x 6 (Part no: 3032)
  • Optional – Bracket – 2 x 2 with 2 holes (Part no: )

All of the pieces need to be stuck together with solvent and then the servo can be linked into this with hot glue. It’s fairly neat, robust and fits into the Lego system well.

The servo actuator needs a little bit of treatment to make it useful. Small servos can use a Technic axle and pin connector (Part no: 3651) and larger servos will need modifying with a pulley (Part no: 4185) along with some small screws. I used PCB pillars to get the spacing just right.

Lego framework with brackets

Large servo in Lego frame

22mm Pulley for actuator

Servo actuator using a pulley

Lego framework

Largeservo and the Lego framework

Small servo

Small servo on Lego tile with actuator