Showing posts with label Trains. Show all posts
Showing posts with label Trains. Show all posts

Saturday, June 11, 2016

HO Trains and DCC++: Part 2

Controlling a DCC++ base station using JMRI and WiThrottle on an iPad.

At breakfast this morning the Boy asked, “Dad, can we fix Gordon today?” Gordon, from Thomas and Friends, didn’t work when the trains were rediscovered. So today, we took him apart to diagnose the problem. He simply wouldn’t run. Turns out the fix was easy: the contact leafs that rub against the drive wheels to pick up power needed a little extra bending to make a low resistance connection. Once we did that, we also had to run him out a little - I suppose the lubricant in the gear box needed to be redistributed. That and little machine oil and he was up and going. The Boy wanted to put this on the blog. Here is a picture of Gordon in a state of disassembly.

Last time, I was setting up a DCC++ base station to control our one DCC locomotive. Since then, I installed JMRI on a netbook running Xubuntu to have some better control. JMRI is a Java-based train control system that supports DCC++ for output. My netbook was running XP and wouldn't support a recent JMRI version, so I installed Xubuntu as a dual boot. JMRI installation on Xubuntu was pretty straightforward and I also have it auto-starting now on login. It has a server for network control, to which an iOS app called WiThrottle (free version) can connect. Installed that on an iPad and now can control the locomotive over wifi.

Not a bad outcome.

The next challenge is sound on board.

Monday, June 6, 2016

HO Trains and DCC++: Part 1

The Boy has rediscovered the model trains. Several years ago we started by resurrecting my 1990’s N-scale layout, which is 2’-x-4’ and could slide under the couch.  This was followed by  Dad’s post-war Lionel O-27, which was augmented by modern Fast Track and my 1970’s banjo crossing. The Fast Track was a game changer - the stuff works perfectly. It’s reliable, easy to join and doesn’t cause derailing. This was the first time the young-version Boy didn’t get frustrated while running trains. We added 21st century Thomas with a whistle. Finally we added an HO scale Thomas and Friends set. He was able to put together the track with this set himself. It also made several airplane trips in a carry-on back and forth to the Grandparents. But, then the XBox replaced the trains.

Most recently, the Boy pulled out the HO scale trains, built his own layout, and began running a Union Pacific (UP) diesel, boxcar and caboose. He’s using my 1980’s power supply, which was advanced at the time because it had a low-pass filter on the throttle to simulate gradual acceleration and deceleration of the train. Modern control, however, uses Digital Command and Control (DCC). The UP diesel has a DCC decoder. When we bought it, I figured I’d buy a command and base station soon after, but never found the opportune time.

Then last month the Boy has been talking about DCC nonstop and then he discovered locomotives with a Bluetooth interface. Time to do something about it. After researching DCC and reading the NMRA standard, I realized it could be implemented on an Arduino. Using my Google foo, lo and behold, I stumbled upon DCC++. I didn’t think it was the right time to invest in trains with dedicated Bluetooth interface and I have a couple Arduino Unos sitting around - this is the ticket.

Install DCC++

The DCC++ base station code can be downloaded from GitHub here. I used the standard Arduino IDE v1.6.5 to install it. The first time around compiling, it failed with the error:

Accessories.cpp:66:20: fatal error: EEPROM.h: 
No such file or directory #include <EEPROM.h>

Turns out in Arduino, all #includes no matter where they are used must be declared in the .ino file. I learned this interesting tidbit here. After adding #include <EEPROM.h> to the .ino file it works fine. I posted an issue to the GitHub site, so I imagine it'll be fixed. This is the first time I've contributed to someone else's code, although it is a pretty minor bug fix.

Prepare the Arduino Motor Shield

Per instructions here, I cut the indicated traces. The picture below shows the Vin trace cut - this disconnects the external power supply used to drive the motors through the motor shield from the Vin pin on the Arduino.
There are also a couple of jumpers to be installed. The final configuration is shown below.

Test the Uno

Before powering the motor shield, much less trying to control a train, I wanted to make sure I could talk to the DCC++ software on the Uno. Using Hyperterminal, I connected to the Arduino and sent the <s> status command. The response is shown in the picture.


Test the motor shield

Now that the software was working, I wanted to test the shield before using a train. I measured the voltage out when powered on. Using the <1> command turns the power on, which should be a 5-kHz square wave with almost 12-V amplitude (there might be some voltage drop in the driver chip). Note the LED’s by the terminal block are now also illuminated greenish-yellow. My digital volt meter is pretty decent at measuring root-mean-square (RMS) AC voltage and indicated 7.9 V for an expected 12/sqrt(2) = 8.5 V. (9/21/16: I was re-reading this and realized this statement is not correct. The RMS of a square wave is the amplitude. The sqrt(2) factor is for a sine wave. The low voltage reading on the voltmeter could be due it's frequency response. Or, it's possible there's a lot of loss in the driver. I need a scope to diagnose it.) That’ll do.

First run - throttle control

Now it was finally time to try it out. The DCC++ wiki gives an example command to move the train: <t 1 03 20 1>. This command tells locomotive “03,” which is the default encoder address, to move forward at speed 20. It worked. It worked without any fiddling. It’s nice when things just work. Though it is kind of anticlimactic. 

In Part 2, I’ll talk about our experience setting up iPad control.