After the recent call for items for the demo table over at Raspberry Pi HQ, I thought I’d send over a flag-waving set. It’s not a product for sale, but it’s one of the most eye-catching and memorable Raspberry Pi demos I’ve made. People mention it more than any of the others when I don’t take it along to Jams. There’s a video, at the end of the page, showing three Pis all waving flags together (based on three different drive systems).
Making the flag
So I set about making a flag. It’s pretty easy. You need to print your logo twice on a piece of paper in such a way that it can be folded over and glued together to make the flag.
You can have the same on both sides or different, depending on your needs. In this case I went for a nice clean Raspberry Pi logo on both sides. The actual size of the flag should be ~15cm long by ~10cm high, but the exact dimensions don’t much matter.
Previously I’d always been very careful to leave enough space at the “flagpole” end for the flag to rotate freely. But when I was pondering how to avoid it being crushed in the mail, I suddenly realised the solution was at hand. Enter stage left, the humble drinking straw. All you have to do is insert a length of plastic drinking straw, and that will ensure the flag can rotate freely (and also prevent crushing in transit).
The other little secret to free-rotating flaggage is the use of a small plastic ring to prevent the flag slipping down the pole. I use a terminal protector from a 9V PP3 battery. You can see one above and one below the flag in the photo of the whole demo.
The flagpole is a bamboo skewer of the sort used in cookery/barbecuing. The potentially tricky bit is that you need a way of linking this to the servo. Being a recovering radio-controlled plane enthusiast, I happened to have wire, z-bend pliers and small diameter drill bits to-hand, to make a linkage like this…
The only parts which are essential are the drill bits and wire.
You need a way of making a very small hole in your small diameter flagpole for the linkage wire and fulcrum to go through.
You’ll need a servo too. These can be had incredibly cheaply from sites like GiantShark.co.uk or HobbyKing.com. If you have an RC or robotics habit, you’ll probably have some lying around. ;)
A small servo is fine. I’m using a Dys 5g sub-micro servo (~£3 from Giantshark)
Here’s how the linkage all fits together.
OK, but we still need to drive the servo somehow.
I’ve been using the ATMega on a Gertboard to-date. This gives lovely smooth movement and is still my favourite way, but I happened across a thread in the Pi forums which linked to an Adafruit blog tutorial by Simon Monk. It was all about how to control a servo directly with the Pi, using GPIO port 18 in pulse-width modulation (PWM) mode with Python and Occidentalis. “Awesome – that’s exactly what I need.” I thought to myself. So I flashed an SD card with Occidentalis 0.2 – click here to download
And it was. It makes the flag waving demo much more compact (although it isn’t as smooth as the Gertboarded version). It can be done with just the servo, the battery box, 4 x AA batteries and wires – but you need to make sure you hook up the right connections to avoid damage.
- Servo signal wire to GPIO 18.
- Servo GND (brown or black) to Pi GND
- Battery negative to another Pi GND
- Battery positive to servo postive (usually red)
I’ve looked into making it less juddery, but it seems the servo pwm driver can only handle 1 degree increments. So if you have a Gertboard or other ATMega device, by all means use it (look at the sweep sketch for a good place to start). If you want a compact and portable setup, and don’t mind a little bit of judderiness, this is the one for you. (Software is found if you follow the two Adafruit links above).
You dont need a Pi or a servo, but…
Of course, you could use cams and gears and an ordinary motor with on-off control instead of a servo, but then you wouldn’t need a Pi either – and where’s the fun in that? ;) If you want to be a spoilsport, you can also wave a flag by hand. :-P