Subscribe via RSS
18Mar/104

Controlling lots of LEDs with your Arduino

There's a great article on the MAX7219/MAX7221 LED Drivers on arduino.cc that details how to utilise these chips to control a large amount of LEDs (MAX7219/7221 Datasheet.) The layout I've been working on was always going to have a lot of scenery lighting and I'd decided this time to use LEDs over traditional 12v DC Bulbs as they draw less current and can often be a lot brighter. Also, Japan does use a lot more 'white light' when lighting streets and train/traffic signals, so it fits in close enough to the prototype.

LED Drivers are specific intergrated circuits that are designed to control a large amount of LEDs wired up in a matrix. This means that, in the case of the MAX7219/7221, the LEDs will be in rows and columns of 8 for a total of 64 LEDs per chip. The exact wiring dictates that each column contains 8 cathodes and each row 8 anodes. This therefore means that if you apply power to one row, and then ground a column, you will light the associated LED. Of course, this means that if you power two rows and two columns you will in fact have 4 LEDs lit. This is because the matrix is limited in only being able to light specific LEDs on a row-by-row basis.

Fortunately, the Drivers are fast enough to light row after row (selecting the exact LEDs to light by grounding certain columns) making it look like all LEDs are on at the same time. Therefore, you can specify the exact LEDs to light and, in the case of an 8x8 matrix, you can draw pictures, scroll text, etc...

Of course, you are not limited to controlling a matrix. These chips fundamentally just light up 64 LEDs and, for my layout, this should be enough for my scenery requirements. The main issue is actually building a 'distribution point' for getting the 64 pairs of wires out to the LEDs from the chip.

Note: PLEASE make sure you have a 'clean' power supply and it's connected cleanly and solidly. I just spent a day diagnosing why my LEDs stopped working... it was because my 12v power distribution had a dry solder joint... totally frustrating!

How to wire up a MAX7219 LED Driver

As the chip only has 16 pins (8 rows, 8 columns), one has to split these out into inidividual wires to LEDs.

If you happen to have your LEDs in groups/clusters of 8 then you will have a lot less trouble wiring everything up... otherwise you'll need to tediously create a 'distribution board' like I've done here:

Plugs to connect LEDs to

So, once this was together I put some plugs on the end of the ribbon wire and then added header pins to my LED wiring. This then meant I could simply plug the LEDs in as no resistors are required. Trying to work out which way around to put them was quite easy, as they seem to get full voltage if you put them the wrong way! So, be careful, if this happens then quickly reverse the LED.

I then wrote some code to turn my well-lit footpath into a flashing mess...

//pins for the MAX7219 
#define CLK_PIN 31
#define LOD_PIN 33
#define DIN_PIN 35
 
//pins for my L298N throttle 
#define THROTTLE_ENABLE 2
#define PWM1_PIN 3
#define PWM2_PIN 4
 
//library required from:
//http://www.arduino.cc/playground/uploads/Main/LedControl.zip
#include "LedControl.h"
 
//LED CONTROL... 3 pins and then the number of devices
LedControl lcl=LedControl(DIN_PIN,CLK_PIN,LOD_PIN, 1);
 
//currently connected lights:
//ROW 0:   NONE. 
//ROW 1: Building, Building, Building, Building,
//       Streetlight, Streetlight, Streetlight, Streetlight
//ROW 2-3: NONE.
//ROW 4: Streetlight, Streetlight, Streetlight, Streetlight,
//       Streetlight, Streetlight, Building
//ROW 4-7: NONE.
  
void setup() {
  //initialise the led driver...
  lcl.shutdown(0, false);   //turn off shutdown..
  lcl.setIntensity(0, 8);   //set the intensity, you can also use the potentiometer.
 
  //set initial throttle, direction and speed 
  pinMode(THROTTLE_ENABLE, OUTPUT); 
  digitalWrite(PWM2_PIN, HIGH);
  digitalWrite(PWM1_PIN, LOW);
  analogWrite(THROTTLE_ENABLE, 200);
 
  //turn on the building lights.
  for (int i = 0; i < 4; i++) lcl.setLed(0,1,i,true);
  lcl.setLed(0,4,6,true);
}
 
int MS_DELAY = 300; //timing, close enough to train speed.
 
void loop() { 
  //the streetlights are in a bit of a jumbled order:
  //ROW 4: 5,4,3,2,1 and then ROW 1: 4,5,6,7.
 
  //turn them all on
  for (int x = 5; x >= 0; x--){ 
    lcl.setLed(0, 4, x, true);
    delay(MS_DELAY);
  }
  for (int x = 4; x < 8; x++){ 
    lcl.setLed(0, 1, x, true);
    delay(MS_DELAY);
  }
 
  //now turn them back off
  for (int x = 5; x >= 0; x--){
    lcl.setLed(0,4,x,false); 
    delay(MS_DELAY);
  } 
  for (int x = 4; x < 8; x++){
    lcl.setLed(0,1,x,false);
    delay(MS_DELAY);
  }
}

And here was the result, with my homemade street lights:

The best thing about these chips is that they can be daisy-chained together to control a total of 512 LEDs off 3 pins. If you think you'll need more than that for your project, then you're crazy... but it can be done. Simply utilise another 3 digital pins of your Arduino to control another 512 LEDs... I shudder to think of something lit that brightly.

16Mar/103

Multiplexing + Controlling points (or other high-current devices) with an Arduino

OK, the Arduino only has a limited number of pins at your disposal (more depending on what model you are in possession of) but, don't fret, there is a way of extending the amount of inputs _and_ outputs.

Multiplexing, as defined by Wikipedia is:

In telecommunications and computer networks, multiplexing (also known as muxing) is a process where multiple analog message signals or digital data streams are combined into one signal over a shared medium. The aim is to share an expensive resource. For example, in telecommunications, several phone calls may be transferred using one wire. It originated in telegraphy, and is now widely applied in communications.

In our situation, we're using digital data and our shared medium will be a smaller group of pins than the amount required if we were to hook up the sum total of devices able to be connected. So, in our case we will use the CD4514BC "4-Bit Latched/4-to-16 Line Decoder" to control/read 16 digital lines from only 6 digital pins.

Quick note:
If you don't mind that the chip is always outputting then just ground the Inhibit pin. It'll save you a pin on your Arduino!

First, a short stint of binary logic. Our numbering scheme will start from 0 and end at 15, giving us 16 possible values. This can be written in binary using 4 digits.

Bit 4 Bit 3 Bit 2 Bit 1 Value Bit 4 Bit 3 Bit 2 Bit 1 Value
0 0 0 0 0 1 0 0 0 8
0 0 0 1 1 1 0 0 1 9
0 0 1 0 2 1 0 1 0 10
0 0 1 1 3 1 0 1 1 11
0 1 0 0 4 1 1 0 0 12
0 1 0 1 5 1 1 0 1 13
0 1 1 0 6 1 1 1 0 14
0 1 1 1 7 1 1 1 1 15

Right, from this table you can see that by setting the Bits to either '1' or '0' we can, with 4 bits, create the numbers from 0 to 15. Now, this is how the input of the CD4514BC Line Decoder works; it accepts digital input on 4 pins, and dependent on whether they are high or low, will output a +5v on the decoded output pin. The chip has, of course, 16 output pins.

The only catch to using this chip is that it also requires 'Strobe' and 'Inhibit' digital inputs. It is called a 'Latched' Line Decoder since it actually holds the output that you have selected. So, the basic idea when controlling it is to:

  • 1 - Set the 4 bits to the desired output
  • 2 - 'Toggle' the 'Strobe' pin. This means setting it to 'HIGH' and then 'LOW' again (this then 'latches' the next pin to output on)
  • 3 - Set the 'Inhibit' pin 'LOW' to output on this pin. When this is 'HIGH', there will never be any output.

Here is the wiring I have used for the CD4514BC:

IC4514 used to control activation of H-Bridge

Dragging the 'Inhibit' HIGH should prevent the points from erratic data on the pins when there is no proper input signal.

From this we can see that we can control 16 devices. The only note is that the multiplexer can only ever output on one pin at a time.

Controlling this chip is quite simple. The steps, as outlined above, are documented in the following code:

#define STROBE_PIN 51
#define INHIBIT_PIN 53
#define BIT1_PIN 31
#define BIT2_PIN 33
#define BIT3_PIN 35
#define BIT4_PIN 37
#define DIRECTION1_PIN 22
#define DIRECTION2_PIN 24
#define TOTAL_OUTPUTS 5 //should 16, but we're only controlling 5 pins for now.

void setup() {
  Serial.begin(9600);
  //set the output mode.
  pinMode(INHIBIT_PIN,OUTPUT);
  pinMode(STROBE_PIN,OUTPUT);
  pinMode(BIT1_PIN,OUTPUT);
  pinMode(BIT2_PIN,OUTPUT);
  pinMode(BIT3_PIN,OUTPUT);
  pinMode(BIT4_PIN,OUTPUT);
  //initial state
  digitalWrite(INHIBIT_PIN, HIGH); //high = off.
  digitalWrite(STROBE_PIN, LOW); //toggle low -> high -> low to set output.
  digitalWrite(BIT1_PIN, LOW);
  digitalWrite(BIT2_PIN, LOW);
  digitalWrite(BIT3_PIN, LOW);
  digitalWrite(BIT4_PIN, LOW);
}

void changeOutputPin(int out) {
  //work out bits
  if (out >> 3 & 0x01) digitalWrite(BIT4_PIN, HIGH);
  else digitalWrite(BIT4_PIN, LOW);
  if ((out >> 2) & 0x01) digitalWrite(BIT3_PIN, HIGH);
  else digitalWrite(BIT3_PIN, LOW);
  if ((out >> 1) & 0x01) digitalWrite(BIT2_PIN, HIGH);
  else digitalWrite(BIT2_PIN, LOW);
  if ((out) & 0x01) digitalWrite(BIT1_PIN, HIGH);
  else digitalWrite(BIT1_PIN, LOW);

  //toggle strobe
  digitalWrite(STROBE_PIN, HIGH);
  digitalWrite(STROBE_PIN, LOW);
}

int currentOutput = 0;
int switchDir = 0;
void loop() {
  changeOutputPin(currentOutput);
  currentOutput++;
  if (currentOutput > TOTAL_OUTPUTS) {
    //only control 8 outputs... change the dir once looped.
    currentOutput = 0;
    switchDir = !switchDir;
    if (switchDir == 1) {
      digitalWrite(DIRECTION1_PIN, HIGH);
      digitalWrite(DIRECTION2_PIN, LOW);
    } else {
      digitalWrite(DIRECTION1_PIN, LOW);
      digitalWrite(DIRECTION2_PIN, HIGH);
    }
  }
  //toggle inhibit to low to actually output power
  digitalWrite(INHIBIT_PIN,LOW);
  delay(25); //25ms is long enough.
  digitalWrite(INHIBIT_PIN,HIGH);
  delay(1500); //now delay before going to next point.
}.

Controlling Point Motors

The Tomix Finetrack points I use on my layout have in-built electromagnets to change their direction. Electromagnets are known to suck a large amount of current in a short burst as they receive power and begin to 'throw'. Due to this, powering one directly off one of the Arduino's output pins is not recommended. Another issue is that the electromagnets will heat up if they are constantly powered. Due to this, they require an external power source controlled in short bursts.

A H-Bridge is used when controlling the actual model locomotives and here one will also be used to control the point magnets. H-Bridges are a great solution to the above issue as they utilise an isolated power supply and can output a reversed polarity. The point magnets from Tomix are only 2-wire and require the polarity to be reversed to switch the track in the other direction.

Note that this can therefore be used to control anything that requires a 5v-34v DC ~1A power source. This could be bulb lighting (where you can vary the voltage/brightness), motors/actuators/solenoids for scenery effects, etc...

So, firstly here's an example of hooking up an L293D or SN754410 H-Bridge to two point motors/magnets:

H-Bridge + Electromagnet wiring

Now, there are three wires feeding into the above circuit (per point motor/side of circuit) that need signals. First is the 'activate' pin which should stay low and only be brought high for brief periods of time to send voltage to the point magnet. Second is the 'directional' pins where:

  • LOW, LOW: No output
  • LOW, HIGH: Left (-/+)
  • LOW, HIGH: Right(+/-)
  • HIGH, HIGH: SHORT! Do not do this!

So, to get the 'enable' signal to the H-Bridge we will utilise 6 pins on the Arduino. One for the actual signal to send and then 3 to control a multiplexer which will then allow us to actually control 8 outputs. This multiplexer (CD4514BC) can only send a signal on one of it's 16 pins at a time. The goal therefore is to set the four input wires (which then selects the output) and then produce the HIGH signal for a brief period of time. This will send the required signal to the H-Bridge which will, in turn, output the 12v pulse to the point magnet.

The final requirement is to set the direction. I have bridged the inputs on all H-Bridges to a single pair of digital outs on the Arduino. I simply set one HIGH and the other LOW to switch in a direction. You could actually use one pin and have a Hex Inverter create the opposite signal required for the other input on the bridge.

Since I only ever enable one side of one H-Bridge, it is perfectly safe to set all inputs on all bridges at the same time.

Here is the final setup:

How to hook it all together

My ugly diagram showing you how to connect the components.

Four SN754410s hooked up (with power LED)

The functional dog's breakfast... This is a tiny piece of veroboard with 4 H-Bridges (8 outputs) and an LM7805 to provide the +5v. The inputs on the H-Bridges are chained together and the enable pins (8 of them) run to one side of the CD4514BC.

CD4514BC Multiplexer

Here is the CD4514BC Multiplexer. This receives 6 wires from the Arduino and then outputs 16 digital to whatever I require.

Complete system functional

And everything working in concert.

24Feb/106

Detecting trains with InfraRed + Arduino

You've probably seen a lot of reversing/stopping circuits around, but the majority of these run on occupancy detection in track blocks. This can work very well but, due to the differences in train engines, you can have issues with how quickly to slow/stop individual locomotives. There are other ways of detecting a train coming to a dead-end, and here I'll show a method using Infrared Light.

Infrared light can't be seen by the human eye, but can be picked up by electronic devices. Due to this, it can be used freely around your layout (with the exception that direct sunlight/room-light can cause interference) for detecting your trains. One of the more common usages is to put an emitter/detector combination in a buffer to stop a train as it comes to the end of the line.

IR Detector

Note that there are two emitter/detector devices! Each 'black box' in that diagram contains both an emitter and a detector. The benefit of using the QRD1114 means that these are neatly packaged in one unit!

In this set up the emitter and detector are both facing towards an approaching vehicle. The emitter-side of the QRD1114 will always be emitting infrared light down the track. The detector will then receive the infrared light reflected off the vehicle as it approaches and its internal resistance will rise accordingly. This means we can read the resistance of the detector to know how close the train is therefore slow it down proportionately. We can therefore ensure the train does not hit the buffer by checking the value of the detector and altering the speed of the train quickly and appropriately.

Firstly, here's the circuit for wiring up both the 'Infrared Emitters and Detectors' and the Optical Detector / Phototransistor (recommended) from Toys Downunder. And Here's the datasheet for the latter QRD1114.

Note: I happened to test out both setups as I destroyed my first QRD1114 by applying 5v directly to the emitter... You must only apply 1.7v max!

Wiring up the detector

And then the detector set up on the engine shed roads:

Infrared Shunt

The two roads above will eventually be located inside an engine shed. Due to the potential interference from one emitter to the other, I will put a separator down the middle of the tracks.

The maxmimum read distance I could achieve was just under 6cm during testing**. This wasn't exactly what I was expecting and would've liked around 10-12cm for this purpose, but I worked around this. It seems that there is a more expensive detector at Toys Downunder: Sharp GP2Y0A21YK that can detect object up to 84cm away. I imagine it would be as simple as obtaining larger IR LEDs to boost the light output and therefore the light reflection.

Once the two detectors were in place, I set about automating a quick shunting process. I'd started noticing that, depending on room light, the readers weren't doing the best job; down to around 20mm distance was all that was being detected. This would not be enough to measure the speed as I wanted to, but I kept going anyway.

Programming the detector was the same as the potentiometer throttle done previously. The detector acted as a variable resistor and the reading would be from +1000 to 0 depending on the reflectivity of the object. It turned out that 0 was when the object was closest to the detector. Unfortunately, this only started changing once the object came within 30mm.

Here's a video of my quick shunt automation in action. First with the QRD1114 and then with the separate emitter/detector:

Results

I ended up stopping progress on this as the detector didn't respond as well as I'd have wanted. After getting a 6cm read distance during test I thought it would feasible, but this dropped to a max of 15mm when actually installed on the track. There would be too much re-adjusting to get either of the types of infrared detectors to work.

The only option from here is to purchase the Sharp detector mentioned above and see if it really can detect 84cm!

18Feb/105

Tracking trains with an Arduino and RFID : Implemented

Right, after telling you all about how the RFID setup works (and how to do it yourself), I thought I'd actually test it on my work-in-progress layout. Just for a recap, this setup uses the Arduino Mega, an ID-12 RFID Reader (plus RFID Button) from Toys Downunder and the code provided in the article listed here.

I knew the ID-12 reader had a 60mm optimal read distance, so I wanted it pretty close to the track for extra reliability. I decided on mounting it inside the platform, as it would be close to the track and I could perform actions/events once a train reached the platform.

First I had to rewire the reader, as previously I'd used component wires (surplus resistor legs, etc...) so that I could easily test it on the Arduino. Now that it was to go through the baseboard I needed lengthy wires:

Re-wiring for cables this time

Fiddly business

And then I mounted it into the station platform:

Station setup

And then, it just worked!

What you can't see is the readout on the computer screen of the unique id on the button. This is what will allow me to perform actions (maybe sounds, path settings or signal settings) per each train I have with a button installed.

What's next? I might try some proximity detection; as you can see, I have a 2-road yard just to the right of the station which will be an engine shed and it'll require that trains don't smash through the rear wall :)

17Feb/1010

Tracking trains with an Arduino and RFID

So, you're now controlling your trains with your Wii Nunchuck and an Arduino... What if you get tired and want them to run by themselves? This next project will help you with one piece of the puzzle, as long as the trains are still moving :)

Whilst looking for the Wii Nunchuck Adapter at Toys Downunder, I came across RFID 'buttons' and an RFID reader that were compatible with the Arduino. Since I have the Arduino Mega, I knew I'd have pins/serial lines to spare, so I went ahead and added them to my order.



I bought the ID-12 RFID Reader and 2 RFID Buttons. I chose against purchasing the breakout board, as after reading the comments it didn't look like it would fit the ID-12 (only fitting the ID-20.) I've since asked Toys Downunder to correct this comment in case it really does, as soldering these readers is a pain. (Note, they have since updated the notes and the ID-12 does indeed fit. They also offered me a free one! I might act on that next time I go shopping there!)

RFID IC Pinout

Wiring up the reader was going to be pretty simple. I'd see examples of it wired here for a door lock and in the datasheet. I was a little confused as to which 'output' to use; there are two provided and I guessed right the first time (pin 9: Inverted TTL Data.) This output was fed into an RX port on one of the 3 surplus Serial ports on the Arduino Mega (Serial1).


After a quick bit of coding, I had the RFID reader picking up the RFID button reliably. You can find instructions on this from the Arduino site for another type of reader, but below is a quick code listing for getting it to work on the Arduino Mega. I wrote this with guidance from the previous door lock link and the Arduino site as well.

bool newData = false;
int cardData[16];
int idx=0;
void setup() { 
  Serial.begin(9600);  // Hardware serial for Monitor 9600bps
  Serial.println("Starting Reader..."); //show some activity
  Serial1.begin(9600); //ID-12 uses 9600!
}
void loop() { 
  while (Serial1.available() > 0) {
    cardData[idx] = Serial1.read();
    idx++;
    if (idx == 16) {
      newData = true;
      idx = 0;
    }
  }
  if (newData){
    newData = false;
    Serial.print("Found RFID device: ");
    for (int i = 0; i < 16; i++) Serial.print(cardData[i]);
    Serial.println(".");
  }
} 

I've since read that external antennas can be hooked up, but creating one of these seems to be quite involved. Even though this ID-12 was the smallest reader available on Toys Downunder, there (after reading the datasheet) seems to be a slightly smaller one. It happens to be smaller since it doesn't include an internal antenna. Either way, if you choose to make your own, you may well be able to lay it in the trackbed. Otherwise, you can just shove a reader like this ID-12 into a trackside building or at the back of a engine shed to know which loco has arrived.



Initial testing showed that the Buttons could be read through my Thunderbird B-Train Shorty with motorised chassis; although the chassis wasn't powered at the time. I'll show the reader installed on a model railway in a future article.

16Feb/107

Wii Nunchuck + Arduino Mega + Model Railway = Fun

Well, it had to happen... I bought the header/adapter from here and then, after a little rewiring to fit the Arduino Mega, got the Wii Nunchuck reporting data to my Arduino. Note that this has been done already in multiple places:



If you have an Arduino Mega, then make sure you have the Negative pin to GND, the Positive to 3.3v, the "d"/"data" pin to SDA20 and the "c"/"clock" pin to SCL 21.

You can then use this code to get the little train moving:

#include <Wire.h>
#include "nunchuck_funcs.h"
#define PWM_INPUT_PIN_1         2
#define PWM_INPUT_PIN_2         3
#define PWM_ENABLE_PIN_1        7
int throttle = 0;
int loop_cnt=0;
void setup() {
  Serial.begin(19200);
  nunchuck_setpowerpins();
  nunchuck_init(); // send the initilization handshake
}
void loop() {
  if( loop_cnt > 100 ) { // every 100 msecs get new data
    loop_cnt = 0;           
    nunchuck_get_data();
  }
  loop_cnt++;
  throttle = nunchuck_joyx() - 127;
  if (throttle < 10 && throttle > -10) throttle = 0;
  UpdateTrackPower();
}
void UpdateTrackPower() {
  if (throttle == 0) {
    digitalWrite(PWM_INPUT_PIN_1, LOW);
    digitalWrite(PWM_INPUT_PIN_2, LOW);
  } else {
    if (throttle > 0) {
      digitalWrite(PWM_INPUT_PIN_1, HIGH);
      digitalWrite(PWM_INPUT_PIN_2, LOW);
    } else if (throttle < 0) {
      digitalWrite(PWM_INPUT_PIN_1, LOW);
      digitalWrite(PWM_INPUT_PIN_2, HIGH);
    }
  }
  analogWrite(PWM_ENABLE_PIN_1, abs(throttle));
}

Note that you need to have the L298 Motor controller from the previous post connected to get power to tracks!

Now I just need to think of a cool way to use the buttons on this controller. Currently I just have the top joystick controlling the train on the X axis with center being stopped.

8Feb/1038

Controlling your trains with an Arduino

A quick introduction to the Arduino

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino projects can be stand-alone or they can communicate with software on running on a computer (e.g. Flash, Processing, MaxMSP).

The boards can be built by hand or purchased preassembled; the software can be downloaded for free. The hardware reference designs (CAD files) are available under an open-source license, you are free to adapt them to your needs

Using it on your Model Railway

So, I recently purchased an Arduino Mega Microcontroller with the intent to control a Model Railway. This article will be the first in a series to show you how to use an Arduino to control different areas of a layout. Our first goal will be to create a controller/throttle with very basic Acceleration/Braking and a 12v DC Pulse Width Modulated output.

Note that this will all be based on DC electronics; this has nothing to do with DCC.

First, here's a list of web resources for controlling a 12v output with the Arduino:

What I created

In the end I chose to use the schematics and information from the guys at pyroelectro.com which uses the L298 H-Bridge integrated circuit. My main reasoning was that, although they used a PIC microcontroller, they correctly controlled the L298 with PWM on it's input rather than it's enabling pin. Either way, the PWM signal is still created...

Here's the schematic. I've added a few extra buttons and LEDs and also added a potentiometer for speed control.

Model Railway Control Schematic

Notes:

  • The IC is facing towards the viewer (i.e. so that the text on the IC is visible.)
  • It's also recommended to use a heatsink!
  • Ensure that you connect the ground(GND) on the L298.. It'll overheat and fry if you don't.
  • You must use Ultra Fast Diodes for the flyback diodes. More information here

Right, what do you need to know?... The PWM pins are labelled on your Arduino board. By default they output a PWM signal when you feed an analogWrite(pin_number) to them. This creates a pulse that the H-Bridge will respond to. The frequency of this pulse (wave) will then govern the final output voltage to the tracks.

For direction control you either apply digitalWrite(HIGH) to PWM2 and digitalWrite(LOW) to PWM3 or vice versa for the opposite direction. Applying LOW to both pins will stop the output and HIGH to both will short circuit!

I've added S1 and S2 to control my direction. It starts off going 'forward', but pressing S2 will set the direction to backwards. The code is written to gradually stop and then accelerate in the opposite direction. Pressing S1 will then set the direction forwards again and the reverse will occur.

S3 is the emergency stop button. Resetting the throttle to zero will cancel the emergency stop flag.

The potentiometer is the throttle... I found a huge one at an antique store down the road and love it. It's rated at 250ohm (no idea what current) and when at '100' the analogRead reports just over 1000. The throttle is only for speed, I really should add a brake lever, as when you return to zero speed the train will only gradually stop. You need to then hit the reverse (or emergency stop) button to stop the train faster.

You'll also require a 12v DC power supply. As your little engines may use up to 1A when starting, make sure this power supply is sufficient. Also, if you don't intend to have the Arduino plugged in to a computer after programming, then this 12v can also supply it (connect all ground wires together!). Just make sure it's a regulated and safe power supply. Note that different Arduinos can handle different voltages! Find your board listed here and then work out the power supply details, otherwise the Arduino Mega details are here (Input max 20v DC).

Source Code

The source code can be downloaded here.

Photos

Here's a few shots of the current set up:

Arduino Mega

Potentiometer in action

Please do ask any questions you have about this... I've probably skimmed over a lot and am more than happy to update this as necessary. I intend on getting on to more interesting things with this controller as I get the time.

18Jan/100

Melbourne – The Southern Spirit

Great Southern Railways (or GSR) is a long distance train operator in Australia operating famous trains such as The Ghan, The Overland and The Indian Pacific. In 2008 they announced that they were going to run a service that brought all of their current services together, including a trip to Brisbane, to be known as the Southern Spirit. Unfortunately, due to the 'Global Financial Crisis', this service did not run in 2009... being postponed for a year.

So, after returning from Japan, I noticed a thread on Railpage titled 'Loco hauled passenger services...' and realised they were talking about the Southern Spirit. This brought back all the feelings of anger from last year when I'd heard it was to be completely cancelled... I was excited back then since the train was to make an overnight stay in Canberra! It also made me realise how much people had forgotten (or ignored) the service altogether, as it seemed like a pipe dream.

Anyway, the service was now running, and was to make a stopover in Melbourne on a weekend... perfect timing. It turns out Saturday was to be great weather, so I chose the beach instead, but the train was to depart for Sydney on Sunday the 17th December and I was going to capture it.

Just a note, the full album of photos and videos is located here.

Departing Melbourne

The consist and loco had spent the night in Dynon Yard which is a large area of freight and maintenance operations in Melbourne. I jumped on my bike on Saturday evening and could see the consist from Mooney Ponds, but couldn't get a good shot of it. I did at least confirm that the train existed and could also determine it's approach to Southern Cross Station the next morning.

I made it to North Melbourne Station at 9am on Sunday morning and then proceeded towards Southern Cross following the railway. Most of the lines running are broad gauge, but there is a single standard gauge flyover from the yards to the Southern Cross a little further south of North Melbourne station. Here I waited for the service to move in.

Whilst waiting I saw a few things I didn't expect. It turns out that the second line on the flyover is broad gauge and is used quite a lot!

At around 1010 NR85 could be seen long-end-leading (which is extremely unusual for an NR) towards the flyover from Dynon Yard. It proceeded slowly over the gradient and then down towards Southern Cross.

From here, as I was on foot, caught a suburban to Southern Cross and took a few more pics of the train.

I then jumped on the next Footscray-bound service and found a spot trackside halfway between Footscray and Middle Footscray. Of course, there just had to be a passing EMU as I was recording a video of the Spirit leaving Melbourne.

Whilst returning to Flinders Street, I saw a freight service heading south towards Southern Cross Station. The EMU I was on managed to beat it to Flinders Street and I got a few shots of it passing through the station.


Shots from Eureka Tower

Unrelated, I've also been up Eureka Tower lately and got a few shots of the return freight service.


10Jan/102

Osaka (incl. the M250 Super Rail Cargo)

Due to having a lot of friends in the Kansai area, I'm always found basing my holidays in Japan from Osaka. Sure, the trains have less colour and there are no where near as many networks as Tokyo, but there's something about the city, it's warmth and, of course, the people. Did I mention trains? Also the trains.

I'm usually found loitering around Shin Osaka station (both photographing and residing) as it's the only place to get on the Shinkansen and also has a lot of limited express services stopping through. I usually stay in the same place; a room rented out by a Japanese citizen for a very good deal, but this time his apartment was booked. I instead ended up near Noda Station (on the JR Osaka Loop Line) and had to, more or less, start my learning of the timetables and networks from scratch. Of course, due to JRs punctuality and level of service, I really had no issues getting around... It just meant getting up 30 minutes earlier if I wanted to jump on a Bullet train.

One good bit about the Loop Line is that it's not all just boring local trains. It so happens that I was in the 4th quarter of the line (counting clock-wise from Osaka Station) and therefore only 2 stations from Osaka itself. This was really convenient, but also meant that I was on the Limited Express line (that bypasses Osaka and goes direct from Shin Osaka to Fukushima) that is also used for freight!

Of course, it wasn't until my last day that I actually saw freight on the line, as you either have to fluke it and see standard container trains to the port out near Universal Studios Japan or wait until around 11pm to see the M250 Super Rail Cargo leave. Since I'd found out the timetables of the M250 prior to this trip, I'd known what to do this time (instead of just seeing it shoot by when stumbling home from karaoke) and got in position to get a photo of the damn thing.

M250 Super Rail Cargo

My first attempt to see this train was on a weeknight from Noda Station at 10pm, heading to Ajikawaguchi Station (which is right next to the yards where the M250 is loaded.) Upon arriving, I saw the M250 cab lit, but also noticed that the Sagawa Transport trucks were still speeding into the yard in quick progression. I watched (walking from Ajikawaguchi Station up to USJ Station) as the trucks drove in, lined themselves up in a queue and then were unloaded by forklifts. They all knew exactly which car number (flat wagon in the consist) to drive up next to. The forklift would then pick up the container, the truck would drive off and the forklift would place the container on the train.

I soon realised, as I walked along the yard towards USJ, that there were only about 3 or 4 more containers left to load... and those trucks were already in the queue waiting to be unloaded! Hence I started speeding up my return, on foot, to Ajikawaguchi, as this is where the M250 would join the Yumesaki line (the line from the Loop Line to USJ/Sakurajima), as this would provide a good vantage point for a photo. Turns out I couldn't get a clear or steady shot without a tripod, so a movie was to be it.

All of a sudden this random music started playing (turn the volume up on the movie, you can hear it at the start) over ALL speakers in the yard... I thought the Thunderbirds were about to arrive. Then I heard a very feeble train horn and, before I knew it, the M250 was departing. It was 2304 and I looked at the timetables on the platforms at Ajikawaguchi... there were to be no trains for the next 4 minutes, a perfect time for this high-speed freight service to depart. And it did! It accelerated quite quickly, passed onto the left line and then disappeared out of sight.

Of course, I then wanted to get this train at another station along the line. I tried again the following Sunday and but I only got to see the consist shut down in the yard and partially loaded. As I arrived at Ajikawaguchi Station, the lights in the yard started shutting down row by row (around 2250) and I could tell that an employee was walking along the yard, manually switching them off. Fail for this night to get a movie.

I then ran out of time in Osaka to get another shot. The train departs at a bad time, as its always when you've had your fill of shabu-shabu, you've sung a few songs at karaoke and you're just not ready to leave the booth! Of course, the last loop line train is also sometime just after midnight, meaning a run to get a video of a train is usually always out of the question. The only real vantage points are at Nishikujo, Noda and Fukushima Stations which are out of the way from where the nightlife is.

Hence I only have the above video... but I'm glad I saw the train, finally... functional.

Umeda Freight Yards

Another favourite place of mine is the Umeda Freight Yards north-west of Osaka Station. This yard seems to be shrinking everytime I go there (due to construction of new buildings), but is often receiving traffic as the west-most lines are dedicated to freight from Shin Osaka and further on to Kyoto. These lines are also shared by the limited express trains that bypass Osaka Station. This includes the Ocean Arrow, Kuroshio and Haruka (to name a few.) Seen below is a Haruka service returning from Kansai International Airport to Kyoto via Shin Osaka. The lanes are also used by the M250 on it's way to Sakurajima.

EF66-29 stabled

DE10-1527, DE10-1575, EF210-9

DE10-1527

JR Freight Yards Umeda

Noda Station

This station on the loop line has meant nothing at all to me before; infact I resented stopping at it on local trains as I would have been able to get to Osaka quicker if it hadn't existed. This trip was, of course, different as it was my closest station. I also had Noda-Hanshin but my JR Railpass dictated a lot of travel paths.

Railway Library... 180yen for 30minutes access.

On the south side of the station is a "Tetsudou Toshokan" or "Railway Library". It turns out you can pay 180yen for 30minutes of access to everything they had available. I snuck a peek from the stairs and saw shelves of maps, diagrams and manuals... but didn't enter. They'd only be picture books to me! (Unfortunately..., this shop has now closed as of 2017)

On my last day I took advantage of the sunset and photographed everything coming towards the station (actually, I lie, most of this was from Nishikujo, but the effect is the same.) I was impressed to see a freight locomotive coming towards me and laughed when I saw it towing only 2 flatbeds to Sakurajima.

EF210-5 heading to Sakurajima Yards


Sakurajima Station

This is the end of the Yumesaki line, whose main purpose is to serve Universal Studios Japan. I just thought I'd add in some photos of the USJ liveried loop line EMUs.

8Jan/102

Sapporo and the Oigawa Railway

The Oigawa Railway is still my favourite railway in Japan (Second is the Eizan/Eiden Dentetsu in Kyoto) and I, again, visited it on my most recent trip to Japan. I also went back up to Hokkaido, this time actually spending time in Sapporo and returning via a different Night Train.

Sapporo

Two words... "Damn cold". I think we averaged around 3 degrees celsius whilst there but loved every minute. Crossing road intersections was a deadly game as you quickly found the ice under the snow and watched as either you or others around fell flat on their asses. All this snow also gave express trains a challenge, but the effects are magical when you get to see one at full speed.

I actually started from Hachinohe and took the Super Hakucho and Hokuto to get to Sapporo. There was no snow falling in Hachinohe but the ground was icy. As we got closer to Aomori the snow on the tracks got thick (I love the front windows in both express services) to the point where you couldn't actually see the rails. I was disappointed to not see any snow plough trains in action.






I didn't really get to venture out too far, but the first night there was spent in Otaru. This is a beautiful "canal city" and I happened to stumble upon a steam locomotive when first arriving.

SL at Otaru

Diesel helping SL at Otaru

Unfortunately it was cheating with a DE10 up it's rear end. Of course this is required as a fail-safe on mainlines, but you could hear the DE10 doing a lot of the work.

Returning to Sapporo I saw all sorts of services and also rode on the Super Kamui and happened to see one pass another.

Super Kamui at Sapporo

I returned to Osaka overnight on the Hokutosei. I travelled from Sapporo just after 1700, arriving at Fukushima at 0600 to swap to the Tohoku Shinkansen and then the Tokaido Shinkansen. Swapping to the Shinkansens early (instead of sleeping through to Tokyo) meant I saved around an hour and a half in transit.


Oigawa Railway

This trip started from Osaka, with a detour via the Entetsu Railway and Tenryu Hamanako Railways:


Oigawa Railway is a third sector railway running from Kanaya (JR Hokkaido Line) to Senzu, known as the Main Line, and then through to Ikawa on the Ikawa Line. The line was built to transport equipment and materials to build a dam on the Oigawa River. The Ikawa line is partially a rack railway due to the gradients in some places.

My trip involved travelling through to Okuizumi on the Ikawa Line and staying at the Okuooi Ryokan (highly recommended). I returned via the SL the next day and I also totally recommend this. It was the christmas day special and I booked ahead on their website.

I took a lot of photos, you can find the whole album here... but here are a select few:

Oigawa Railway Station at Kanaya Oigawa Railway workmen Rail ladder Rail ladder Nankai 21000 Series

Nankai 21000 Series

Stuffed and Mounted

21000 Series at Senzu Station

Stuffed and mounted

The highlights were the workmen at the start pushing a rail ladder along, the manual operation of the turntable and the in-car entertainment on the way back!

I'll be returning again...