# Arduino DCC control



## BrokeCurmudgeon

Does anyone have experience or opinions concerning using an Arduino and JMRI for DCC. This Youtube video is intriguing and he claims that he built a system for about $10. I already have the Arduino and have ordered a H Bridge for a couple of dollars. I have attached two YouTube links should you be interested.


----------



## gregc

are you considering this instead of buying a commercial product to run your trains in order to save money?

Or are you considering this as an interesting science project to learn more about Arduinos and DCC?

If you're going to rely on this for running trains, i think you'll need to have an intimate understanding of how it works so that when there are problems, you can debug it and if you have any problems with the decoders, you can determine if there might be a problem with the Arduino code.

It also looks like they have some nice handheld controllers. I think one was just a TV remote with an optical interface but the other was an iphone. It wasn't clear what the iPhone interface is.

it's one thing to build a prototype to demonstrate a concept, it's a bit different to build something that is reliable and can be kicked around and abused a little and continue to work.

I downloaded the code. I don't see a lot of comments nor a good description of the features or design.

The NCE PowerCab and I assume all DCC systems monitor current in order to shutdown in case of a short to prevent damage. I don't know if this has that feature nor the circuitry to do this.

I'm an embedded SW developer at Qualcomm and develop RF SW.


----------



## RT_Coker

It always entertains me how much disinformation appears on forums. And most of it comes for non-users of the item(s) in question. 

A little www research will lead to “DCC++”s own sub-forum on another train hobby site. I think it is wonderful that people are willing to provide free open-source products that bring new people and breathe in new life into the hobby. 
Bob


----------



## fcwilt

If you are at all comfortable with electronics and programming you should give it a try.

The important thing for using on your layout would be sensing excessive current and shutting things down.

Typically DCC command stations do this and periodically try to apply power to see if the short (or overload) is still present.

Alternatively you could have a manual reset.

If you decide to give it a try feel free to ask for help.

I've worked a good deal with the LocoNet code for Arduino.

This code is likely to be similar.

Frederick


----------



## BrokeCurmudgeon

Thanks for the comments and advice. Over fifty years ago I had one years' training courtesy of the USAF. I worked for over ten years as a technician and I have a FCC General Class Radio Telephone license (for whatever that means now)and then I went into management. Needless to say I am quite rusty with my electronic theory. However I have had a computer since the 1982 DOS and Command Line days. I now struggle with what I use to be able to do without much trouble. All that being said, I believe that I can work my way through this Arduino project. Especially for less than $20. If I am successful I may be willing to invest in a Digitrack system. The problem is running stock. I have 4 DCC ready Kato F3 locos. Hopefully I can get occasional help when I bog down from this and other forums. But isn't this is what our hobby is about?


----------



## wvgca

it works, I have had it running for a while on a test layout.. no issues, but use jmri for control, not a remote or ipad .
It's intresting, but I still use a standard system on the main layout


----------



## RT_Coker

One of the typical advantages (which is also a disadvantage) of open-source is that there are many variants of the product. From what I have seen on the web, DCC++ has many variations of hardware and software. So any users should be willing and persistent in seeking help from the originator(s). Most open-source originators are very helpful. 

It is also a good idea to stay with a main variant of the product unless (or until) you feel comfortable with the software and hardware environments you will be using.
Bob


----------



## sachsr1

Prior to last June I had zero experience with electronics. I made the wireless version of this that I've used on a test track. I found a new sub hobby of ordering cheap electronic components off of ebay. Dave Bodner does a lot of Arduino topics on his site trainelectronics.com.


----------



## Lemonhawk

You could use a DCC circuit breaker, it would help protect against heave shorts on the track and eating the wheels away. Digitrax PM42, other DCC circuitbreaker.


----------



## wvgca

There is provision in the DCC++ code for current sensing, and shutdown .. however the sensing is done off the H-bridge , and not all variations support this ... it's easy to do a coin test to check this ..
I mostly run a L298 type labelled Deek Robot, 2A, and some times a BTS7970B style labelled IBT_2, that I mostly use for tractor autosteer, but works fine for DCC++, rated 43A, both support current limiting , both driven by a Uno in my case ..
The smaller one will run three / four loco's on my test track with no issues..
If needed you can also make your own boosters, for slightly more as a display is nice to add to these ..


----------



## gregc

how is current sensing accomplished with an H-Bridge?


----------



## wvgca

gregc said:


> how is current sensing accomplished with an H-Bridge?


Some H-bridges modules do have current sense provision on the board, the image below is from the 43A version, pins 5 & 6 ..to get a reasonably accurate response from various bridges, the user needs to adjust a feedback response value within part of the DCC++ code, specifically the CURRENT_SAMPLE_MAX value in the file CurrentMonitor.h part of the code ..
I use 300 for the smaller one and 500 for the larger, and this also selects what percentage of the bridge current that you can use before the 'duino shuts down pulses to the bridge. 
There is also the ability on the BTS7960B to hardwire current limiting directly on the IC, but the lower limit is around 33A.. okay for tractor, not so good for model trains .. 
on mine I need to reset the 'duino to reset after a shutdown .. The code I have is around five months old, when I started with DCC++, I don't know if newer versions have provision for a soft reset? I'm basically a novice user of DCC++, and mostly use it to save CV values, just in case 
If it matters, small bridges are a couple of dollars, and normally can drive two tracks, in DCC++ for main and program, the one in the image is 12-15 or so and will drive two motors in single direction, or one bi-directional, which is perfect for DCC PWM usage., .


----------



## gregc

thanks for the explanation. wasn't aware some devices had this feature.


----------



## wvgca

gregc said:


> thanks for the explanation. wasn't aware some devices had this feature.


It's common in industrial drivers, in smaller stuff it's easy to implement in direct mode with a shunt resistor, and running the voltage across it through either an op-amp or a differential amp, same as used with those cheap voltage / current readout modules ..low side sensing between load and ground .. 
In the image there are two load sense pins because there are two drivers in the bridge ..only one side needs to sensed because both sides ~should~ output the same current for DCC++ usage..
The common L298 quad bridges are also handy to drive DC motors for layout animation ,,, four PWM outputs for a couple of dollars ..nice..


----------



## Cycleops

I have to declare I have no interest in pursuing this branch of the hobby. If I did the one thing that would worry is the aforementioned short protection. If you are going into it this just for cost reasons and have sound or even non sound decoders, if you do get a short and manage to fry them $20 doesn't look so cheap any more.


----------



## BrokeCurmudgeon

I like most aspects of the model railroad hobby. However where we seem to be going is similar to my experience several years ago when I was heavily involved in radio control aircraft. I started out building solid model airplanes as a young boy. Then stick kits powered with rubber bands. Radio control with a one function actuator installed in scratch built airplanes came next Afterwards came digital PCM radios but still in built scratch or kits. I spent many weekends building and then going out to fly just to crash and burn. It was quite rewarding to me despite of the many frustrations! Now, most people buy RTF (Ready to Fly) beautiful models. I lost interest because I really enjoyed the learning and challenges and not just the operation.
All that being said, with due respect to model railroad operations and operators, I truly enjoy the many aspects of building, designing, improving my layout. It is not just about the cost. 
My old brain is beginning to lose it and I struggle with newer technology but I find it fascinating that for a few dollars one can build a DCC system. The points about shorts and burnouts are very valid. However, one can incorporate current limiting capabilities into the design with an Arduino for little cost. Just my opinion however.


----------



## RT_Coker

Cycleops said:


> I have to declare I have no interest in pursuing this branch of the hobby. If I did the one thing that would worry is the aforementioned short protection. If you are going into it this just for cost reasons and have sound or even non sound decoders, if you do get a short and manage to fry them $20 doesn't look so cheap any more.


I have study the available DCC decoder designs and it doesn’t appear reasonable to me that a short on the DCC power should fry a properly designed and used DCC decoder. However I have fried a motor-control-board by switching the DCC on-and-off, but it was my fault because I ignored a warning about protecting the board from reverse-voltage-surges.
Bob


----------



## wvgca

Cycleops said:


> if you do get a short and manage to fry them $20 doesn't look so cheap any more.


Well, make it $21 and include an inline fuse [with holder], or the auto bulb method 
although most prefer more elaborate method .. 

The few DCC controllers that I have actually seen a schematic of [older stuff], just run a crowbar circuit or similar, slightly faster than a fuse, but slower than processor based current sensing ... 

Also most shorts on layouts occur between track and wheel power pickup, and doesn't even get to the decoder itself ..


----------



## fcwilt

Without actually doing the math it would seem that hardware based current limiting would be a faster than processor based.


----------



## wvgca

fcwilt said:


> Without actually doing the math it would seem that hardware based current limiting would be a faster than processor based.


Yes , with a _decent_ hardware design, I have only seen a couple of schematics of current limiting used on older DCC systems, and they were pretty crude ..I have no idea of how the newer ones work, 

And there is the benefit of being able to adjust current limit with just changing a couple of numbers in processor code ..no extra soldering ..

Still a lot people using fuses and light bulbs, easy to get and install for most  .. and while they may not be the most elegant solution, they do work and do offer some protection


----------



## RT_Coker

wvgca said:


> ..I have no idea of how the newer ones work, ...


In least in some cases they work very strangely. 

I had DCC “command-station” (list-price ~$370) from a major manufacturer. Its short-control-logic could become confused and it would put out a DC-like signal. It was easy to tell when it was confused because the dual-mode-DCC-locomotive(s) would take off a high speed (potentially more damaging than a blown-decoder). Admittedly this was not apparently a commonly occurring problem. To make a long story short, it eventually lead to a forum discussion with an anonymous person who had all the appearance of knowing how the system was designed but seam almost paranoid about defending that design. The only result was that I needed to change the way I was doing the isolation-joints on the track. 

Many manufacture system are “defined-good” by the manufacturer and it is very difficult to prove otherwise. This is where open-source has a major advantage; at least eventually someone will find the design flaw and it will typically be expediently fixed.
Bob


----------



## Shdwdrgn

Dragging up this subject again, I've been slowly buying pieces to try and set up an arduino DCC system. At one point I had a schematic that I was going to use, but seem to have lost it. The problem is most discussions of implementing DCC++ seem to expect the person to just use an arduino Uno or Mega, along with the motor shield board. Bleh!

I have arduino pro-micro boards. I also have (and prefer) the ESP8266 which I should be able to use in conjunction with the DCC++ TCP/IP code modifications. I picked up an L298N motor driver board, so it seems I should only need an appropriate power supply at this point... if only I could find the schematic again...

Also I have a lot of confusion about the power supply. For a small HO layout (a test loop to run two trains) I think a 15VAC @2A would suffice, and apparently in this day all train motors have been converted to 12VDC? Any advice here?


----------



## sachsr1

I can't help you too much with the wiring on the smaller Arduinos, but I bought a Chinese copy of and Wemos board. It's basically a Uno with the ESP chip in it. I haven't played with it much, but it seemed to work during a few basic tests. As for track voltage my NCE Powercab puts 13 volts on the track. I used a 15 volt laptop power supply on my DCC++, but I have only run one train around an oval with it. Here's a link to the NMRA standard.

http://www.nmra.org/sites/default/files/standards/sandrp/pdf/s-9.1_electrical_standards_2006.pdf


----------



## /6 matt

I have tried the dcc++ system and it hasn't worked for me yet. My Bachmann Sound value Alco 2-6-0 doesn't respond to address 3 like it should. I am using jmri and I can switch the track power on and off. When I place it on the program track and try to read the cv for the the address, it shows a different value each time. I tried setting it to 3 and it still doesn't read or respond. Since this is my only dcc locomotive and my only dcc system I don't know if the problem is in the dcc++ system or the locomotives decoder or if I need a programming booster. At least I only have $20 in it.


----------



## Shdwdrgn

So far I only have $4 into my setup, so I have you beat there...  Of course I'll easily double that cost just from the purchase of the AC power supply. I don't have any commercial DCC components, not even so much as a DCC-ready loco, but I keep thinking I want to build my system around some kind of existing standard, so hopefully I can get it going. Got some time tonight, I'll do more digging and see if I can find a schematic or something to work from...


----------



## /6 matt

I figure I'll keep plugging along on this till I get it right. Does this aspect of the hobby interest me? No, but I'll learn and work at it because I refuse to spend $150 for something I could build for $20. Building a wireless control will cost about another $20. How much does a comercial wireless dcc starter set cost?


----------

