Subscribe via RSS
17Jan/118

Arduino + Dreamcast Densha-De-Go Controller

I've had Densha-De-Go and the controller for the Dreamcast for a while now... I'd even invested a few hours in playing the actual game, but the accuracy required is crazy. Supposedly in Japan it's that realistic that even real train drivers have a hard time getting it spot on :)

Anyway, I'd wanted to get this going for train control for a while after managing to make a Wii Nunchuck control my trains.

DSC03710 DSC03712 DSC03715
DSC03707 DSC03698

You can find more information on the controller at SEGA Retro, SEGAGAGA Domain, Wikipedia, Play Asia and genki Video Games.

Previous attempts

Quite a few months ago I spent a few hours with my Densha-De-Go controller and my Arduino Mega in an attempt to get them to communicate. The goal was to be able to read the controller and then use it to control my model railroad. Unfortunately, I was doing this blind, running off information from Marcus Comstedt's 'Dreamcast Programming' site; specifically his breakdown of the Maple Bus Protocol.

I ended up with nothing working and sent out a few pleas for help on the Arduino forum and to Marcus himself. I received information regarding the fact that it should work (the Arduino had the horsepower), but I would have to ensure the timing was intricate and that the Arduino was always ready to receive data.

I then posted to the Arduino Forum for help. A few months later WzDD came to my rescue with word that he had successfully made the Arduino communicate with a Dreamcast Controller. I hadn't had much time up until now to work on this, and WzDD hadn't done any further work on it, so I took it that he just wanted to prove the concept and that I'd have to get off my backside to make things progress further. In the end, I did want to get my controller functioning.

I had previously had everything I needed to test this again, so I gave it another go. My previous setup was a cut-in-half Dreamcast controller extension cable and my Densha-De-Go controller. The extension cable meant I didn't have to hack around with the actual controller or port imitation.

Getting set up...

Due to the requirement to use assembler for the actual low-level controller interactions, we cannot use the Arduino IDE and must use WinAVR (or just avrdude on Linux.) Download this from here (select the latest version) and install to the default directory.

You then need to download the arduino-maple source code and extract somewhere locally. I've put the folder on C:\arduino-maple\.
Open Programmers Notepad [WinAVR] from the start menu and then open the arduino-maple.cpp file from where it has been extracted. (C:\arduino-maple\arduino-maple.cpp in my case.)
If all is installed correctly, then you should be able to choose Tools - [WinAVR] Make All and have the following output in the output window:

> "make.exe" all
avr-gcc -Wall -g2 -gstabs -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -ffreestanding -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=16000000UL -I./arduino -c arduino/pins_arduino.c -o build/arduino/pins_arduino.o
In file included from arduino/wiring_private.h:30,
                 from arduino/pins_arduino.c:26:
c:/winavr-20100110/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>."
...
Lots of warnings, no errors...
...
avr-g++ -Os -Wl,-gc-sections -mmcu=atmega328p  build/arduino/pins_arduino.o build/arduino/WInterrupts.o build/arduino/wiring.o build/arduino/wiring_analog.o build/arduino/wiring_digital.o build/arduino/wiring_pulse.o build/arduino/wiring_shift.o build/./arduino-maple.o build/arduino/HardwareSerial.o build/arduino/Print.o build/arduino/Tone.o build/arduino/WMath.o build/arduino/WString.o build/./libmaple.o -o app.elf
avr-objcopy -R .eeprom -O ihex app.elf  app.hex
avr-size --format=avr --mcu=atmega328p app.elf
AVR Memory Usage
----------------
Device: atmega328p

Program:    3380 bytes (10.3% Full)
(.text + .data + .bootloader)

Data:        796 bytes (38.9% Full)
(.data + .bss + .noinit)

> Process Exit Code: 0
> Time Taken: 00:02

Now, as you can see above... that's not my Arduino! I have an Arduino Mega and therefore we need to adjust the Makefile correctly for my setup. Here you'll need to know the CPU code, interface type and the port number. Also make sure you change the upload task to program so that we can use the menu items in WinAVR.

# Makefile for building small AVR executables, supports C and C++ code
# Author: Kiril Zyapkov
# Hacked up by nfd
 
SOURCE_DIRS = . arduino
INCLUDE_DIRS = arduino
MMCU = atmega1280
F_CPU = 16000000UL
SRC_ROOT = .
BUILD_DIR = build
 
CFLAGS = -Wall -g2 -gstabs -Os -fpack-struct -fshort-enums -ffunction-sections \
 -fdata-sections -ffreestanding -funsigned-char -funsigned-bitfields \
 -mmcu=$(MMCU) -DF_CPU=$(F_CPU) $(INCLUDE_DIRS:%=-I$(SRC_ROOT)/%)
 
CXXFLAGS = -Wall -g2 -gstabs -Os -fpack-struct -fshort-enums -ffunction-sections \
 -fdata-sections -ffreestanding -funsigned-char -funsigned-bitfields \
 -fno-exceptions -mmcu=$(MMCU) -DF_CPU=$(F_CPU) $(INCLUDE_DIRS:%=-I$(SRC_ROOT)/%)
 
LDFLAGS = -Os -Wl,-gc-sections -mmcu=$(MMCU) #-Wl,--relax
 
TARGET = $(notdir $(realpath $(SRC_ROOT)))
CC = avr-gcc
CXX = avr-g++
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AR  = avr-ar
SIZE = avr-size

SRC = $(wildcard $(SOURCE_DIRS:%=$(SRC_ROOT)/%/*.c))
 
CXXSRC = $(wildcard $(SOURCE_DIRS:%=$(SRC_ROOT)/%/*.cpp))

ASMSRC = $(wildcard $(SOURCE_DIRS:%=$(SRC_ROOT)/%/*.S))
 
OBJ = $(SRC:$(SRC_ROOT)/%.c=$(BUILD_DIR)/%.o) $(CXXSRC:$(SRC_ROOT)/%.cpp=$(BUILD_DIR)/%.o) $(ASMSRC:$(SRC_ROOT)/%.S=$(BUILD_DIR)/%.o)
 
DEPS = $(OBJ:%.o=%.d)
 
$(BUILD_DIR)/%.o: $(SRC_ROOT)/%.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/%.o: $(SRC_ROOT)/%.S
	$(CC) $(CFLAGS) -c $< -o $@
 
$(BUILD_DIR)/%.o: $(SRC_ROOT)/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@
 
all: app.hex printsize

#$(TARGET).a: $(OBJ)
#	$(AR) rcs $(TARGET).a $?

app.elf: $(OBJ)
	$(CXX) $(LDFLAGS) $(OBJ) -o $@
 
$(BUILD_DIR)/%.d: $(SRC_ROOT)/%.c
	mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -MM -MF $@ $<
 
$(BUILD_DIR)/%.d: $(SRC_ROOT)/%.cpp
	mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) -MM -MF $@ $<
 
#$(TARGET).elf: $(TARGET).a
#	$(CXX) $(LDFLAGS) $< -o $@
 
app.hex: app.elf
	$(OBJCOPY) -R .eeprom -O ihex $<  $@
 
 
clean:
	echo $(RM) $(DEPS) $(OBJ) $(TARGET).*
 
printsize:
	avr-size --format=avr --mcu=$(MMCU) app.elf

# Programming support using avrdude. Settings and variables.
PORT = /dev/tty.usbserial-A700ekGi
#PORT = /dev/ttyUSB0
AVRDUDE_PORT = com3
AVRDUDE_WRITE_FLASH = -U flash:w:app.hex
MCU = atmega1280
AVRDUDE_PROGRAMMER = stk500v1
#AVRDUDE_FLAGS = -V -F -C \app\arduino-0021\hardware\tools\avr\etc\avrdude.conf 
AVRDUDE_FLAGS = -V -F \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE)
UPLOAD_RATE = 57600
#
# Program the device.
INSTALL_DIR = \app\arduino-0021
AVRDUDE = avrdude
program: app.hex
	#python pulsedtr.py $(PORT)
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)

The first line in the program target (Line 93) 'pushes' the reset button on the Arduino. As we don't have Python installed we have to do this manually. So, build the source code via the [WinAVR] Make All and ensure there are no errors. Now press the 'reset' button on the Arduino and then quickly choose Tools - [WinAVR] Program. If all goes correctly then you'll see the code uploading to your Arduino:

#python pulsedtr.py /dev/tty.usbserial-A700ekGi
avrdude -V -F -p atmega1280 -P com3 -c stk500v1 -b 57600 -U flash:w:app.hex
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e9703
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "app.hex"
avrdude: input file app.hex auto detected as Intel Hex
avrdude: writing flash (3508 bytes):

Writing | ################################################## | 100% 1.09s

avrdude: 3508 bytes of flash written
avrdude done.  Thank you.

> Process Exit Code: 0
> Time Taken: 00:03

And that's it, our the compiled code for the arduino-maple project is now on the Arduino and running!

Using the Python code on Windows

I lied, I said I didn't have Python installed... but I ended up installing it anyway. The job to convert the Python code to C# was going to take too long and, to prevent a debugging nightmare, I decided I would get the known-to-work Python code going under Windows first. So, I installed Python from the official website and then started learning :)

Note that I downloaded and installed Python Version 2.6.6 as this was the version that would have been available when arduino-maple was created.

After selecting 'IDLE' from the start menu, I was presented with a light-weight GUI. I opened up the 'maple.py' that's included with the arduino-maple code and attempted to compile it.

I had problems at the start, as in the included Makefile there are two declarations of CPU type. Initially I hadn't set these both correctly and the Arduino includes were not correctly compiled... make sure you carry out a proper clean whenever changing code; this includes manually deleting all of the .o files.

Once this was sorted, it all finally worked... sort of?

connecting to COM3:
connected
SENT: 0000200121
No device found at address:
0x20
SENT: 0000010100
1c20000501000000ff0f3f000000000000000000415400ff204f544920313030746e6f436c6c6f7
2202072652020202020200024191bdc94191958dd481e508815481c9bdc99591b98da5308195
cdb995bdc91881154c8c9b40481051d491551394d25494130b14d1480b911508080808007d00371 117
Command 5 sender 0 recipient 20 length 1c
Device information:
Functions  : CONTROLLER
Periph 1   : 0x3f0fff
Periph 2   : 0x0
Periph 3   : 0x0
Name       : ..TAITO 001 Controller      $.  
License    : .....X...P.H..H..Y...S....\....[..T.....Q.I.I%M9M.0A.......P
Power      : 53251
Power max  : 32775
Play with the controller. Hit ctrl-c when done.
SENT: 010020090100000029
SENT: 010020090100000029
1111101010011111
SENT: 010020090100000029
1111101010011111
SENT: 010020090100000029
1111101010011111
SENT: 010020090100000029
1111101010011111

Timing issues

As I continued to run the code, I would get random results as to the 'Name', 'License' and 'Power' fields... well, it was obvious in the text fields that there were problems, but I had no idea that what the 'Power' fields were meant to read. Either way, this indicated a timing issue somewhere and I guessed that life was about to get difficult. Note that I had always been running the controller at 5v, as that's what WzDD's post said the blue wire should be connected to, but it turns out that the device should have actually been running on 3.3v.

Unfortunately, setting the controller on to 3.3v didn't change anything... the responses were still mildly random. The buttons would be sent though correctly (apart from the B button) but the initial device description would come through jumbled. I took a few samples of the data and realised that the data would always have a minimal length. To me this meant that we weren't missing bytes/bits, but actually reading too many. The analysis showed that there were similar chunks all the way through, but at certain intervals there'd be extra/changed characters. Based on Marcus Comstedt's Maple Bus information, I guessed that we were re-reading bits too quickly and needed to slow down a little... This would mean slowing down the pin reading in WzDD's arduino-maple assembler code.

In the maple_rx_raw: function down near _rx_loop:, the code iterates through the pins hoping to read the data. It initially checks the state of the pins to sense when the controller is about to send data, but this did not have the final check for the second pin going low.

4:	IN rport2, _SFR_IO_ADDR(PINB)
	BST rport2, bitmaple5			; maple5
	BRTS 4b							; must be low now

The above code was added around line 305 to ensure this check was in. I then also 'spaced' out the store/read calls by placing a delay in. WzDD had already written the delayquarter macro and I simply re-used this.

	...
	_rx_store rport bitmaple5 5
	_rx_read bitmaple5
	delayquarter
	_rx_store rport bitmaple1 4
	_rx_read bitmaple1
	...

After these two changes, the text from the device information call worked flawlessly. But my B button still didn't work. I decided the B button wasn't important at this stage and went on to decoding the controller to work out how the levers functioned.

Densha-De-Go controller workings

So, after having used the standard Dreamcast controller to play hours-upon-hours of Shenmue, Shenmue II and Chu chu rocket, I would have expected at least one of the levers on the Densha-De-Go controller to use the analog joystick and the other to also use some form of analog control. After a few minutes decoding the controls, it became apparent that they simply used the buttons available (up, down, left, right, x, y, z) in a binary-value style configuration.

Throttle Position X Y Z
T0 [x] [x]
T1 [x] [x]
T2 [x]
T3 [x] [x]
T4 [x]
T5 [x]
Other Buttons Mapping
SELECT D
START START
A A
B ??
C C
Brake Position UP DOWN LEFT RIGHT
B0 [x] [x] [x]
B1 [x] [x] [x]
B2 [x] [x]
B3 [x] [x] [x]
B4 [x] [x]
B5 [x] [x]
B6 [x]
B7 [x] [x] [x]
B8 [x] [x]
EM0 [x] [x]
EM1 [x]
EM2 [x] [x]
EM3 [x]
EM4 [x]
EM5 - - - -

In between the B's there is a slight overlap of the buttons, where the current and next 'combination' is combined, but this doesn't seem to last more than one cycle.
In between the EM's the controller reads UP-DOWN-LEFT-RIGHT. This area exists between all EM's and B8-EM0 and seems to be about 3mm wide.

Controlling trains

Now it was time to get this incorporated into my original train throttle. I didn't want to have to use the Python code, so instead I 'crafted' the packets into the Arduino code.

	//here is a quick packet to request device information from controller 'one'.
	//i.e. the only controller connected.
	packet.header[0] = 0; // Number of additional words in frame
	packet.header[1] = 0; // Sender address = Dreamcast
	packet.header[2] = (1 << 5); //(1 << 5); // Recipient address = main peripheral on port 0
	packet.header[3] = 1; // Command = request device information
	packet.data[0]   = 0x21; //checksum
	packet.data_len  = 5;
	//send the above packet to initiate comms with the controller.
	maple_transact();

I'm going to gloss over this part pretty quickly, as this post was more about getting the Dreamcast controller usable rather than another lesson in physics and model railway throttles. For the code, I ended up just deciphering the packet that comes back from the controller, working out what the throttle position is and then adjusting the target speed. The main program loop then makes then increment/decrements the current speed to eventually match the target speed. This provides a very simple form of acceleration.

void control_throttle(void) {
	//quick hack, should actually do a binary 'and'
	//packet data[6] contains the throttle position, so use this to gauge
	//voltage output to pin 7 (or speed)
	switch (packet.data[6]) {
		case 0xF9: target_speed = 0;	t_pos = 0; break;
		case 0xFA: target_speed = 88;	t_pos = 1; break;
		case 0xFB: target_speed = 96;	t_pos = 2; break;
		case 0xFC: target_speed = 140;	t_pos = 3; break;
		case 0xFD: target_speed = 190;	t_pos = 4; break;
		case 0xFE: target_speed = 250;	t_pos = 5; break;
	}
}

The changing of pin 13 below lights the on-board Arduino LED to show once the loop has made the speed match the target speed.

	digitalWrite(13, LOW);
	if (target_speed > speed) {
		//accel
		speed += t_pos / 2;
	} else if (target_speed < speed) {
		//speed += abs(target_speed - speed);
		//decel
		speed--;
	} else {
		digitalWrite(13, HIGH);
	}
	//send the speed to the pin/railway
	analogWrite(7, speed);

And then... it just worked :)

DSC03744

Download the source code here.
Note that this does not include the Python code; nor will my code correctly interact with the python code anymore. The goal was always to have the Arduino talk to the Dreamcast controller directly.

As you can see, I've only implemented the throttle on the controller... I need to now bring in the brake lever as well, but this is where the physics lesson comes in. I'll be posting again soon enough with source code for acceleration and braking using this controller.

I've got a few ideas as to how to semi-realistically control the train with both levers, but I will need to do a little more reading before I get something going. I do know that in the actual Densha-De-Go game, the game complains when you have both levers on at the same time... and it seems wrong to be doing so... but then again, it'd be like doing a hill-start :) Maybe for freight trains?

If only our model railway trains had gears and could free roll!

7Jan/110

Canberra to Queensland

I'd been invlted to the Gold Coast for NYE 2010 and so I thought I'd make an adventure of it and go by rail. Google Maps indicated that, via the Pacific Highway, the distance is 1,130km and, by car, it would have taken around 14 hours. I wasn't going for a land-speed record (and this isn't Japan) so I decided to take a relaxed path via Country Link (which does happen to be the only regional rail transport that travels north nationally.) This trip was to go via Sydney, Maitland (the start of the Hunter Valley) and then the north coast (overnight) to Brisbane. I could have chosen to switch to a bus at Grafton/Casino, but I didn't feel like changing transport at some gawd-awful time in the morning and a bus didn't appeal to me. After arriving at Brisbane early in the morning, I was to change to QR and travel south to the Gold Coast, arriving around 8:00am.

Canberra

This trip started early at Kingston Railway Station in Canberra, ACT on Wednesday the 29th of December. This station (note that we are in Australia's capital) sees no more than 3 passenger train departures per day and 3 arrivals. These are even staggered so that every second day you can leave in the morning and afternoon, alternately with morning and evening on other days. Randomly inconvenient and it gets worse; the trip to Sydney (Central Station) takes around 4.5 hours. Meanwhile, if you are wanting to buy tickets for Country Link trains, I can only recommend to purchase them at Queanbeyan Station as it's run by the staff of the ARHS ACT and they get a commission.

Either way, we got off on time and stopped at Queanbeyan 10 minutes after leaving Canberra.

DSC02859 DSC02861 DSC02862

We then arrived at Bungendore around 30minutes later. As I had worked on the ARHS ACT trains, I knew I had enough time to grab a few photos as the whole line from Canberra to Goulburn still uses the 'staff' system. This meant that the driver had to exchange staffs in each of the signal boxes along the way.

DSC02864 DSC02866

At Tarago, the same thing had to happen and so I checked out the station. This was the final station on the Goulburn-Canberra branch before the train was to enter the "Main South". After this there were not going to be many other photo opportunities.

DSC02875 DSC02876 DSC02877

Sydney (aka. CityRail)

We arrived at Strathfield Station at some time after 10:00am after leaving Canberra at 6:43am. I then had about 6 minutes to change platforms and get onto a northbound express service. This service was to be run by CityRail which is the Sydney electric train network operator. They also run DMU services on non-electrified track.
This northbound train was to terminate at Wyong, but that was good enough, as I knew that there were freight services running over the "Main North" to keep me entertained there. I'd stopped by Wyong around 3 years ago and had seen a nice couple of RLs carrying freight southbound... unfortunately, we were well short of Wyong when the freighter stormed past, doing a great speed up the Cowan bank.
The CityRail fleet consists of all sorts of electric trains, but the northbound long-distance routes are covered by "V" sets (I believe) and they are ancient... Fortunately they are extremely comfortable and are even decked out with toilets and mildly-functioning air-conditioning. Really quite retro!

DSC02884 DSC02887 DSC02892
DSC02894

I therefore got off at Wyong and waited for the next service to Newcastle. I would only travel as far as Hamilton which is three stops before Newcastle and is the first station which intersects with the Hunter Line. Here I would transfer and then travel on the diesel service to Victoria Street where I was to stay overnight.
The DMUs used on the Hunter Line are two-car and I think nearly everyone of them had a flat-spot on one wheel somewhere.

DSC02905

Maitland and surrounds

Now, once in the heart of coal-country, it wasn't going to be too long until a coal train was to come hurtling past; it ended up being three, straight after each other. From what I gathered, the trains gave around 10 minutes minimum between each other when travelling in the same direction; but the paths were already clear well before.

DSC02913 DSC02921 DSC02927 DSC02934 DSC02942

After realising I could see coal trains all day, I packed up the camera and checked in to my hotel. Once settled, I then headed back to Warabrook Station and checked out the action. This station is located between Islington Junction and the other triangle (Koogarang Junction?)... although the double-triangle is probably known as Islington Junction. Either way, coal trains would be entering from all directions and I wasn't disappointed.

DSC02973 DSC02976 DSC02990
DSC02997 DSC03011

So, random light engine movements, but no coal trains... it turns out I could see them, but none were coming from the Newcastle direction. I therefore jumped on the next westbound train and got off at the next station past the triangle: Sandgate.

DSC03021 DSC03023 DSC03027
DSC03031 DSC03037 DSC03047
DSC03083 DSC03101 DSC03107
DSC03108

Day two

I was to catch the 6:65pm XPT from Maitland Station to Brisbane and therefore had the whole day to check out what was happening around the Hunter. I dumped my bags at Maitland Station and then proceeded to loiter at random points between Maitland and Newcastle. Fortunately, as soon as I'd sorted out my luggage, an 81 class + 2 48s rolled in with a grain consist. It turns out they were not going anywhere until the next DMU was through (thanks for that information from the drivers!) and therefore I took a few photos at Maitland Station and then waited for it at Sandgate.

DSC03129 DSC03130 DSC03135

At Sandgate, the main line is elevated over the coal lines to Koogarang Island. I was told by the grain train drivers that they were to change onto the main line and proceed through to Broadmeadow yard. This meant that they would come over the hump... of course, I didn't make it to the platform end to get the 'perfect shot'... but it worked out OK anyway...

DSC03164 DSC03167

I loitered at Sandgate and was lucky to see QRs new liveried 50 class.

DSC03177 DSC03180 DSC03186

The rest of the afternoon...

It was too hot by 11:00am to be hanging around in the sun and so I travelled on to Newcastle and swam at the main beach. Afterwards I ventured back to Broadmeadow Station to see if there was anything interesting going on. Broadmeadow is at the mouth of a maintenance/storage yard for locomotives and wagons. Unfortunately I only got to see a coal train passing through.

DSC03194 DSC03198 DSC03201
DSC03202

Back to Warabrook Station

I had been on to a good thing the day before, and so I though I would return to see what else was moving around.

DSC03208 DSC03212 DSC03223
DSC03229 DSC03236 DSC03241
DSC03242 DSC03245 DSC03263
DSC03268 DSC03269 DSC03277
DSC03285 DSC03295 DSC03296
DSC03301 DSC03314 DSC03316
DSC03324

Overnight on the XPT

I'd done this once before, back in 2000 or so, and I can only imagine that I'd forgotten how difficult it was to sleep upright. We ran on-time all the way, but the track wasn't as smooth as it could've been.
Meanwhile, the view as the sun was setting north of Maitland was beautiful. Rolling green pastures and lots of stock roaming around or running from our train. Unfortunately, the sun set pretty quickly and the reflective tint on the outside of the windows meant that there was next to zero visibility.
Lights were out at 10:00pm and most people tried to sleep (some with very loud music in their earphones.) Sleeping wasn't too easy though, as there were stations all throughout the night and people were getting on and off the train, dragging their luggage and making enough noise to wake all the light sleepers up. Even better was the fact that the guy next to me wasn't meant to be there, so at 11pm we all had to shuffle around when the actual passenger arrived.
After a random amount of sleep, then sun started rising at 5:30am and the view from the train was undeniably suburban Brisbane. A lot of the houses we passed backed on to the railway line and didn't care much for fences. We finally arrived at Roma Street Station and then I transferred to the Gold Coast Line to Nerang.

DSC03342 DSC03345 DSC03348
DSC03352 DSC03357 DSC03359

Final words...

Until Australia cares for passenger trains... CountryLink will be the only option for east coast travel. The line has been primarily built for freight trains and therefore there is no regard for speed or smooth travel. They have done a lot of improvement work over the years, but again, population and demand is lacking to make any more of it.

I would recommend this trip be done during daylight as opposed to overnight. The view is spectactular and having had the sun up during the entire route would have been great. The only other way to do it would be via a sleeper compartment, but the cost will be quite prohibitive for the foreseeable future.

13Dec/100

Eizan Dentetsu (Eizan Electric Railway)

The Eizan Dentetsu (Official Site [Japanese Only]), known as Eiden for short (a combination of 'Eizan' and 'Dentetsu'), is a private railway in North-East Kyoto, Japan. This railway was originally owned by Keifuku Railways, but is now a wholly-owned subsidary of Keihan Railways. Prior to the purchase, Keihan had extended their Main Line to Demachiyanagi Station where the Eizan Railway starts to increase rider-ship in the Eizan Railway.

Location

The Eizan Electric Railway originally only had one main line from Demachiyanagi Station in the north east to Yase-Heizan-guchi, further north-east. This line was opened in 1925 and provided a gateway to Mount Hiei, a popular tourist destination in Kyoto. The branch to Kurama was opened in 1929 and has proved popular ever since. Both lines terminate at transfer stations where passengers continue travel on cable cars.

From 1978, Demachiyanagi Station was cut off from other forms of connecting transport when the Kyoto City Streetcars stopped running. Fortunately, in 1989 the opening of the Keihan Oto Line through to Demachiyanagi re-connected the Eiden to the wider network and made it easily accessible once more. The Eiden network had seen lower ridership in between 1978 and 1989, but it soon became popular once more.

Rolling Stock

The Eiden's rolling stock inventory consists entirely of EMUs running at 600VDC. The Deo 700 Series is a single-car EMU which usually runs along the Main Line.



The Deo 800 series is a 2-car EMU which usually runs up to Kurama.


And then my favourite, the Deo 'Kirara' 900 Series. This model was released by Kato and I have it in both the Maple Orange and Maple Red. It also received a prize (can't remember the exact name, 'Lauriel?') for it's design. It's internal seating allows the passengers to sit sideways and view the scenery along the route. It also has high observation windows.




Stations and Facilities

Ichiooji Station

Shugakuin Depot

Iwakura Station


Kurama

After getting off at the final stop, passengers transfer onto the Cable car and end up at Kurama. Here you'll find a temple and an onsen. Be careful though, I visited here in Winter of 2005 and it was very slippery and dangerous! (Then again, I'm probably just from Australia and don't understand snow :))




8Dec/100

Japanese Night Trains: Twilight Express

Night trains are becoming a thing of the past in Japan; but there should be a few that survive... hopefully the Twilight Express is one of them. This overnight sleeper train starts in Osaka and terminates in Sapporo, Hokkaido (and vice-versa.) The trip takes roughly 23 hours and traverses the west coast of the main island of Japan. There are two full consists of the Twilight Express to allow daily services from each end of the trip.

Sightings

I'd seen the train in Japan when I was there in 2008 but hadn't even thought of travelling on it.

The Twilight Express pulls into ShinOsaka

Twilight Express heads to Osaka Station

A ticket in hand

My next trip to Japan was to be in 2009 and I was determined to get on the train. I hadn't had many spare nights in Japan and the train had been booked out between Osaka and Sapporo on the nights I did have spare. This didn't deter me though, as the reverse trip wasn't booked out. Of course, I then had to get to Hokkaido first and I therefore took the Nihonkai (another sleeper train) to Higashi-Muroran (Hokkaido) and intercepted the Twilight Express as it returned to Osaka. I wasn't able to get all the way to Sapporo in time to meet the Twilight Express there. Higashi-Muroran was pretty cold; although it was the start of the Japanese summer, Hokkaido was still in the low teens (degrees) and I wasn't prepared.

The Nihonkai had arrived on time, giving me a 2 hour stop-over in Higashi-Muroran. There wasn't much rail traffic and so I ran to the nearest katsu curry restaurant to have my favourite dish. On returning to the station I didn't have to wait long to see those familiar blue DD51 diesels arrive. Of course, the lighting was dismal and my digital camera had no chance of catching them moving... I also had no time of getting to the front of the train to take a still shot.

Twilight Express enters Higashi-Muroran

First impressions

Upon entering the car (I was in a B Class Sleeper) I was presented with beautiful wooden walls and very well kept rooms. As you can tell, I settled in pretty quickly... I'd also brought a few goodies on board. The conductor came in quite soon after to say hello and to apologise for not being able to speak English. Fortunately, my limited Japanese meant we could work out all the formalities: the coin-operated shower was in the Salon Du Nord car, dinner was in allocated time slots: 7pm,8pm,9pm (if I remember correctly) and finally I had to choose what 'type' of meal I wanted for dinner and breakfast? Japanese or Western... I wasn't on the train for Western food!
I then realised I wasn't alone in my cabin and started making new friends. Soon enough another conductor came and found me and offered to change me into another room (still a B Class 4-person) but with me being the only occupant. I couldn't turn down their hospitality and so obliged.


Salon Du Nord

Once settled in I decided to wander around to see what the train had to offer; The first target was the famed "Salon Du Nord". What I found was an amazing observation car beautifully fitted out with very large windows and two TVs. The channels were selectable, but of course, everyone had to agree to you changing the channel :) ... I do believe I watched the same movie 3 times whilst on my trip... but I didn't mind as I was mainly staring out the window.
The car also included the coin-shower and a vending machine. You could also go to the dining car next door and order 'from the bar'. I happened to have a very lovely couple of obaachans talk to me and ask me about my travels... it was quite difficult trying to converse in my broken Japanese and recall all the polite grammar forms; but it made the trip even more enjoyable. It made me laugh when they didn't believe that there were people from other countries taking the relaxed approach on a sleeper train because they liked trains... I was glad to change their perceptions.

Twilight Express Salon du Nord

Dining

I, unfortunately, did not take a full shot of the dining car, but I can assure you it is as tastefully fitted out as the rest of the train. The staff are fantastic and I even had my waiter ask where I was from and what I was up to. Then then offered drinks and the menu which had quite a lot of options. I, if I recall correctly, had a very lovely dish of Japanese Karaage (fried chicken.)
For breakfast I was greeted by the same staff and selected the Japanese breakfast option. There was no menu to choose from, as it was a set breakfast and I was asked to take a seat, admire the great view and await the meal. All of a sudden I had 5 dishes on my table and all I can say is yum!

Twilight Express breakfast

I then bought my souvenirs; available from the dining car menu and returned to my room.

Other classes

I had chosen the 'shared' cheaper B Class sleeper rooms, but you could also have a completely private A Class sleeper room. This included a 1-seater sofa/couch which folded out into a bed. The A Class carriage also included a small communal room at one end.

Twilight Express B-Class lounge/vestibule

Twilight Express operations

Now comes the fun part of the trip. Both trains, regardless of direction, have an engine swap half way on their journeys. Actually... I lie... over the trip the train encounters a total of 4 engine swaps, but you can't get out and watch the other 3 of them.
The engine swaps are:

  • Twilight Express EF81 from Osaka to Tsuruga
  • Twilight Express EF81 from Tsuruga to Aomori Depot
  • Unknown (I didn't get to see it) EF from Aomori Depot to Hakodate Depot
  • Double Blue DD51 from Hakodate Depot to Sapporo

The reason for the swaps are very simple. Hokkaido isn't 100% electrified, so the diesels are required. They use two for on-time running more than gradient climbing. The diesels can't enter the Seikan Tunnel (Honshu to Hokkaido) and so the unknown EF (a stainless steel version) is for that section. The EF81s are then used for the rest of the trip, mainly for brand-recognition :)

Southbound engine swap: Tsuruga

So, after a sound nights sleep, we arrived in Tsuruga with a warning that we'd have to stop over for 10minutes whilst they swapped the engines. We (as they pretty much expected we were all train fanatics) were allowed out to take photos but were to return to the train as soon as the buzzer was heard.
Who could resist? I got out of the train and got to the front to see our first engine (EF81 113) already detached and heading south to the depot. I then walked further down the platform to take a shot of our train next to the Thunderbird that had just arrived. I could not believe the dirtiness of our consist; I hadn't expected an EF81 to cause that much build-up on the passenger car, but it could have been caused from the entire trip.
EF81 104 then started approaching to couple up to the train. It had been sitting in the yard ready to come up as soon as 113 had cleared the points. As soon as it 'clunked' onto the train and the air flowed the buzzer on the platform went off and everyone cleared back on to the train.


Final stations to Osaka

As we got closer and closer, more and more passengers departed at certain platforms. The train was actually scheduled to only stop at stations that passengers had designated to get off at; which is now quite obvious, as it was never going to pick any up. I had booked all the way through to Osaka, but was considering getting off at Kyoto... Unfortunately we were held up due to 'unfortuante circumstances' and I ended up just relaxing in the Salon Du Nord and getting back to Osaka an hour late.

Since this trip I've now also travelled on the Hokutosei and the Kitaguni. I still recall the Twilight Express as being the most memorable and stylish... but will endeavour next to get onto the Cassiopeia.

23Nov/100

V/Line Rolling Stock

I've now realised how many photos I'm burying in the depths of my Photo Album (specifically the Australian Railways Album) and so I'm going to throw a few sets together and post them here as I find the time.

First out of the yard is a collection of V/Line Stock. V/Line are currently repainting a lot of their diesel locomotives (and their V/Locity DMUs) in 'Hi-Vis' colour-schemes; somewhat reminiscent of the 'Candy' scheme I missed out on due to my age :)

Shots from around Southern Cross Station



V/Line on the flyover near North Melbourne Station



Passing Middle Footscray


Passing Manor Loop


And other locations...

29Oct/100

Melbourne and surrounds (October 2010)

Recently purchased a new camera (finally a DSLR!, well, actually a DSLT) and have been checking out the old haunts lately. Great timing too as we've just entered daylight savings.

Steam around Melbourne (and a trip to Seymour)

Steamrail are a Melbourne (Newport Workshops) based heritage rail operator and have quite a nice selection of rolling stock. Their R-Class Steam Locomotives are even licensed to run by themselves on the mainline...


El Zorro Freight

El Zorro is a small freight operator in Victoria who run both Standard and Broad gauge trains. Recently they have been running a grain train to and from Dynon using leased heritage engines in their original VR livery.


Queensland Rail

QR (who are about to be privatised) also run out of Dynon with large intermodal freight. They provide a nice change of scenery on the standard gauge with their LDP and G Class locomotives.



Sims St Junction (Pacific National Locomotive Depot)

At the west side of the freight are in Melbourne is Pacific National's Locomotive Provisioning Centre. Here you'll mainly see NRs getting fueled and services (with the occasional AN) and then either coupled light engine to head off to Spotswood or sent east to a rake of containers for haulage.


Melbourne-Sydney XPT

Poor old Countrylink can't win nowadays; The 'main south' from Sydney to Melbourne has been in the press nearly every day for the last few months as the ARTC bungle up the re-sleepering program (and duplication of the standard gauge.) Recently, due to their technique of sleeper replacement, the new concrete sleepers have not been seated correctly in the ballast and mudholes have resulted. This has caused some very rough riding for all trains and has even caused damage to XPT power cars and break-ups (uncoupling) of freight trains.
Seeing the XPT in Melbourne has become an unexpected treat!


81 Class shunting in Dynon

The intermodal container trains are (usually) shunted around by an 81 Class. This loco will put the empty flatbeds in the correct roads and also reconnect loaded container wagons. Sometimes this train must use the standard gauge track that leads to Southern Cross (Spencer Street) Station but it usually doesn't travel too far along. Fortunately, I was in the right place at the right time to see the 81 travel all the way down the other side of the flyover.


It also then shunts from the other end of the yard across the Dock Link Rd level crossing.


Another random sighting for this shunting maneuver was the original NRs pulling the consist half way up the flyover incline.

Track Machines

Lately there's been a lot of work down at Southern Cross Station for the addition of a new platform for the Regional Rail link debacle. This has meant track machines working during the day to lay new track or realign old lines. They return home each night via Sims St.


Middle Footscray

I tried Middle Footscray Station yesterday instead of the usual Sims St Junction and was impressed with the traffic that passed between 1800-1930.




And that's about it for now... Melbourne sightings are picking up now that daylight savings is here. It seems that early evening is the best time as well. You can can find the whole album that the above shots come from here.

25Oct/100

Osaka, Yodogawa, Koyasan and Nishi-Akashi.

Just to finish off displaying the photos I took whilst in Japan over September, here are the highlights from the Kansai area whilst chasing trains.

Noda, Osaka

Full gallery here.
As I was staying near Noda(JR) Station on the Osaka Loop Line, I was able get an elevated view of it from the building stairwell. Fortunately, this station is located between the Ajikawaguchi branch and Umeda, so I got to see the freight pass through, as well as the express services to Kansai Airport and Wakayama.


Southern end of the Umeda Freight Terminal

The west-most track of the Umeda Freight Terminal is used as a single-track bypass of Osaka station between Nishikujo and Shinosaka. Freight trains to Ajikawaguchi and all expresses to Kansai Airport and Wakayama (and further) use this track. Note the second last photo which shows the speed limits for a variety of express trains which travel this section of track:


Noda Hanshin Station

The Hanshin Railway runs from Umeda to Kobe. It is underground from Umeda Station before climbing above ground before Noda Hanshin Station. It does this just before the Osaka Loop Line, which travels over the top.


Noda JR Station

A favourite, Noda JR Station allows you to see for quite a while towards Nishikujo along some very straight track. This provides some great shots at full zoom of the loop line trains and other expresses heading south.


Yodogawa Bridge

This bridge provides a connection east of Osaka City for freight trains from Suita to Hirano in South Osaka. There have been rumours that it will also soon get it's own passenger service. The line is currently being upgraded.


Suita Station, Osaka

I walked back to Suita Station from Yodogawa Bridge hoping to see another service pass along the line; unfortunately the scheduled trains never arrived. Either way, once at Suita there was action in every direction.




Koyasan

Full gallery here.
I travelled with a friend on the back of his motorbike up to a temple in Koyasan, but on the way we stopped at a Gusto Restaurant near Nankai Mikkaichicho Station.




Nishi-Akashi Station

After spending a night in Ako City, I took my time returning back to Osaka and stopped by Nishi-Akashi Station. This is on the main line between Kobe and Himeji and sees a lot of freight passing through. Since it is a larger station, all passenger expresses stop, but the freight trains pass... so you knew when and where to look for them. Note that the first shot is from Ako station of the local to Himeji and the second and third are from Himeji Station.




15Oct/102

Sending full bytes over .NET Serial Ports to the Arduino

Ok, I have just spent a good two nights of my life diagnosing why I could send all bytes up to value '127' and no higher. In hindsight, it all makes perfect sense and the documentation is clear, but when you've been taught to think in strings, you might hit this very quickly.

The Scenario

I have my MAX7219 + LedControl Library set up on my Arduino and all works fine. I use two functions to control it: setLed and setRow. setLed simply takes a boolean to determine if the LED you are pointing at is to be on or off, but setRow requires a byte. This is all fairly straight-forward as each 'row' in the LED matrix has 8 LEDs, and a byte has 8 bits. So, starting from the lowest significant bit, a value of b00000001 will turn on the first LED in a specified row. (i.e. setRow(DEVICE,ROW,BITS);).

All communications between my application and the Arduino had been based on strings and so I had previously been using one character (one byte) to set one LED. Due to this being a complete waste of bandwidth, I decided that each byte I sent through the channel should be a byte to control full row of LEDs. This meant that I could therefore no longer 'see' the output as a string (or ASCII), as the characters I would create from setting the bits may no longer be in ASCII range... this was no big deal, as I could just view the byte values and decode it all myself.

So, on the client end (C#.NET Application) I started encoding the bytes from bit values. This all worked until I tried to set the last bit...

byte b = 1 | (1 < < 7); //let's set the first and last LED.
string buffer = (char)b + "\0";
serialPort.WriteLine(buffer);
Data Sent LEDs lit Correct?
b00000001 1st OK
b01010101 1st, 3rd, 5th, 7th OK
b10101010 1st, 2nd, 3rd, 4th, 5th, 6th WRONG
b10000001 1st, 2nd, 3rd, 4th, 5th, 6th WRONG
b01000000 7th OK
b10000000 1st, 2nd, 3rd, 4th, 5th, 6th WRONG

What the hell was going on? That 8th bit is fishy!

The Answer

So, after reading numerous blogs and not finding my answer, I went to the Arduino Forums and posted a topic asking for help. I was given advice to write a very simple test app to work out where the bytes were failing... but I never did get to write that app, instead I went to the MSDN site as soon as I saw that the Write() procedure could be overloaded.

And look what I found at the article on MSDN:

By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater than 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

And guess what... ASCII Character ? is 63 in decimal and therefore b00111111 in binary!
So, whenever I was setting the 8th bit, the .NET Framework (in all its wisdom) would translate this to a question mark as it was not expecting to send an invalid ASCII character. Ladies and Gentlemen, ASCII is only 7 bits!

The work-around?

byte[] b = new byte[] { 1, 127, 128, 129, 255 }; //let's set the first bit, last bit, etc...
serialPort.Write(b, 0, b.Length);

And then everything just worked. Do not send chars to your port if your receiver wants bytes.

7Oct/100

Gakunan Railway

I'd heard a lot about this railway, and had seen the models released by Tomix, but wanted to see it for myself. I'd been in Tokyo overnight and decided that, although I had my RailPass, I wanted to also ride the Odakyu Express to Odawara and then commute further to Yoshiwara to ride this railway. This trip therefore also involved catching the Shinkansen.


After a quick trip on the Tokaido Line, I arrived at Yoshiwara to find a DE10 in the yard. I later realised that this was the marshalling area for the freight that then gets taken by the Gakunan railway.

Shuttle DE10 at Yoshiwara

I caught the next service through to Hina, as this was the best location at the time to see the most freight movements. I'd gathered this via the 2010 Japan Freight Timetable (but you can also get the timetable here.)

I was greeted at Hina by some archaic looking machines. After around 15minutes of checking out the area, the boom gates came down and then I saw 5 WAMU wagons coupled together and rolling towards me. One of the shunters was hanging on the back and one was in the middle. The guy in the middle all-of-a-sudden jumped off the consist and then jumped back on as the cars kept rolling. I then realised there was no engine attached as the shunters grabbed the handbrake on the wagons.

Before they'd dragged that rake to a hault, the engine (which may have given them a push... it was out of sight) then came through the crossing and coupled up to another rake of WAMUs.

Unfortunately, this was then the total of the freight action seen on the Gakunan Railway itself. But before I returned to Yoshiwara, I checked out the area. There's a few abandoned carriages around the station.

I then waited for the next service back to Yoshiwara. I must note that the passenger services are spaced half-hourly and they give you a good deal of time to check the area out.

ED403 in yard at Hina

Back at Yoshiwara, I checked my freight timetable and saw that there'd be a JR service arriving shortly to drop off cars for the Gakunan Railway. There were also to be other services passing, so I grabbed a bite to eat and waited.

EF66 arriving at Yoshiwara

EF66 arriving at Yoshiwara

EF66 arriving at Yoshiwara

I then returned to Osaka, taking the Tokaido Line to Shizuoka and the Shinkansen from there. You can find the complete photo album for the Gakunan Railway here.

29Sep/100

Minoakasaka and Tomida

The Seino Railway runs from Minoakasaka to Otomesaka just west of Ogaki. JR drops off empty wagons to Minoakasaka from Ogaki and then waits for the return full freight cars. This is a very scenic area and recommended to all. Just make sure you get there when you can get a JR service between Minoakasaka and Ogaki. This is only in the early mornings or late afternoons, as around lunch there are hardly any services!

And yes, I failed miserably to stick to the timetable I had previously wanted to follow. I'd slept in and therefore got to Minoakasaka around 1100 for the 1108 JR service. It was still definitely worth the wait. Below are a few of the good shots (including some of the Yoro railway.) Note that I walked from Ogaki to Minoakasaka and I do not recommend this, it's a considerable distance.

Here's a link to the full album.

Thunderbird heading to Osaka

Closed level crossing

DD403 waits for JR Freight

EF66 arrives at Minoakasaka

EF66 stabled DD403 moves to front Staff ready to arm level crossing DD403 running around DD403 running around

EF66 stabled awaiting return cargo

Note that once the JR engine has detached, the Seino diesel hooks and pulls away very quickly, they have no other traffic on their line and don't wait around!

Yoro Railway

I then proceeded to run back to Ogaki as I'd realised there was no JR passenger service at 1200 and there were also no visible taxis (I should've asked the station attendant!). On the way I dropped my camera battery, ruined my feet due to my sandles and missed the ~1300 Yoro Railway service. I then jumped on JR and got to Tomida to see the cement trains. If only I'd gotten up on time!!

Once in Tomida, I got to see one cement train leave and then two JR oilers pass... not as much as what the timetable would have indicated should have passed. There was a strange bogie-carrying-maintenance-car on the Kintetsu line though! I soon returned back to Osaka.