Introducing DCC++ ---a complete open-source DCC station and interface

Gregg Aug 25, 2015

  1. Gregg

    Gregg TrainBoard Member

    237
    302
    15
    It's been about 5 years since my last post. During that time I've developed my own version of an open-source DCC controller. The base station consists of an Arduino Uno (or Arduino Mega) and an Arduino Motor Shield, and that's the only hardware needed (with the exception of an 18V AC or similar power pack). All of the code for the Arduino is written in C++ using the Arduino open-source IDE, hence I named my home-brew system DCC++ (pun intended).

    The interface is written in Java using another open-source IDE and basic graphical library called Processing. The interface runs on Windows as well as Mac systems, though I have not yet written and iOS version. Connection between the PC/Mac and the Arduino is either by USB cable or via BlueTooth for wireless control.

    The system itself supports just about everything you can do with DCC, including multi-train throttles, 28-function decoders, programming on the main, reading and writing CV's from a dedicated programming track, controlling turnouts, etc. It also has built-in support for IR sensors which I have found work very well for train detection and enable complete automation of very complex operations.

    One of the reasons I created DCC++ is because I was disappointed with the commercial controller I had purchased when I first started building my N-scale railroad. I really want to automate my entire layout and thought I might give JMRI a try, but at that time it did not support my controller. But the real reason I created DCC++ was because I always wanted a good excuse to program an Arduino, and a good reason to learn Java.

    All of the code, both the C++ for the Arduino as well as the Java for the interface were developed by me from scratch and are not derivations of any other system, commercial or otherwise. Since I relied heavily on other open-source systems (Arduino and Processing), my intention is to provide all of my code back to the community for anyone to freely use, modify, hack, distribute, etc.

    Though all of my code is heavily documented, bundling any code for distribution to others in a way that is useable is not that easy. So, as an initial step in this process I've created a DCC++ youtube channel with a few videos demonstrating the interface as well as showing how the system is used to fully automate my small but complex N-scale layout.

    Over the next few weeks I plan on creating and uploading a few more detailed videos that explain how the Arduino is configured, how the Arduino Motor Shield turns out to be the perfect add-on for producing two channels of bi-polar signals (one for the Main track and one for the Programming track), how the Java graphical interface works with the Arduino, and how to create some simple IR sensors for use with the system.

    Please feel free to check out my youtube channel out at: https://www.youtube.com/channel/UCJmvQx-fe0OMAIH-_g-_rZw. I apologize for the cryptic URL. Youtube does not permit custom URLs until a channel reaches 500 subscribers.

    Based on feedback, if there is sufficient interest I'll find a place (probably Google Drive) to upload the code so others can download it as well.

    -Gregg
     
    Goofy, Michel Goyard, Tom1941 and 4 others like this.
  2. Rocket Jones

    Rocket Jones TrainBoard Member

    758
    510
    16
    I'll be following with interest. Thanks for sharing.
     
  3. TwinDad

    TwinDad TrainBoard Supporter

    1,823
    514
    31
    Wow! Sounds interesting!

    Have you considered hosting your source code someplace like GitHub?
     
  4. RT_Coker

    RT_Coker TrainBoard Supporter

    517
    31
    13
    Way to go! Great work!

    What interface are you using between the computer and the base-station? If it is a serial-port (even a serial-port through USB), then your system would probably also work through Bluetooth with the addition of something like a HC05 Bluetooth to the base-station.
    Bob
     
  5. Gregg

    Gregg TrainBoard Member

    237
    302
    15
    That's a good idea --- I'm a bit familiar with the site but have not used it before. I'll check out the details as it could be a great repository for the code base.
     
    Davemil likes this.
  6. Gregg

    Gregg TrainBoard Member

    237
    302
    15
    Thanks for the kind words! In terms of the interface, it is indeed serial, connected via a USB cable from the PC or Mac to the Arduino. However, Arduino makes a Bluetooth enabled Arduino that can be used instead. No software changes required -- you would still connect serially, but without the USB cable. A while ago I added a separate BlueTooth module (RN-42 Blue SMiRF I picked up from Sparkfun) to my Arduino so I can simultaneously program the Arduino via a USB cable while running the trains via Bluetooth (great for diagnostics and testing).
     
  7. Doug A.

    Doug A. TrainBoard Supporter

    3,389
    37
    50
    Interesting! I will be following this one. Definitely would like to see someone develop an iOS version.
     
  8. esfeld

    esfeld TrainBoard Member

    385
    361
    11
    Gregg ...... Very impressive! As a retired Comp Sci professor having taught programming for years I fully understand the work you have done .... as an avid n scaler and JMRI user I am anxiously awaiting your information on building the Arduino interface ...... hopefully that will follow soon. Could I indulge you to give a timeline? Thank you. esfeld@cyberdude.com

    ยท
     
  9. DCESharkman

    DCESharkman TrainBoard Member

    3,155
    204
    43
    In short..... Too Cool for School!

    Well done!
     
    BarstowRick likes this.
  10. Gregg

    Gregg TrainBoard Member

    237
    302
    15
    Friends,

    I have added two more videos to my DCC++ channel on YouTube. They form parts 1 and 2 of a series showing how to configure an Arduino for use as a base station. Part 3 will hopefully be ready next weekend.

    -Gregg
     
    esfeld likes this.
  11. subwayaz

    subwayaz TrainBoard Member

    3,221
    94
    44
    Same here will be watching. iOs especially
     
  12. arkman1231

    arkman1231 E-Mail Bounces

    2
    1
    3
    Gregg,

    It would be great if you could upload the code to GitHub. I'm an NScaler - and longtime software developer - who suddenly was infected with the Arduino virus about 3 months ago :). I'd seen a few things w.r.t. Arduino and DCC out there, but your solution seems to be the most thought-out. Especially the videos - very well done and easy to understand, no kidding. Great stuff. You DID leave us hanging at the end of the 2nd hardware video, but we'll be patient. Not the world's biggest Java fan, but once the code is out there, I'd like to maybe take a stab at an iOS version, or even a version that would work across iOS/Android/Windows Phone. Or possibly a node.js/HTML interface.

    Looking forward to more stuff!

    Greg (2G vs 3G :))
     
    esfeld likes this.
  13. esfeld

    esfeld TrainBoard Member

    385
    361
    11
     
  14. esfeld

    esfeld TrainBoard Member

    385
    361
    11
    Gregg
    Anxiously awaiting further work on this project.
     
  15. WAKtrain

    WAKtrain New Member

    1
    0
    13
    Wow!!! What an amazing system! You have done a great job of taking a complex system and simplifying it so that it is easy to understand and use the system. Where and when can I get the code ???
     
  16. real joe

    real joe New Member

    2
    0
    3
    Very VERY interesting............

    I would like to get started yesterday......ha ha.........

    Problem is would need software and be able to find the correct boards. The Arduino UNO I found on fleabay but the motor board shown in the video I could NOt find on ebay or digikey..
     
  17. Gregg

    Gregg TrainBoard Member

    237
    302
    15
    Friends,

    As some of you have already noticed, I just uploaded two new videos to my DCC++ YouTube channel. These form parts 3 and 4 of the Arduino DCC++ Base Station Hardware series. In these videos I show how a standard Arduino Motor Shield can be readily used with an Arduino Uno to convert DCC logic signals produced by the Uno into full DCC bi-polar power signals that can be connected directly to the tracks. This is a very atypical use of the Arduino Motor Shield and I only stumbled onto it by happenstance --- I happen to have a Motor Shield driving a motor to animate a horse head oil pump, and after learning about full-bridge circuits realized that the Motor Shield could be used to create bi-polar signals without any modification (except for two jumper wires).

    Real Joe (above) asked about where to find the Motor Shield. I used to buy them at Radio Shack, but that's unfortunately no longer an option. However, two reliable sources carrying them in stock are Digi-Key and Mouser. The price seems to have gone up. I paid about $15 at Radio Shack last year and these sources list them at about $26.

    I know a number of you have been asking about the software. Though my code base is reasonably mature, it needs a lot of commenting to be useful. I'm in the process of doing that now and have created a GitHub account which will serve as the repository (assuming I can figure out how to use GitHub). Note that the total DCC++ system comprises two separate software systems: C++ code for the Arduino that acts as the DCC base station, and Java code for a PC or Mac that serves as the interface/controller. However, the Arduino part can be used on a standalone basis, at least for testing purposes. All control is through the serial port using formatted single-letter commands. The Java interface produces these automatically, but you can type them in manually through the serial monitor of the Arduino IDE.

    I hope to be able to upload the fully-commented C++ Arduino code to GitHub in the next few weeks. I'll also post a video explaining the code and the command set. I'll follow-up with the Java code shortly after that.

    -Gregg
     
    subwayaz likes this.
  18. lyled1117

    lyled1117 TrainBoard Member

    35
    21
    5
    Extremely interesting, will be looking forward to the base station code becoming available. Been doing some Arduino projects, this will be a great one to add.

    Lyle
     
  19. real joe

    real joe New Member

    2
    0
    3
    One SERIOUS problem with DCC is its ADICTIVE!
    I started out planning to convert a FEW locos to DCC (just to "play with") and ended up converting almost all, even 25-30+ yr old locos, ones that were worth converting anywho. Then I started playing with sound. I converted a few, very few, to DCC w/sound and made a few sound cars (usually box cars) so any loco could drag sound around. I even managed to stuff DCC into a N scale Plymouth switcher. I am an Nscaller, in case you have not guessed yet.

    Then came a point I wanted to show-boat some of my DCC handy (or not so handy) work. So I wanted to trigger DCC sound installed into rolling stock using a portable small controller. I ended up picking up a couple used Baxhmann EZ DCC units cheap. They are very limited, but suitable for what I wanted to use them for. I ended up "winning" 2 of them on eBay and converted both of them to dual 9vdc battery power, but still can be used with the normal/usual 12-16vac power.

    I do not plan to do any fancy stuff, just tinker and have fun, I hope.

    JD

    (PS BTW Thanks for the info, greatly appreciated, I ordered a Arduino uno & motor shield from Digi-Key)
     
  20. pinpres

    pinpres New Member

    3
    1
    2
    Hi Gregg,

    How does your system handle sensor input - is this DCC or direct connection to the Arduino?

    Keep up the good work!

    Pinpres
     

Share This Page