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!

Advertisements

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

pen=2
leftright=1
updown=0

def pwm(pin, angle):
#    print("servo[" + str(pin) + "][" + str(angle) + "]")
    cmd = "echo " + str(pin) + "=" + str(angle) + " > /dev/servoblaster"
    os.system(cmd)
    time.sleep(DELAY)

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

def penup():
    pwm(2,160)

def pendown():
    pwm(2,140)

def dot():
    slow(2,160,140)
    slow(2,140,160)
		
def servo_off():
	pwm(0,0)

def servoY(posY):
    pwm(0,(posY*1.1)+100)

def servoX(posX):
    pwm(1,(posX*1.2)+80)

penup()
time.sleep(0.5)
pwm(1,60)
pwm(0,100)

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

yplot=0
xplot=0

for row in list_line: # one row at a time from list_line (the result from figlet)
    slow(1,(xplot*1.2)+60,60)

    print row
    servoY(yplot)
    yplot=yplot+5
    xplot=0
    for letter in row: # work along each row - check each character.
        blockshade=letter
#        print blockshade
        if blockshade=="#":
            servoX(xplot)
            time.sleep(0.5)
            dot()
        xplot = xplot+5
servoY(0)
time.sleep(1)

servo_off()

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.

DalekSetServo

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?

AssemblingTheHead
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