LEGO robot – C64 controlled

It would be reasonable to assert that I’ve been interested in robotics for quite some time.

LEGO robot

LEGO robot

Observe: I built this robot back when I was only 9 years old! It was made entirely out of LEGOs (primarily of the Technic variety) – which isn’t, in and of itself, especially noteworthy. No, the noteworthy part was that little wire running out of it.

Well, not literally the wire – it was just some telephone cable – but, rather, what the wire was connected to: a Commodore 64! (quite possibly the best computer ever). A handful of relays and transistors served as crude motor drivers, and interfaced to the C64’s parallel user I/O port. Directing some BASIC POKE commands in the general direction of that expansion port allowed the computer to take control of the robot’s motors.

Input was provided by one of the C64’s joysticks, allowing someone to manually drive the robot around. I never did actually get around to giving this particular robot any autonomous functions (children and their short attention spans, I suppose…).

Looking back on this, I’m impressed by what was possible before the Internet (gasp! before the Internet?); it’s amazing just how many books our local library had about hardware interfacing to and programming for the C64.

Interface circuit

C64 interface

C64 interface

To the best of my knowledge (and, moreover, memory), the above schematic accurately captures the simple interface electronics I used to connect the robot to the C64. I’ve also added some basic bump sensors to the schematic, although these were never present on the original robot.

Each motor is controlled by two SPDT (single-pole, double-throw) relays, wired as an H-bridge – one relay per power lead to the motor. The relays allow each power lead to be connected to ground, or to a power source. When both relays are either on or off, the motor windings are shorted out, thus braking the motor. If only a single relay is on, the motor spins (which relay is on determines which direction the motor turns).

Since the C64 can’t drive the coils on a typical relay directly, transistors are used as an intermediary. When the corresponding line on the C64 I/O port is asserted, a current is fed (by means of a current-limiting resistor) into the base of the transistor. This turns the transistor on, completing the circuit through the relay’s coil and ultimately causing the relay to switch.

When the C64 I/O line de-asserts, the transistor turns off and current tries to stop flowing through the relay coil. Due to the inherit inductance in the coil, there is some residual energy that attempts to keep the current flowing. If left unchecked, a large voltage spike would be generated at the collector of the transistor – possibly destroying it. To prevent this, a diode is placed in parallel with the coil to provide a safe path for the current to momentarily flow through.

Leave a comment