Electronics Microcontrollers

Homebrew Intervalometer

I wanted an intervalometer for my Canon DSLR, which at the time, rather miserly did not contain. An intervalometer is a device to take exposures at regular periods. It’s great for time-lapse work. Their own add-on was quite pricey. Even knock-offs were more than I thought was worth it. And besides, I wanted a project where I could make my own printed circuit board, or PCB.
So I thought I’d build one myself. The fanciest way would have been something to talk USB, which could have made all sorts of changes to the camera settings per-shot, but I went with the ultra-simple “bulb” interface. All you need to do is close the circuit between two contacts, present on an unscrupulously proprietary interface on the camera. A simple switch would work. So would a relay, if you want to automate it. But a relay uses quite a bit of current to operate, and one useful property any intervalometer can have is to run for a long time on a small battery.
So I elected to use an opto-isolator. These devices are totally electrically unconnected to the power they are switching, as they work by the input current switching on an LED inside an IC-style package, which shines onto a light-sensitive transistor, which switches on, allowing the current to flow through it. There is nothing other than light going between the two sides of the opto-isolator, and only in one direction at that!
I experimented to find what the shortest was that I could close the circuit and have the camera reliably take a photo, and wrote a short program to activate the pin that would turn on the opto-isolator for that time, and then sleep until time to fire again. I added an LED to visualise what was going on.
I designed the PCB in, erm, PCB.
This was printed out with a mono laser printer, onto the very glossy, flimsy inserts you get in newspapers, advertising, usually, cash for gold, or takeaways that sell EVERY FOOD EVER. Place this onto some clean, copper PCB board, and apply a hot iron. The kind you do shirts with, not a soldering iron. This melts the plastic toner binder, and it should preferentially stick to the copper. You then wash and very gently clean off the paper, and you’re left with the black toner where you want the copper to remain.
This goes into the etchant, which was hot ferric chloride in solution. Once this is complete, you can, again, carefully, clean off the toner, to re-expose the copper.
Next, drill the holes for the component pins. Highly recommend not doing this by hand, PCB drills are super brittle and will easily snap off. Then, solder the components in place. As a temporary housing, I think I used a box that some cufflinks came in.
The microcontroller was programmed with the following code:
[code lang=”c”]/*
* intervalometer.c
* Created: 22/07/2011 22:12:03
* Author: Phil Bambridge <>
#include <avr/io.h>
#include <avr/interrupt.h>
#define FALSE 0
#define TRUE 1
unsigned volatile int systime = 0;
// Given our setup, this being called means a millisecond has elapsed
void delay (int mssecs) {
int timenow = systime;
while(systime – timenow < mssecs) {
MCUCR |= 1 << 5; // Disable sleep guard
asm("sleep"); // We’ll wake up when the timer counts a millisecond and throws an interrupt
MCUCR &amp;= ~(0|1<<5); // Enable sleep guard again
int main(void)
SREG |= 1 << 7; // Enable global interrupts flag
ACSR |= 1 << 7; // Turns off the unneeded analog comparator
PRR |= 1 << 0 | 1 << 1 | 1 << 3; // Turn off the ADC, the Serial and Timer 1 respectively
// Set up timer for a 1KHz interrupt- for 8MHz operation, that’s a 1/64 prescaler, and a count of 124.
// For 1 MHz (default) operation we’d go with a 1/8 precaler.
OCR0A = 124; // Count to 124
TCCR0A |= 1 << 1; // Clear timer when we hit that count set above
TIMSK |= 1 << 4; // Enable the interrupt
TCCR0B = 0x2; // 1/8 prescaler, also enables the timer-counter.
// Set all three output pins low, then set to output.
PORTB = 0;
DDRB = 0 | 1 << DDB0 | 1 << DDB2 | 1 << DDB3;
while(1) // Run forever
// Put shutter and indicator high
PORTB |= (1 << PORTB0 | 1 << PORTB3);
// Put shutter and indicator low
PORTB &amp;= ~(0 | 1 << PORTB0 | 1 << PORTB3);
By way of comparison, if I’d done this with an Arduino, the code would look something like this as a close approximation- it’s basically the blink sketch:
[code lang=”c”]#define OPTO 12
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 12 as an output.
pinMode(OPTO, OUTPUT);
// the loop function runs over and over again forever
void loop() {
digitalWrite(OPTO, HIGH); // turn on the opto-isolator (open camera shutter)
delay(75); // wait for 75ms
digitalWrite(OPTO, LOW); // turn off the opto-isolator (close camera shutter)
delay(2000); // wait for a 2 seconds
As you can see, it’s a lot fewer lines of code. The Arduino preprocessor builds the real code after you hit the compile button (if/when you know C, you realise that what you see in the Arduino IDE can’t be the whole story), we can find the actual code in a temp file. In this case it was 8036 lines, 90% of which were comments. Not a bad read for a lazy Sunday afternoon. Point is, it’s doing lots of things behind the scenes that you don’t know about. Doing it by hand not only allows you to target more chips, but you can speed up a lot of routines, and save battery power.
Electronics Programming

Boring Deadly Urgent Machine (Game) :: Part 1 :: The Spec

Some machines I like because of their sleek, minimalist exteriors, modernist or even brutalist megaliths of silicon, or brass.
But I love me some blinkenlights. If it’s got switches galore, laden with quadrant faders and vernier dials, festooned with vu meters, pulsing with neon lamps or LEDs, I’m going to pay that some serious attention. Throw in some industrial interconnects, be they ubiquitous BNCs, or some exotic mixed signal sockets, anything heavy duty, very very high frequency, lots of pins or fibre optic, fastened with clips, twist-locks, clamps or thumb screws….ahem.

Microcontrollers Programming

Atollic TrueStudio and STM32Cube

TL;DR version of getting Atollic TrueStudio and STM32Cube working
I have an ST Nucleo-F411RE development board that I’d like to use for a project. It’s using a microcontroller from the same STM32 family as I’ve tried out before, but packaged onto a board with Arduino (Uno)-pattern headers, as well as the full pin breakout. I’m not sure how useful that is for my project yet, but I wanted to give it a test drive.
Most platforms have multiple development options.
The Arduino biosphere has various hardware targets, but with a common IDE. But the Arduino boards are all based on microcontrollers from Atmel (now part of Microchip, the company that also makes PIC microcontrollers). So you aren’t limited to the Arduino IDE, and if you’d like to, you can use all sorts of development toolchains and IDEs.

Microcontrollers Programming

IllumBalloon – Microcontroller controlled balloon illuminator

I have a few bad habits. One is using digital tech where analogue would do.
This might be a classic example.

IllumBalloons at JoeFest 2010

Electronics Embedded Systems Microcontrollers

μC I have met and liked

The Arduino Family

Arduino UNO rev3

The Arduino project has been a huge success. I partly attribute this to Right Place, Right Time, though to say they have benefited from the new Maker’s movement is true but ignores how influential it has been on that movement. It is also a tribute to their holistic approach, spending as much if not more time developing the IDE and documentation to go with it- you can be uploading a new program (or “sketch” as they call them) within 5 minutes of getting it out of the box.
I have two Duemilanoves,
one Uno R3, and one Diecimila with a busted FTDI chip (meaning not only can it not communicate over USB, but it can’t be powered that way either).
Arduino Duemilanove

The Arduino hardware platform exists in many different forms, targeting various form factors, differing connectivity requirements, and in the case of the Arduino Mega, increased memory and I/O. It is also an Open Hardware platform, meaning anyone can produce works based upon it. Some have made improvements, such as the more robust version with more protected ports, or this dual-voltage capable version from ElecFreaks. Some are just
cheaper clones.
Having been introduced to the Atmel 8-bit AVR chips, I also own a few handfuls of ATtiny45 chips. I made my own programming shield with a ZIF socket to load them up. I tend to write their software in “bare” C, using Atmel Studio 6. It isn’t open source or cross platform, but it is free-in-cost, and not artificially limited.

ST Microelectronics STM32F-series ARM Cortex chips

Do you need more power? Perhaps faster clock speeds, or will be handling 32-bit floating point numbers, or you need more and more complex timers? The STM32 uber-family of chips can be handy. Would you like a built-in real time clock? Large quantities of I/O, or multiple USARTS (serial)? They have that too. Incredibly, the boards are, despite housing more powerful chips, cheaper than any
Arduino Uno, let alone the Arduino Mega.
They are a bit more fiddly to get started with on Linux, but by no means impossible. Texane’s stlink program can communicate over the USB debugging interface to upload your firmware, and all the chips have a built-in TTL serial based bootloader, very much like the Arduino- so a cheap USB-to-serial adaptor (I hacked apart an old Nokia phone cable) can get you in the back door, so to speak.
I have the STM32L-DISCOVERY board, which has the low-power STM32L152xx chip, with built-in LCD driver, and touch sensitive buttons. To show off that LCD driver, it has a 4 digit (starburst) display. These displays are still popular wherever saving energy is a must. You do lose access to most of the peripherals though, because it requires so many pins.


I also have the more powerful (168MHz, 1MB flash, 192KB RAM) STM32F4DISCOVERY
board. The board is equipped with a DAC that is also a headphone amplifier, a MEMS accelerometer, and a MEMS microphone. Also provided is a second USB interface, that can be used by the chip to act like a USB peripheral. The demo code it comes with enables it to behave like a mouse, and it moves your pointer based off the accelerometer output. It also has DSP functionality, so you could perform hardware FFT analysis of the microphone input.
Most recently, I have gotten a board with an F0 series chips, their new low-end ARM Cortex M0 cored microcontroller on it. The STM32F0DISCOVERY will set you back about £5, and for that, you get a 32-bit chip, with 64KB of flash (double the Arduino Uno), and 8KB RAM (four times the Uno’s) running at 48MHz (three times the Uno’s speed). It even comes with a generously proportioned slab of prototyping board!

Texas Instruments MSP430 family

The TI MSP430 chips seem to get everywhere, and they’re really cheap. They’re also 16-bit, which can be a boon if you need to manipulate numbers that size. The low end ones supplied with the Launchpad eval board have very small memories, and not a lot of peripherals, but you can get started with a USB-based breakout board for about £3.60…

MSP430 Launchpad

Currently I own just the one original Launchpad kit, which comes with two DIP packaged chips. So-say there is a new revision which comes with more capable chips and an improved board, but Farnell don’t seem to be stocking that yet- I guess they have too many older ones still. Or they are shipping it and haven’t updated the information. Then again, the wiki doesn’t mention the new revision either.
People have moaned about TI making a great, low-cost, low-power board, and then saddling it with non-free compilers. Now you can get hold of them for no money, but
they are limited to the code size they will produce. You can’t hit the limits with the chips that come with the Launchpad, but I would prefer something open source.
There is a port of GCC to the MSP430 family, and I’ve used that on my Kubuntu (KDE-sporting variant of the Ubuntu Linux distribution) 12.04 system here: mspgcc
But this, Energia, looks mighty interesting…an Arduino IDE fork that targets the Launchpad, and runs on Windows, OSX and Linux. Early days on this one, don’t expect to take any old Arduino sketch and have it work (and you never will, the microcontrollers have very different peripheral sets), but keep an eye on it.
And how about doing it all online with Lars Roland’s Inventor Town? That sounds suspiciously modern. Of course, you still need to be able to upload your hex file to the chip, but for that he’s provided a simple Windows program that launches when you receive the compile code. For everyone else, there’s mspdebug.

Which one should I get?

So why would I still have to recommend the Arduino out of all of these? You get an all-in-one solution, with the board, the IDE that is also the programmer, which runs on Windows, OSX and Linux, lots of libraries to get you going with many common hardware devices, and access to all the shields, for those of you not yet solder-happy. Someone with no electronics experience can be taking tentative first steps within minutes of the board arriving, and that is important for first-timers to get that confidence boost.
Yes, it’s not as powerful as the ST ARM Cortex based boards, nor as cheap. Those might well be
what you graduate to after this. But be warned that you won’t find any of them in easy-to-solder DIP packaging. NXP make a modest ARM-cored µC though- LPC1114.
Whilst I hesitate to say “follow the herd”, the sheer number of beginners who have trodden this path means there is a raft of documentation out there, and a great many tutorials, invaluable to a newcomer. And remember, if you hit the wall of resources with your chip, there’s usually a beefier one waiting for you in a parts list somewhere out there!


Brick quickly

When playing with software, unless you’re kernel hacking, if you make a mistake, there’s only so much that can go wrong. Generally you might cause a crash of some kind- an unhandled exception in Java, or a segfault in C. When you get into hardware, writing code for microcontrollers, you can properly break things.
Today, I broke a clock.


Is your Nexus 7 no longer in charge of its battery?

Betteridge’s Law might not apply here. It didn’t to me.
I was the owner of a new Google (slash-Asus) Nexus 7. And I rather liked it. I liked it a lot more once I found out the previously suggested lack of USB OTG capability turned out not to be true- a review later on.
I liked it right up until the point that my N7 stopped charging. Or did it? The battery meter was suggesting that I could not get off the 77% mark, despite also showing I was on AC power. But then it also didn’t drop below 77%.



I have too many little dev boards and breakout boards and other components laying around here, picked up from cheap Hong Kong-based suppliers. I buy them thinking “oh yes, that would be handy” and then never do anything with them.
Today I have used two in one go. Blam! I made this, the Beverage-o-Meter:


One Arduino, called the server (although the wireless boards are just peers with respect to each other), sends changes in the potentiometer’s position to the client (shown above), which rotates a stepper motor in sympathy, as it were, pointing at the beverage
desired. It is probably not that diplomatic a thing to plonk down in front of someone, so before deploying, work out a rota of who gets to hold the control.

Linux Programming Raspberry Pi

Wheezier, squeezier.

I’ve put Raspbian Wheezy onto a separate SD card, having been running Squeeze since I received my Raspberry Pi several months ago. Once I’d dd‘d the filesystem onto it from the downloaded image, I mounted it on my main Linux desktop, and edited /etc/rc.local to start lcdinfo, which I copied across as a binary, and lo and behold, after unmounting, putting the card in the RPi, and giving it power, it booted and the LCD worked. Excellent.
Now for some testing…

Electronics Programming Raspberry Pi

Raspberry Pi plus Hitachi HD44780-compatible LCD using GPIO

It’s not listed on the microcontrollers page, because I class it way outside the embedded category, though within “small computing”, but I also own a Raspberry Pi.

Raspberry Pi plus Hitachi HD44780-compatible LCD