Tuesday, 1 June 2010

A train moves!

I've got train with my new circuit design working on the tracks! Hooray! Although I've had this working before, the new design differs in two ways:
  • The previous design had all the electronics in a carriage towed behind the main engine. While this was asthetically nicer and would allow me to put a nice looking cover on the engine and keep all the electronics hidden, it was somewhat impractical. This was mainly because there were quite a few wires that needed to go between the electronics carriage and the engine (track power pickup +/-, motor drive +/-, front reed switch input. At this stage of the project I want to keep things as simple as possible, so I've moved everything onto a single engine. It's not pretty, but it's much easier to work with. Plus it looks like a robo-train from THE FUTURE, which I kinda like.
  • Previously I used a DPDT relay wired in a crossover configuration to reverse the connections to the motor when the train was moving backwards. While I generally like to try and find an excuse to use a relay whenever I can (love that relay *click*), this was a bit of a silly solution - not least because it meant the train used considerably more current when reversing because of the relay coil. I'm now using a 2675 H-Bridge chip borrowed from my housemate for motor direction control. It's a nice little chip to use - although sadly it needs a 5v supply which means I've got two linear regulators on the board (the other is 3v). At some point I'll find a 3v H-bridge. Speed control is using PWM from the microcontroller.
Mounting the circuitry to the train body didn't turn out to be too hard. I stole a female USB socket from an old hub and Araldited it vertically onto the train. This provides a nice mount for the train's control Mote that allows to be easily removed for reprogramming. For now I have decided to use reed-switches and magnets under the track to sense when the train has passed the boundary between track segments. Mounting the reed-switches to the underside of the train proved quite difficult as there is very little clearance between the bottom of the train and the tracks - yet the switches need to be quite close to the magnets to function reliably. It seems to be working well now though. Here are some photos of the thing in all its glory (note the shoddily mounted reed switch on the front. Amazing what you can do with Araldite):


The train firmware is very simple at the moment. It accepts messages on the radio from my PC that allow me to start/stop and set the speed. Each time it reaches a reed-switch (positioned at every end of my test track) it automatically stops and reverses direction. Here's an ever so slightly more exciting video!