Clearing space on the SD card

All of a sudden the startx command resulted in a crash. I had updated and upgraded and wondered if that was the problem… Or was the card corrupted?

One train of thought was – Is the card full?

I typed:

df -h

and there it was: 100% full!

I didn’t want to remove any of my files so somewhere in the back of my mind I remembered that apt-get keeps a cache of all of the downloaded packages. How to clean up? A quick search revealed all I needed was:

sudo apt-get clean

A blink of an eye later and my SD card was reporting 84% full with a saving of 560Mb. Just what I needed and startx performs normally again. Excellent news!


Lego Matrix of Dots printer – snappy title, eh?

Here’s the Egg Drawing robot converted into a simple one-dot dot matrix printer. I’ve borrowed a routine that I used in the Minecraft Relief Maps project and used that to interpret a JPEG file. There are methods which use Pygame, but I’ve stuck with things I know – and can achieve quickly.

The program reads in the image and converts it into a pattern of “#” symbols and spaces using JP2A. For this reason, a decent monochrome image makes a good starting point. Once converted, it’s split into lines and the servos are then made to scan backwards and forwards, putting in a dot wherever JP2A has left a “#”.

I needed to convert between coordinates on the bitmap and the actual positions needed by the servo. This is relatively easy to do once the correct range given by the servos has been found experimentally.

I had a few problems with the pen bouncing, and also the route that the pen takes is really a curve. This would be more suited to drawing bitmaps on eggs, so that’s the next step. Maybe “Egg Minions?”.

import commands
import os
import time

DELAY = 0.002


def pwm(pin, angle):
#    print("servo[" + str(pin) + "][" + str(angle) + "]")
    cmd = "echo " + str(pin) + "=" + str(angle) + " > /dev/servoblaster"

def slow(servo,start,stop):
	difference = start-stop
	servopos = start
	if start<stop:
		step = 1
		step = -1
	servopos = start
	while servopos != stop:
		servopos += step

def penup():

def pendown():

def dot():
def servo_off():

def servoY(posY):

def servoX(posX):


wr_str = "MonoLogo.jpg"

cmd = 'jp2a --width=20 --height=20  --background=light --chars=" #" '+wr_str # create an operating system command
line = commands.getoutput( cmd ) # send cmd as a command to the operating system and receive the result.
list_line = line.rstrip().split("\n") # split the result from "figlet" into separate lines (right strip new line feeds)

print "Your picture has been converted to"
print line


for row in list_line: # one row at a time from list_line (the result from figlet)

    print row
    for letter in row: # work along each row - check each character.
#        print blockshade
        if blockshade=="#":
        xplot = xplot+5


print("All done!")

Once that’s all running, assuming you have a MonoLogo.jpg file available, the machine will convert and start automatically.

Lego printer image

Simple print out of the Raspberry Pi logo using a Lego dot matrix printer.

Minion bitmap drawn on the egg

Drawing a design on an Egg

The finished egg design

The finished egg – just in time for breakfast.

Programming the Egg drawing robot

Scratch program for drawing squares on the egg.

The program to draw a grid of squares on the egg.

In order to program the egg drawing robot, a simple pair of loops are required. One draws the horizontal lines and the other is responsible for the vertical ones.

In this case, I’ve simply laid out a loop that:

  • Move to the left
  • Drop the pen
  • Move to the right
  • Lift the pen
  • Rotate the egg upwards slightly
  • Repeat ten times

Followed by:

  • Rotate the egg upwards to the start position
  • Move to the left
  • Drop the pen
  • Rotate the egg downwards
  • Lift the pen
  • Move the pen to the right slightly
  • Repeat ten times

In order to make the servos move over their required range, it was necessary to find out what the extremities of movement were – for example, how far can the pen be moved from left to right. This then gave a range of values. I subtracted the smaller value from the larger value. Then I needed to find the offset – the starting value. I then used a scale value to make my servos now respond to a range of 0 to 100. A bit difficult to describe, but a quick visit from the formula for a straight line: y = mx+c

Overall, the grid is fairly simple but it’s ideal for demonstrating control over movements, the resolution of the servos and the pen and just showing what can be done with some Lego and some servos.

Next up… hopefully bitmap conversion!

Egg drawing robot

I quickly knocked together this Egg drawing robot after seeing the “EggBot” somewhere online. I’ve been experimenting with building a Lego motor/switch/servo Raspberry Pi controller and it seemed like something that might demonstrate some capabilities of the various parts needed.

There are three servos: Pen Lift, Rotate egg, Side-to-side for the pen.

The servos are controlled using ScratchGPIO and to make the range of the servo match my coordinates I needed to dust off my O-level maths for the straight-line formula: y = mx + c

Ultimately, the project was a minor success. I’ve learnt that the egg needs to have warmed to room temperature otherwise the condensation makes it too slippery to grip. I also needed a sharper pen – I seem to have picked a “bluntie”.

Programming of the ScratchGPIO Dalek

Finished Dalek Model

Finished Dalek model ready for control with Scratch or Python

The Dalek here consists of four outputs connected to the GPIO port on the Raspberry Pi. These are:

  • Standard size servo – on GPIO pin 7
  • Blue head LED (left) – on GPIO pin 11
  • Blue head LED (right) – on GPIO pin 12
  • Red Antenna LED – on GPIO pin 13

These are all within the capabilities of ScratchGPIO which can be obtained from SimpleSi’s website. Out of all of the Raspberry Pi software, this is one add-in that I keep coming back to as it’s easy to install, intuitive to use and gives me the control I need.

Servos are controlled by setting up a variable – for example: Servo7 would be used to send the appropriate PPM signals on pin 7. Using Set Servo7 to 0 will ensure that the servo moves to its central position. Note that there is a limited range that servos can rotate to. I have got servos that will only cope with a range of 50 down to -50.


Simple digital output devices such as LEDs are controlled by using a broadcast command. To turn on an LED, I use broadcast Pin11OnDalekSetPinOn

DalekControllerWhen these commands are combined with forever loops, the repeating effects are quite effective despite the simplicity of the commands.

  • I’ve used a repeat loop to flash the blue head LEDs 10 times
  • Move the head left and right, followed by a movement to face forward
  • Fire the gun 10 times with a short pause in between each flash
  • Repeat the whole lot forever…

One thing that my Pi seems to be struggling with is the use of sound. I grabbed an “Exterminate mp3” from the internet but I’ve had all manner of strange noises and interference. It might be an interaction with the servo driver, Scratch or just something else within the operating system. It might even be due to the fact that I’m developing on an original 256Mb Raspberry Pi and it’s all a bit tight in memory!

However, the next step will use Python, and for this I’ll need some help from the Raspberry Pi website. Some time ago, they featured “Boris, the Twitter Dino-Bot”.

More info coming soon once I’ve had a chance to try out the Python programming.



Construction of the ScratchGPIO Dalek – Invasion part 2

Here’s the second installment of the ScratchGPIO Dalek – the first part can be found here. My apologies for the poor quality of the photos. Our camera was in use elsewhere so I only had my mobile. I’ve discovered that it can’t cope with low light and close up shots. Perhaps I should have used the Raspberry Pi camera?

MostOfTheBitsHere’s what I’m starting with. I’ve got a servo, some LEDs (red and blue), Chromed LED bezels and a few bits of plastic cut on a CAM router. The Dalek is a plastic container originally for bubble bath,but having removed the bottle it seems that there’s plenty of space for a circuit board, a servo and some odd bits of wiring.

EyeballThe eyeball LED is made from a piece of chromed brass tubing removed from an old telescopic aerial. The LED is soldered to the end of stranded wire and carefully sealed with hot glue. A clip-on LED bezel is used to complete the effect and makes for a realistic eyeball. I would have liked to add on some disks half-way along the stalk, but I didn’t really have time and perhaps it can be easily overlooked?

The head lights are made from blue LEDs soldered to the end of stranded wire and then pushed into some chrome LED bezels that were in my parts stock. At first, the LEDs were difficult to see as they are so directional and the bezel tended to shield the light coming out sideways. The solution? Fill the bezel with hot glue (in fact, overfill it) and then let it cool without disturbance. This created a slightly domed translucent light which can be seen from all angles. For such a simple solution, I’ve been really impressed with the result. And I didn’t burn my fingers. The domed lights are then pushed into the head. The slightly rubbery nature of the head means that I’m unlikely to need to put the nuts on the other side of the bezels. I don’t think I’d succeed either!

BufferboardThe bufferboard is one of my own designs (more information here) that I produced a while ago. I use it as I managed to kill a couple of Raspberry Pi computers while experimenting with servos. I’m not sure whether it’s a faulty servo that did it, but ever since I’ve been quite nervous to work without this board in the way. It also level shifts the outputs to 5v instead of 3.3v, making the LEDs (particularly the blue LEDs) able to run at their full brightness. Having said all that, I’ve used a 330Ω resistor in series.

ServoWheelThis part is a simple three-spoke wheel that fits on top of the servo horn. The outside diameter has been chosen to fit the inside hole under the dalek head. The three spokes gives plenty of space for the wires to pass upwards from the base. I had pondered how to get the servo horn to stay attached as I’ve found hot-glue to be a bit unreliable on these and there wasn’t really room for the M2.5 screws that I usually prefer. Cable ties to the rescue! They hold well, especially as I filed a few little slots in the servo horn. Simple and effective.

DalekbaseFitting the servo up inside the base was a bit more tricky. There are quite a few obstructions up inside the base which have to be taken care of. In the end, I cut out the top section carefully and then used added a foamed pvc plate which carries the servo. After nearly exhausting my supply of M3 screws, the servo was mounted and the horn fitted.

TwoPartsOfDalekHere are the final two parts ready for fitting together. The cables will pass down through the wheel into the base where they are then connected to the buffer board with 330Ω resistors. The servo is also connected. I ran a little test routine from Scratch to ensure that the servo can reach both extremes and also find the centre. Once this was done, a few blobs of hot glue ensures that the head and the wheel are joined.

Coming up… programing the Dalek with ScratchGPIO (and Python eventually).

Building a PICAXE controlled rover

P1250840I’ve already shown how a PICAXE can be used to build a simple Robot. I know that this blog is really meant to be aimed at Raspberry Pi users but the techniques would be similar. As a result, I thought it’s worth uploading the photographs that show the robot being constructed. If I can get the technical Lego back from my son, it might be possible to rebuild using the Raspberry Pi, and even extend the functions to make more of it!

The original blog post shows the robot in action.

Chassis parts

The chassis is constructed using a variety of beams and plates along with a couple of gear trains. You’ll need:

  • 8 x 1 beams (4x)
  • 8 x 2 plates (1x)

Chassis parts

Continue reading

Invasion of the ScratchGPIO Dalek

ScratchGPIO controlled Dalek

The finished Dalek – Blue and Red LEDs with a standard servo

I found a Dalek model in the local recycling centre and, along with a few other items, was able to take it home in return for a few coins. Disassembling it that evening revealed that it was a very elaborate bottle holder, and I’m guessing that the original contents were something like shampoo. Wow… all of that detail for a simple product.

It didn’t take me long to realise that it wouldn’t take long to make this into a simple model that could be controlled by a Raspberry Pi, using a servo for rotating the top half. I also considered moving up and down the antenna stalk, but there wasn’t really enough space to fit the kind of mechanism I had in mind. Overall, I wanted to keep it simple.

I had to do quite a lot of cutting and filing to fit a servo inside, using a small piece of foamed PVC board as a servo mount, along with a custom made “wheel” that fitted the servo horn and the inside of the top.

The electronic interfacing was taken care of by using one of my previously tried and tested buffer boards using a 74HC541 which protects the Raspberry Pi to some extent. I’ve added a standard sized budget servo, two blue LEDs on the head and a red LED on the antenna.

From a software point-of-view, I’m testing using the wonderful “ScratchGPIO”. A couple of scripts are responsible for flashing the LEDs in a menacing manner and a simple loop makes the Dalek rotate back and forth using the Servo7 variable. I like using ScratchGPIO as it gives me a chance to check all of the outputs easily without having to refer back to my syntax cheat sheets. Eventually I’ll probably move the control to Python and use ServoBlaster directly.

Ultimately, this may become an information Dalek. I’m hoping I can get it to pick information out of Twitter, read the news and weather and perhaps announce incoming mail. Watch this space!

I’ve put the second part online now and I’m working on developing the third part of the documentation.