Jump to content

DCC++ Arduino Based Controller


Recommended Posts

I think there have been a few threads on here mentioning DCC++ in the past, but I thought I'd share my experience of putting together a system using it now, and hopefully join up some of the dots of the different bits of kit and and code that are necessary - especially to use it with WiFi. 

 

I've never been totally satisfied with the DCC controllers that I've owned, but equally never felt that any of the others on the market particularly appeal either. My main DCC controller has been a ROCO Multimaus system with the basic booster split from a train set and bought cheaply from German eBay, which has the big limitation of not being able to read-back CV values or anything. The relatively high track voltage also made me a little tetchy. A little while back I got tempted by the Digikeijs DR5000, which seemed very appealing in terms of offering many of the WiFi based advantages of the ROCO Z21 system, without the need for a clunky second WiFi router, however I personally found it very counter-intuitive to use and ended up selling it. So, when I saw a mention of DCC++ as a system built off an Arduino, I was hooked by the potential for a flexible system that, to me at least, seems to demystify DCC by making it a bit less of a "black box".

 

DCC++ is a system that uses a combination of off the shelf Arduino circuits to implement the NMRA DCC standard. It seems to have been developed single handedly several years ago, and development of the core code doesn't seem to have continued much since 2016, but it is fully functional. The code is all open source and freely available via GitHub here: https://github.com/DccPlusPlus . The name is a deliberate pun on the fact that the Arduino platform is coded in the C++ programming language. The developer posted a really comprehensive videos on YouTube that explain (very clearly) how the NMRA DCC system works conceptually, as well as how it is implemented. I found these really illuminating:

 

 

The video very nicely explains the fact that a DCC signal is required to be bipolar (swinging between equal + and - polarity to encode the digital bits) whereas a normal micro controller, such as the Arduino, uses digital signals that range between a + value and 0. The video goes on to explain how the code he has written takes clever advantage of some of the low level features of the Arduino, like using low level functions to customise the duration of PWM signals generated by the controller's timers, which just happen to work in a suitable way on just two of its pins. 

 

The third video explains how the next stage of transforming the customised PWM signal into a bipolar signal using a particular full bridge driver chip, which just happens to be the one used on the official Arduino motor shield. As he says, this is getting very lucky! Jumper pins are added to connect the PWM signals generated by the Arduino to pins used by the motor shield for 'direction', which it controls by reversing the polarity of the signal. Hey presto, a DCC type signal is created!

 

So, I ordered a new Arduino Uno, and a genuine Arduino Motor Shield, rev.3. Apparently some of the clones will work, but not others, so I went genuine.

 

Before clipping the two boards together it is also necessary to cut one trace marked V-IN CONNECT on the bottom of the motor shield, which isolates the shield's external power supply from feeding back to the Arduino itself. This is necessary as the motor shield needs 15v, which will the track voltage, but that is at the upper limit of what the Arduino can handle - it's designed for the 5v supplied via a normal USB connection. This means you'll need two power supplies.

 

The other step is connecting the jumpers between pins 10 and 12, and 5 and 13.

 

The external power supply connects to the outermost screw terminals of the motor shield, the next pair of terminals are the track feed, and the final pair are used for a programming track connection. I've put the whole lot into a small project box, and connected the power in to a standard 2.1mm DC power jack, and all of the track connections to some chunky 4mm Hi-Fi style test terminals. I really like these because you can both plug in a normal banana plug, and screw in a bare wire - useful for testing!

 

IMG_20200429_195204.jpg.6f673b1e7de7037cdae6dbbd743589c3.jpg

 

Once powered on and connected to the track, you can use all DCC running and programming functions using the Arduino's USB connection. The developer of DCC++ provided an interface for this created in an environment called Processing. This is a bit confusing, not least because the author's layout track plan is hard-coded into it! I hadn't met the Processing environment before, but it looks like it wouldn't be too difficult to master. Nonetheless, I decided it was easier to just ditch this, and use JMRI, which has built in support for DCC++. I found this worked with no hassle at all, although of course control via a PC is a little clunky. 

 

The other component you can see in the box is a ESP-01 WiFi module. There seem to be lots of ways of implementing WiFi with DCC++. many of them documented via threads on the Trainboard forum. This one called BaseStation seems like its been the most commonly used one for a while, which uses a combination of an Arduino running the normal DCC++ software, plus an ESP module. The ESP family of modules are very compact WiFi clients that can be programmed in the same way as an Arduino. However it seems like several of the libraries the most recent version depends on to compile in Visual Studio code have already changed too much or disappeared, and I couldn't get it to work. Instead I used a simpler project called WiThrottle https://github.com/vhar/withrottle by a Russian developer, which is documented in this video.  

 

The ESP module needs an adapter to program. There are some instructions out there on using an Arduino as an interface for this, but I found it was easier to buy a UART - USB adapter from eBay for a pound or two (although even this needed a jumper or switch soldering on to put it in programming mode). Once that is flashed with the WiThrottle code (via the Arduino software), the module I had needed an adapter to connect the 3.3v board to the 5v Arduino. The video shows how to do this with resistors, but I got a dedicated adapter circuit (also dead cheap from eBay) so I could still easily plug it back into the programmer if needed. This made it easy to collect to the Arduino via jumper wires (to Ground, 5v, TX to RX, and RX to TX). 

 

So, now I have a working controller which I can use EngineDriver on my phone to control as a throttle via WiFi without needing a PC turned on, or I can program via JMRI and a USB connection. I've basically spent what it would have cost me to buy a Sprog. But I certainly feel like I know an awful lot more about the way DCC works!

 

It seems like the developers who have been working on this kind of thing have moved on from Arduino as a basis to using ESP modules on their own. The developer behind BaseStation has a new project that connects a more up to date ESP32 module directly to a motor shield: https://www.trainboard.com/highball/index.php?threads/esp32-command-station.112634/ which looks really promising.

 

However, for now, I've decided to try effectively replacing the ESP module with a Raspberry Pi running a full version of JMRI, which will allow the EngineDriver app to download loco profiles, as well as letting me program decoders etc via WiFi as well by connecting to a remote desktop. The big attraction for me is being able to connect via my normal home WiFi, so phones connected as throttles can still access the internet and other devices on the network at the same time - not being able to do this with Z21, DR5000, etc, seems a bit of a fatal flaw to me.  I've ordered a Raspberry Pi 3A+ (older slower model, but designed for embedded applications) that hopefully should arrive very soon. 

 

I hope this little write up has been useful. I'd love to hear how others have got on with DCC++!

 

Justin

 

 

Edited by justin1985
  • Like 2
Link to post
Share on other sites

I too have dabbled with the DCC++ project and apart from  my Deek Robot motorshield not wanting to play at first (not sure how I actually fixed it!) it works very well.   I have a suitable project box for it and just need to  install the Arduino/motor shield boards and provide some suitable terminations.   I haven't gone down the WiFi route yet but I have a couple of modules I got for a another Arduino project (a motorcycle GPS route tracker:D) but didn't use so I'll have a go at that at some point.

 

The "Processing" environment for the user interface isn't that bad actually (the IDE is very similar to the Arduino "Scratch and Sniff") although the programming of the layout plan is rather clunky.   I've replaced his layout with mine which, as the layout is a plank of wood with  two lengths of 7mm Peco track on, is extremely simple!   I've also configured the first loco interface to control a DigiTrains 08 decoder and it seems to work very well.   For the price of an Arduino and a motor shield board the system is truly excellent and means that you'll never have to remember the code to get the 08 driver to scratch his right ear is Shift F23 on your NEC Powercab which has to be a bonus.

 

Like Justin, I found the YouTube videos particularly useful and interesting.

 

Anyway, see it works - do you like the complex track plan?

 

Alan

 

 

 

 

 

Edited by PupCam
Typo
  • Like 1
Link to post
Share on other sites

  • 4 weeks later...

I have a simple DCC system from Bill Cuthbert which uses an Arduino with an HC05 for Bluetooth cost about £40  and using a Samsung power supply off EBAY. THe phone app is six quid from Googleplay. Works well but has an odd quirk. You can only use loco IDs 1 to 20 but in doing that you enter the details of the loco on screen. When you press Loco a screen comes up with     the list of locos and their details so I have No7 STeam Railmotor 77. choosing that loco the F button all on screen now show the details I entered for that loco so Instead of F2 is says Brake, Whistle in place of F4 etc. Very useful . Bill also sells a PCB and the phone app for a Wifi version which uses an ESP32 to create the Wifi hub.

Like Nick however I prefer to use a Knob and Buttons I seem to have trouble with my fingers and touch screens. For the DCC I am using an old Xperia. I have joined MERG and plan to build their DCC system price is much less than other systems.  My long term aim is to add an ESP32 or other Wifi Board to the  MERG Cab plus a battery. I should them be able to send the packets over Wifi to the CBUS  that MERG uses to link cabs to the command station. One problem though is I believe WIFI can be problematic at exhititions as everyones smart phone keeps trying to connect to your wifi hub. Perhaps Bluetooth would be better.

Don

  • Like 1
Link to post
Share on other sites

On 26/05/2020 at 00:14, Donw said:

I have a simple DCC system from Bill Cuthbert which uses an Arduino with an HC05 for Bluetooth cost about £40  and using a Samsung power supply off EBAY. THe phone app is six quid from Googleplay. Works well but has an odd quirk. You can only use loco IDs 1 to 20 but in doing that you enter the details of the loco on screen. When you press Loco a screen comes up with     the list of locos and their details so I have No7 STeam Railmotor 77. choosing that loco the F button all on screen now show the details I entered for that loco so Instead of F2 is says Brake, Whistle in place of F4 etc. Very useful . Bill also sells a PCB and the phone app for a Wifi version which uses an ESP32 to create the Wifi hub.

Like Nick however I prefer to use a Knob and Buttons I seem to have trouble with my fingers and touch screens. For the DCC I am using an old Xperia. I have joined MERG and plan to build their DCC system price is much less than other systems.  My long term aim is to add an ESP32 or other Wifi Board to the  MERG Cab plus a battery. I should them be able to send the packets over Wifi to the CBUS  that MERG uses to link cabs to the command station. One problem though is I believe WIFI can be problematic at exhititions as everyones smart phone keeps trying to connect to your wifi hub. Perhaps Bluetooth would be better.

Don

 

I also bought one of Bill's systems last year and have more recently got into using it properly. It can be slightly buggy but it's a brilliantly cheap way into it. As you mentioned, I love having the android app as it means you can add text to each function button, and properly name each loco address so you're not having to faff round remembering what's what. I've also just got an Arduino servo controller board from him in the last week for an upcoming project which works in tandem with the DCC system and app for up to 10 servo controlled points, and 8 LEDs. A quick test proved it all worked flawlessly. Very impressed.

  • Like 1
Link to post
Share on other sites

  • 2 months later...

I got (re)started into railway modelling a few years back because of DCC++ and from a Robin Simonds (The N Scaler) article about block detection. I've had an interest in railway signalling since I was a toddler and wanted to build something with interesting and accurate signalling and interlocking.

 

So instead of doing anything like that, I acquired a 20x120cm baseboard from the local model railway club's scraps pile and built Inglenook on it, for fun and experimentation.

 

Initially it was DCC++ driven by JMRI, then I built a basic controller, fixed to the board edge, with these features:

- Four pushbuttons and a rotary encoder for input

- Four-digit seven-segment display for output

- Favourite loco addresses hard-coded into the firmware

- Clunky programming mode added after I lost patience with DecoderPro

- Connects to the DCC++ Arduino Uno via a serial connection

 

It also has an engraved control panel - I bought a "T8" CNC engraver after watching a few too many sponsored YouTube videos. It's somewhat underwhelming due to the components it came with but can be fettled up into something more useable. Principle lesson is that engraving doesn't really suit plywood :)

 

A second Nano operates the points, which are servo-driven, with a second engraved plywood panel. It is independent of the DCC components except using the same 5V power supply. The servos are superglued directly to the underside of the board and operate the tie bar with a straightened paperclip. Occasionally the servo angles need to be adjusted by a degree or two to fully close the point but without the servo buzzing - this can be done by plugging the laptop into the Nano and sending commands over the serial connection. The servo angles are stored in the Nano's flash memory.

 

I'm in the process of designing and building a complete replacement with these features:

- 128x64 OLED screen

- Layout fleet and point config information stored on an SD card

- Point servo angles configurable via the controller

- Trains driven with a genericised version of real train controls: separate power, reverser, and brake controls

- 3-digit 7-segment speedometer display

- Driven by ATMega328P microcontrollers in a modular I2C network

 

I'd originally planned to cram Timesaver onto the board too - there's just about enough space to fit Inglenook and Timesaver together behind a headshunt long enough for a loco and five 15ft-wheelbase wagons, raising the possibility of simultaneously solving Inglenook and Timesaver with two locos and transferring trains between the two. The idea is definitely ridiculous, I'm just not sure if it's workable or worth the effort!

 

I'm quite excited by the potential of more realistic train controls than the traditional turny-knob plus decoder-defined momentum. Should make shunting trucks more interesting.

 

Moving forward - I now have a working 3D printer, and a 121/122 railcar - might go for a more advanced controller with a notched power controller and gear selector, and see if I can make it dual-purpose as a model railway throttle and as a Diesel Railcar Simulator game controller…!

20200805_204552.jpg

20200805_204617.jpg

Edited by BusDriverMan
Link to post
Share on other sites

  • 9 months later...
On 05/08/2020 at 18:58, BusDriverMan said:

So instead ...... I built Inglenook on it, for fun and experimentation.

I've been thinking along exactly those lines (no pun intended blah blah blah!) - the track and turnouts turned up at lunch time.       I've got a (7mm) Dapol 08 and a BR 16T Mineral wagon built.   A BR Standard van kit is perilously close to being turned into "No longer a kit" and just a few more will complete the rolling stock.

 

The DCC++ unit is now properly boxed and has a single output using a Phono plug for the connector.   I'm using a spare Hard Disk Wall Wart power supply to power it.   As a unit, it doesn't look very exciting but who cares it works beautifully!

 

The other week I thought I'd have a play around with some of the sound CVs on the 08 so I've added a toggle switch to the output for Programming Track / Running Track selection (I've only got the one loco so I won't accidentally re-programme another loco on the "layout").

 

Still wondering what form the "User Interface" will ultimately take as I certainly won't be using the PC and the Processing App but that can wait for a bit.

 

IMG_3094.jpg

IMG_3093.jpg

Link to post
Share on other sites

I dont get on with touch screen based systems (they seem to wilfully misinterpret my actions) so I prefer a normal handset so I am developing my own handset which I will then modify to be cordless. Progress has slowed because I couldn't get the library functions to indicate if a key was being held. I have produced my own Keypad function to resolve this but since then  I have been busy with work outside including building the garden railway layout.

 

This is my test rig

testrig.jpeg.abc761f89513a6bc2f86d6c98428d636.jpeg

 

The piece of ply has just beeen placed there to support the keypad and the poetentioeeter is just one I had to hand.

 

The DCC++ is pretty compact being just a mega and a L298HN shield. I use a 15v 3A PSU to power it.

 

Don

 

 

  • Like 1
Link to post
Share on other sites

You may already be using  DCC++ EX, but this is a reminder that the old DCC++ Project (Now called DCC++ Classic) has been replaced with DCC++ EX. The same commands work and many new ones, but the software has been completely rewritten from scratch. WiFi is built-in and there are many enhancements to it and to software like Engine Driver and JMRI. We update all three pieces of software weekly with specific DCC++ EX enhancements. There is direct support for WiThrottle and DCC++ compatible throttles (no coding and no JMRI required). Many more motor controllers are supported, there is no need for wire jumpers, and it is easy to expand with a config file, but also a mySetup file that is like an Autoexec.bat file to startup with custom settings and track commands, a user function override feature (aka filters) that let you intercept regular commands and route them to things like the new LCN accessory system or any custom hardware or software you want to create without having to dig through the source code of the Command Station. Also, EX-RAIL automation for layouts is in beta testing.

 

There are new features like "drive-away" where you can drive onto a siding used as a programming track, program your loco, and drive off. We can program virtually any decoder and do it ten times faster which is important when reading a page of CVs or when using all of those decoders that do not follow the NMRA specification due to poor design. There are many other differences and enhancements. EX works on Nano Everys and Teensies now also.

 

Two of our main software and hardware developers (new shields and an all-in-one CS are coming) are based in the UK. :)

 

The best way to find us is via the web page and via chat on our Discord Server where you can get live support and discuss your needs pretty much 24/7.  We try to get on all the boards and forums but other than Trainboard, Discord, and the "DCC++ and Arduino Model Railroading" Facebook group, it is difficult to check them all. 

 

https://dcc-ex.com

 

Thanks to everyone for supporting DCC++ EX and "Classic".

 

Fred

DCC-EX

  • Round of applause 1
Link to post
Share on other sites

2 minutes ago, FlightRisk said:

the old DCC++ Project (Now called DCC++ Classic) has been replaced with DCC++ EX.

That sounds good!    I will have to investigate.

 

Alan

Link to post
Share on other sites

Bit of lazy typing by me Fred.   The MEGA and L298HN is loaded with DCC++EX.  It is very neat how the team reassigned pins so there is no need for any wires as in DCC++ classic. Having been on the Discord Server I can assure people there is real support on there.

 

Don

  • Like 1
Link to post
Share on other sites

20 minutes ago, FlightRisk said:

We can program virtually any decoder and do it ten times faster which is important when reading a page of CVs or when using all of those decoders that do not follow the NMRA specification due to poor design.

 

The way I understand it [1] you can READ decoders up to 10 times faster, not program them any faster, IF the decoder contents match the current JMRI roster data (i.e. it's a new decoder and the JMRI defaults are correct, or a previously programmed decoder that is in the roster).

 

Faster than what [2]?

 

This is done by first attempting to verify the current roster value. If it matches then the read is complete in one operation, otherwise it falls back to the normal method of verifying the 8 bits of the byte.

 

In fact in direct byte or paged mode it could be claimed to be up to 256 times faster.

 

[1] I implemented the back end support for this in JMRI.

[2] Others have applied it, or are applying it, to other systems too.

Link to post
Share on other sites

On 07/05/2021 at 22:23, PupCam said:

 

IMG_3094.jpg

 

That's nice and neat. However couldn't you have used something better than a phono socket?

IMHO they are bloody awful things and should be consigned to the dustbin.:D

 

Link to post
Share on other sites

16 minutes ago, melmerby said:

However couldn't you have used something better than a phono socket?

Whilst they may not be the best possible connector (I spent my entire working life in an industry that used very expensive "best possible connectors") the phono socket in this case has a number of advantages:

 

a) It's perfectly adequate

b) It is tight and won't come adrift without a bit of a fight

c) It's perfectly capable of operating at the current levels demanded by my loco

d) (and most importantly) I had a matching set in my bits box ..... :D

 

 

Link to post
Share on other sites

Well Helllo Andrew! And thank you for all your contributions to the hobby, BTW.

 

Actually, it is still faster than DCC++ (which is what I am comparing), there is a lot more we are doing that Classic does not do regarding packet sending and ACK detection, so even the 8 bit writes are much faster (maybe that's not 10 time faster, I think the data showed 6? ) And it is able to work with more decoders because of how all the new code works and because we can analyze the diagnostics built into EX and use it to tweak things to deal with bad decoders. We found 2 last week and with one, the manufacturer as willing to fix the bug. We could work around it in software (the decoder was modulating its ACK pulse), but great that their support was willing to issue a firmware update.

 

I was also referring to the way the CS operates internally and not JMRI, our new <V> command that validates or verifies against our best guess speeds up the process. My understanding was that was then added to JMRI thanks to you working with our developers (Steve Todd and Harald Barth)?. So again, thank you!  Cooperation instead of competition, how rare is that? ;)

Link to post
Share on other sites

21 hours ago, FlightRisk said:

I was also referring to the way the CS operates internally and not JMRI, our new <V> command that validates or verifies against our best guess speeds up the process. My understanding was that was then added to JMRI thanks to you working with our developers (Steve Todd and Harald Barth)?. So again, thank you!  Cooperation instead of competition, how rare is that? ;)

 

I can add it to my own products, and it works well, is that Cooperation or Copying, LOL. They do say imitation is the sincerest from of flattery :)

 

Link to post
Share on other sites

@FlightRisk - are the details for the new hardware (CS and motorshields) available somewhere? I have had a look on Discord but found it difficult to find anything. I built a DCC EX system a little while ago (a mega, L298 shield and the little ESP-01 board and TrainDriver) - works very well on the 1 yard test track.

 

I’m aware of the L298 limitations so I guess that a better MOS device will be used rather than an old BJT device, although the data sheet shows how to parallel the outputs - and a lower current drive can be used for the programming track. Looking forward to some optimised hardware.

 

Thanks,

David

Link to post
Share on other sites

Hi Don,

 

 I am a frequent visitor to  dcc-ex.com but I haven’t seen anything on the hardware development, though I might have missed it. Maybe I’ll try github.

 

Cheers

Link to post
Share on other sites

Do you mean new boards we or people we are working with are developing, or configuring Pololu, IBT_2, the 15A Chinese board, etc?  Existing boards are under "motor controllers" in the references section. Going to figure out a way to have sub-groups since that section is getting large.

To keep Discord from inundating people software and hardware development technical discussion between the developers is on a hidden development channel that people can be invited to. I'll try to make sure more updates go in for public discussion. There is the open #motor-shields channel under "Hardware" and there is a private "hdw" repository in GitHub where we store things, which I am happy to let anyone join who wants to be part of it. We are still trying to figure out how to make things easy and organized. GitHub has repositories, teams, discussions, projects.. Discord has channels. It can get confusing. I need to put the roadmap on the website in its own heading. That would probably be a big help.

Link to post
Share on other sites

I was curious about the motorshield development. I had thought about doing my own (already hinted at!), but it is another project that I don't have time for. I appreciate that you'd want to keep the development to a limited group - every (wo)man and their dog wants something slightly different ....

 

David

Link to post
Share on other sites

You are right, we can't be all things to all people. Thought we do love to get input from as many places as possible before making a decision. There are usually caveats or snags we find out about during our research into things. I've added a roadmap to the main menu. It is a bit preliminary, some things are solid and other things might change as we firm it up over the next couple of weeks.

 

https://dcc-ex.com/roadmap/index.html

 

Fred

DCC-EX

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...