The Picaxe is programmed in a simple version of BASIC, using a small circuit connected to your PC.
For the track controllers I use the following process:-
Pressing and holding A (Accelerate) will slowly increase the track voltage. If held for about 8 seconds the voltage will reach the maximum (provided by the supply). If A is released at any time before max volts are reached, the voltage will remain at that level indefinitely.
Pressing and holding B (Brake) for about 6 seconds will reduce voltage to zero. If B is released at anytime, the voltage will remain at that level indefinitely.
Pressing button C for about a second will select one direction of travel (Clockwise say). Pressing D for a sec will select the other direction. These will work only if the speed is less than about 1/8 of max.
If C or D are pressed when the volts are greater than 1/8 max, this will result in an immediate emergency STOP.
For battery locos I use a slightly different method (program) whereby there are only 6 speed steps possible. You can press A up to 6 times and the loco will accelerate up to the number you have pressed. The speed then remains there indefinately.ie if you press 3 times it will accelerate to half full speed. It takes about 8 secs to get from stop to full speed. Acceleration between steps is 'seamless'
Similarly pressing B and releasing it reduces speed by one step. If pressed more than 6 times the speed just goes to zero.
Button C can be used for a horn or whistle.
Pressing D for a sec will toggle the direction if the speed is less than step 3. If speed is above step 2 this will result in an immediate emergency STOP.
I prefer this method, but it only works where the battery voltage is 'matched' to the max speed you want. It reduces the amount of transmission time and so decreases the liklihood of two operators sending signals at the same time.
Here is a typical schematic of the track power version. To use for loco battery power, just delete the rectifier and capacitor on input and use battery - email me if you want more info.
On locos I don't use the halogen bulb as a current limiter, but I use a loudspeaker protector called a Polyswitch. These are like a solid-state circuit breaker and are available in a range of trip settings from 1A to 5A.
Batteries and Charging
I have used a couple of lead-acid gel batteries and they seem quite good, but you're stuck with 12V. These days I use AA size 2400 mAh NiMH cells - any number I need for the required voltage, from 4 to 10. These are very economical - less than $4/cell. I just solder the normal nipple types, being as fast as possible with the heat on the positive end so as not to damage the cell venting system. Batteries are always over the drive wheels for weight/adhesion.
As overload protection, I use loudspeaker 'Polyswitches' as circuit breakers for the batteries. These are small solid state disks (20mm dia disks like a coin) and come in different amp settings from about 1 to 5 amps. Mount them right at the battery terminal to protect against short circuits.
I NEVER use fast charging but always charge overnight at the 10 hour rate (C/10). Every few months I do a very slow charge at C/100 for a couple of days to equalise all cells.
I gave up using charging sockets and now just put 2 metal pins/nails/lugs or whatever, whereever they fit, and use alligator clips on the charging leads. I've built a triple charger with long leads around the ceiling of the train room, so they can drop down to wherever the loco is for charging. My locos rarely leave the track.
Electronic sound circuits
I have built many sound circuits using discrete components or using Picaxe microcontrollers.
The Picaxe includes a white noise generator (SOUND command) which can be used to simulate both diesel engine and steam chuff sounds.
Picaxe steam sound
Other steam ccts
Picaxe diesels
Other diesels
Sound recording chips
Picaxe steam sounds
While no-one will ever be able to say 'ah that's an Alco' or a certain type of steam loco sound, Picaxe can provide a 'different' sound from a small and cheap package.
Click here to listen to the diesel, and here for the steam
The basic circuit for both sounds is as follows. Only the program is changed to get the diesel or steam sound.
L1 refers to leg 1 of the Picaxe - ie pin1 in the usual parlance.
R1 and the setting of the 10k pot are chosen so that the input voltage into leg 6 of the Picaxe, is 3.3V with the track voltage corresponding to max loco speed. A typical value for R1 would be 15k. Adjust the 10k pot setting to give max 'chuff rate' or diesel sound rate with the max track voltage you will use. The 10uF capacitor on leg 6 filters pulse controllers.
The sound appears at L5 ('pin2') and is fed into a small amplifier - LM386 in this case, but any could be used. I found that the diesel sound needs a higher gain for the same perceived volume, probably because it is a lower frequency. So you could use an LM380 or two LM386 in a bridge configuration for the diesel.
You can experiment with a resistor from pin 2 of the LM386 to 0V to change the 'timbre' of the steam sound.
Note that the speaker output is really just a digital signal, so that a good amplifier is not needed. I have even used a 555 connected as a flip flop as a driver for a small speaker.
Simple STEAM Loco sound
This is a very simple program of only 38 bytes. The steam chuff is just the white noise output from the SOUND command turned on and off at a rate determined by the voltage on leg 6, so it is a very 'harsh' sound with no attack or decay time. The sound can be varied by selecting different values in the SOUND command.
When the loco is stopped there is a constant 'hiss'.
SOUND 2, (255, time) is very harsh and SOUND 2, (249, time) is less so. The odd numbers give better sounds than the even numbers. Change the line labelled 'Chuff: ' to experiment.
The 3 lines labelled times2: set the length of the chuff and the silent time between chuffs. If the max chuff rate is wrong for your situation you can adjust these. They are just simple equations that seem to work OK. Alternatively, you can use a LOOKUP command.
Many more features can be added such as:
1. Having 3 chuffs of one sound and the 4th of a different, to simulate a loco with a valve timing problem. To try this, change the chuff: lines to
chuff:
sound 2,(255,Ontime)
Pause Offtime
sound 2,(255,Ontime)
Pause Offtime
sound 2,(255,Ontime)
Pause Offtime
sound 2,(252,Ontime) ‘change sound of 4th chuff
Pause Offtime
goto Nextread
Or you can have a different sound for every cylinder! Try values of 255,253,252,251 in the four Sound commands. If you have a 3 cylinder Shay, use 6 of the Sound commands.
2. Adding a 'panting' sound when stopped to simulate a compressor. Try this in line
stopped:
sound 2,(250,50)
Pause 20
goto nextread
More Complicated Steam Sound
This extends the above simple program to change the chuff volume when the loco is slowing
This is done by storing the previous speed and changing the chuffsound number in the Sound command. To avoid instability when the speed is just on the borderline between two analogue values, the speed has to increase by 2 steps before the louder chuff is turned on again.
DIESEL Loco sound using Picaxe
This is a more complicated program and provides:
1. An idling rumble sound, which then increases in rate as the speed (voltage) increases.
2. A horn that sounds twice as the loco starts to move.
3. If the speed is reduced, the sound reverts to the idle sound until the speed increases again. This is to represent the driver 'shutting off' and coasting. However, this feature is disabled for speeds less than about 40% of max so you can shunt around and the sound rate will change.
4. The horn sounds at random intervals while running – the time between is dependent on the random number generator and the speed of the loco. Sometimes there will be 2 or 3 horn blasts together – it just depends on the random number generator.
5. When the loco stops there is a loud hiss for a few seconds to represent the brake and then the idle sound commences.
Generation of the diesel sound works on a similar principle to previously published circuits - a shift register is clocked at a speed dependant on the loco speed and the last two bits of the register are Ex-ORed and fed back to the input. I found that a 5-bit shift register sounds OK. This is easy to implement in code as a left shift of a register is just multiply a number by two (called 'seed' in program). Using a Picaxe 08M allows an 8 MHz clock and a better sound for the higher engine speed.
The 'clocking speed' is read from a lookup table and depends on the input speed/voltage. Because of memory limitations, there is not enough space to have 16 different clocking rates for the 16 input speeds. So I only use 6 steps, but this doesn’t seem to be noticeable.
The horn is simply a single note generated by the SOUND command.
DIESEL Loco sound using Talking Electronics circuits
I've found an Australian company called Talking Electronics which provides a good diesel sound kit of parts (as well as other model railway related circuits). These provide very good loud sound, that can be easily varied in 'throb rate'.
Sound recording chips and kits
I have used sound recording chips to record sounds such as horns, whistles and off-track sounds. A 20 sec recorder is available from electronics123 in the US and Jaycar in Australia has a 120 sec unit. The 20 sec one is best. All sorts of sounds can be downloaded here.

Here's some details:
6V dc supply max - works OK at 5V. Retains recorded sound even when power removed.
Takes 0.2 mA idle and 18mA when making sound. (5V)
Speaker O/P has V/2 volts dc, on it so needs decoupling.
It can record up to 24 seconds.
Hold the Record button down to record. LED lights during record.
Push momentarily or Hold the play button to replay sound. If hold it down till the end of recording, it restarts (with a slight pause).
If push momentarily, it starts to replay, and if push again during playback, it stops playing.
Record and playback inputs are held high normally, via about a 220k resistor, and the pushbuttons take this to 0V- ie have to provide a low signal to activate for at least 90 ms, of about 25 uA
I FOUND IT NECESSARY TO PUT a 0.1uF cap across the RECORD BUTTON, as I had a couple of cases where the recording was wiped out. I suspect that my UHF controllers may have interfered as I think I saw the record LED flash.
To record a sound
I use a direct connection to the computer speaker, although the inbuilt recorder microphone can be used but the recorded voltage is lower (~0.5Vpp).
The "raw" sound file can be manipulated using Goldwave.exe to produce the required length sound.