Construction Brick Scratch Interface Device


Lego compatible Scratch Interface Device

I’ve been thinking about this for a while. It’s all very well having a battery pack connected to some motors and LEDs with Lego, but what about making it all controllable remotely from Scratch running on a laptop or desktop?

In previous articles, I’ve looked at using the Raspberry Pi and the Lego firmly next to each other, with a wireless keyboard and mouse and that oh-so-bulky monitor cable.

Then I figured out what the implications of “Scratch Interface Device” meant when I spotted it on CympleCy’s website.

Having bundled the Raspberry Pi into the case and added a set of LEDs and switches, it was a simple job to install SID and get working. The last four digits of the Raspberry Pi are used to identify it, and these must be entered on to the PC (Or Mac, if you have one). Once this is done, starting Scratch and enabling Remote Sensor Connections allows the laptop to control the Raspberry Pi without having the bulky connections. Now it’s possible to seriously integrate Lego and intelligent control.

ChristmasLights (4)

ScratchCPIO program to run the lighting

The whole setup now runs faster as the Scratch project runs on a PC, while the Raspberry Pi handles the GPIO control remotely. I haven’t yet tried all of the functions, but all those that I’ve tried have been supported. My PiBlox case has space for the Raspberry Pi camera, so running “Broadcast Photo” causes a photograph to be taken and stored on the Pi’s SD card. At the moment, it’s directed to /home/root/photos but maybe that’s something I’ve done wrong – ScratchGPIO running directly sends the files to /home/pi/photos which is a little more convenient (more later on why…).

Now… I could have stopped here, but inspiration has now kicked in. At the time of these early experiments, I was using an external battery pack and then…

…the Raspberry Pi Zero was released!

And the reason I’m now thinking of experimenting further?

Proposed Lego compatible Scratch Interface Device:

  • PiBlox case
  • Raspberry Pi Zero… when I can get hold of one.
  • WiFi dongle – perhaps a hacked and built-in version?
  • Li-Ion battery and 5v converter/charger
  • Connector setup to suit 0.1 connectors easily at the side of the case. Digital (and analogue?) Inputs, Motors and Servos.
  • Motor and GPIO controller (Explorer pHAT or maybe PiRoCon v2 depending on the size)
  • Mini amplifier PCB and small speaker.

For now, here’s a video of some of the work in action.


Cheerlights with the Raspberry Pi

cheerlightsI had seen a reference to Cheerlights on CymplyCy’s website and was intrigued. The whole idea of a set of lights being controlled by a twitter feed seemed a useful demonstration of bringing electronics, user interaction and social media together.

By tweeting #cheerlights, it’s possible to change the current Cheerlights colour. This is picked up by a variety of devices around the world and the idea is that all of the connected lights would display the same colour.

CympleCy has added to ScratchGPIO7 so that a “broadcast getcheerlights” command will trigger a fetch of the current colour.

My idea was to take the colour and use this to change the background colour of a Scratch screen to match the cheerlights around the world. I created a set of background colours that matches the cheerlights defined colours. It’s then a simple job to see what the current colour is and then choose a background to match. With the Scratch window set to full screen, it’s quite an effective colour source and a useful demonstration. Eventually the screen-blanking will kick in and I haven’t investigated disabling that yet.

With a few RGB LEDs it might be possible to create a physical light that matches the current colour. Equally, it would be lovely to see this controlling a set of NeoPixels (RGB LEDs) although this isn’t so straightforward with the Raspberry Pi.


Raspberry Pi Construction Brick Camera

Lego compatible Raspberry Pi case with LEDs, Switch and Piezo Buzzer

Lego compatible Raspberry Pi case with LEDs, Switch and Piezo Buzzer

I recently saw a Raspberry Pi case being sold by CPC which is compatible with Lego construction bricks and decided to get one. Just the sort of thing I’d been looking for in order to extend the experiments that I’d been working on.

In a very short time I’d built a Rasberry Pi selfie-camera with count-down and WiFi capability. Apache handles being able to access the photos remotely whilst ScratchGPIO manages the interfacing and triggering the camera.

Pressing the trigger button causes a gentle beep-beep-beep and flash from the red LED for a couple of seconds, followed by a green flash while the picture is taken.

The raspberry pi case easily handles the camera – it pushes onto two little pegs and the camera lens pokes through where a stud would normally be moulded. It’s so discrete that it wouldn’t be possible to guess it’s there unless known about.

Scratch Program

Scratch Program for the selfie-cam

The programming bit goes around in a loop waiting for the switch to be pressed. When that happens, the camera goes through a loop flashing and beeping, then pulsing the green LED. ScratchGPIO allows a simple “Broadcast Photo” command which works with either a USB or Raspberry Pi camera module. If Apache is set up to allow access to the same folder, then those photos can be viewed remotely.

A quick video should appear here later…

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.