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

Gregg Aug 25, 2015

  1. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Pinpres,

    I connect sensors directly to unused pins on the Arduino. Because I have so many sensors I actually switched from the Uno to the Arduino Mega which has many more free pins. The DCC++ Base Station software (which I should be able to post within the week :)) polls each pin sequentially looking for a drop to ground. The software performs real-time exponential smoothing so separately de-bouncing each sensor switch with a dedicated circuit is not needed. For my own layout I've had good success using QRD 1113 infrared transmitter/sensor packages (https://www.sparkfun.com/datasheets/BOT/QRD1114.pdf). These are small enough to fit between the rails of an N-scale track and are easy to hook up. I then place white reflective tape on the bottom of each of my engines, and a white piece of plastic on the bottom of the last car of each train. In this fashion I can detect when the engine passes over the sensor, and then again when the last car does.

    -Gregg
     
  2. TwinDad

    TwinDad TrainBoard Member

    1,844
    548
    33
    Is the white "marker" on the rolling stock necessary? Can the detector not see the cars without it? I'm a little surprised that in the IR range the locos and cars don't reflect enough to show up without the white tape or plastic...
     
  3. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    You bring up a good point, and when I first tried the QRD 1113 I thought the IR transistor would simple switch ON whenever a train car was above. However, when I experimented with different resistors to limit the current draw, I either found the transistor was so sensitive that it would flicker when cars rolled by (or would go off completely if the train stopped over the sensor between cars), or there would be insufficient current drawn to drive the Arduino pin to ground. In fact, I found that to strike the right balance I had to disable the Arduino's internal pull-up resistors (which can be done in software for any given pin) and use an external pull up resistor. This seemed to give me the right level of sensitivity but required a very reflective and proximate surface to trigger. In my case the white plastic on the bottom of the last car of each train needs to be installed to that it is riding just above the surface of the tracks. Any higher and the reflection is not strong enough.

    Though the software handles this well, and can keep track of when a train first crosses a sensor and then exits the "sensor region", it is much more complicated than I would have hoped. Perhaps there is a better combination of resistors that can be used, or a different circuit altogether (my goal in DCC++ is to minimize all external circuitry and rely on the software? Maybe in this case some additional circuitry would have been better?). Any thoughts or ideas would be greatly appreciated. Below is screenshot of the schematic as implemented:

    DCC++ use of QRD 1113.png
     
  4. TwinDad

    TwinDad TrainBoard Member

    1,844
    548
    33
    Hmm... if you could get the sensitivity right at the expense of the current draw, you could feed the sensor through a simple amplifier circuit to drive the Arduino input.

    Most of the solutions I've seen regarding handling IR sensors and between-car gaps involve timing (a 2-3 second delay before going logically "off") or a second sensor placed less-than-a-car-length away, so one is always covered. Of course, I've mostly looked at them in the context of moving trains (e.g. triggering a gate crossing), and not stationary trains (e.g. staging track occupancy).

    I suppose you could hide the "marker" piece on the bottom of the truck, which would get it very close to the track, at a consistent height, and fairly well out of sight... but then your "visible area" of the car would be limited to the truck(s).
     
  5. RT_Coker

    RT_Coker TrainBoard Supporter

    517
    33
    13
    Greg,
    FYI: The IR sensor that I am using on DBTC is very similar to the one you are using. I am getting a better IR reflection using “foil” labels rather than the white.
    Bob
     
  6. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Thanks Bob! I'll have to give that a try --- it would be nice if I can avoid adding extra plastic to the bottom of my trailing stock.
     
  7. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Friends,

    At long last I have created a GitHub account to share my DCC++ code-base.

    An initial repository containing a complete C++ sketch (with documentation) for an Arduino Uno DCC++ Base Station is now available at https://github.com/DccPlusPlus?tab=repositories. Please feel free to explore, download, test, and ask questions if needed.

    Next up will be an expanded C++ sketch for use with the Arduino Mega (in which I take advantage of the Mega's extra memory to implement a self-contained auto-pilot routine, as demonstrated in the YouTube videos, in addition to some other bells-and-whistles). I'll then post the Java code for the DCC++ Controller.

    Enjoy!
     
    Whiskeyjr and papahnash like this.
  8. arkman1231

    arkman1231 E-Mail Bounces

    2
    1
    3
    This is beyond awesome. Your timing is perfect, we're expecting monsoonal rain in Texas through the weekend, know what I'll be doing. Thanks for all of this, Gregg, it really is fantastic.

    Greg

    Sent from my SM-T800 using Tapatalk
     
  9. pinpres

    pinpres New Member

    3
    1
    2
    Hi Gregg,

    Thanks for your work - I have been working on something similar (an HO switching layout which will be fully automated including lights, sound, DCC loco and turnout control, and uncoupling). I have had success using Hall effect devices under the track (invisible) with small disc magnets attached to the loco (or loco + last car in your case). The Hall effect device (Allegro Microsystems A1120) works reliably and is very economical.

    Regards

    Pinpres (UK)
     
  10. papahnash

    papahnash TrainBoard Member

    323
    35
    13
    Hi Gregg,

    Thank you for all your great work.
    The motor shield is rated at 2A/channel 4A total. Have you found that to being a limiting factor with your operations?
    Are your switches driven from a track connection?
    Thanks again.

    Harold
     
  11. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Hi Harold,

    So far I've not had any issues with the 2 amp limitation of the motor shield. My layout has 7 N-scale trains and I only draw about 500-600 mA (that includes one engine with sound). However, I've not tested this with HO or larger and my guess is that the 2A capacity would start to become a limiting factor. I have seen other motor shields with larger current capacities and one could always put a heat sink on the 298 chip which should help a bit. For much heavier loads I think you would need to run the output of the motor shield into a separate DCC booster.

    As for my switches, they are all controlled by Lenz stationary decoders that take their logic signal from the tracks but use a separate 18V AC power supply to avoid drawing down any track current. The switches are all Kato Unitrack (electromagnetic). They are quite reasonable but if I ever build another layout I would most likely go with a very simple non-powered turnout operated by a wire connected to an undertable servo. Over the past few years some of the Kato turnouts have lost a bit of their springiness and the points don't always return to their correct position when thrown. Its not practical to remove and replace the track since its soldered and cemented in place. But an undermount servo would be easy to replace if needed. Next time maybe!

    -Gregg
     
    papahnash likes this.
  12. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello Gregg,

    Where can I find the DCC++ Controller GUI? Thanks - Scott
     
  13. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Hi Scott,

    I haven't yet uploaded the GUI to GitHub --- similar to the base station code, it's mature but needs a bit of commenting and organization to be more useful. Have you had a chance to download/try the base station code?

    -Gregg
     
  14. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Hello Gregg,

    I finished watching all 8 videos on youtube and downloaded the Arduino sketch and I'm going to attempt to put it all together later tonight. I model in HO Scale and I have an Adafruit Motor shield... https://www.adafruit.com/products/1438 will this one be sufficient? or do I need to go bigger? also as a power supply could I just use the fixed DC outputs off of a regular DC transformer? I currently use a Digitrax DCC system or could I just use that power supply? Thanks for the guidance! - Scott
     
  15. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Scott, I think the original motor shield from Adafruit (which I believe was a clone of the Arduino shield) would work without modification. However, the new Adafruit shield uses a completely different method to create the outputs. I'll have to read through the specs to see if/how it can be used.

    -Gregg
     
  16. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    If I have to get the motor shield you used that's fine.....the HO Scale motors draw one (1) amp per motor so I would have to use a heavier power supply in order to drive more and I would have to use separate power supplies....one for the arduino and one for the motor shield correct?
     
  17. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    I was just looking at the specs for the new adafruit motor shield and I don't think it can be used for DCC++. The adafruit shield has an additional PWM chip that controls two sets of H-bridges and does not allow for direct communication to the H-bridge chips. It might be possible to use the adafruit with some (potentially significant) modification, but it may be more hassle than it's worth.

    In terms of power, you would definitely need to power the motor shield separately from the arduino, since you'll need a higher voltage for the tracks than the arduino can safely handle. What are the output specs for the power supply that comes with the digitrax system? If it outputs DC voltage (which is needed for the motor shield) it might be possible to re-use.

    The max current the motor shield can handle is 2 amps, so you may be initially limited to 2 or 3 HO trains at a time. You may also need to modify one of the parameters in the base station software to increase the cut-off point for current overload --- I have it set to somewhere below 2 amps for extra safety, but it can probably be raised.
     
    Scott Eric Catalano likes this.
  18. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    The power supply I have right now is 18 volts 15amps for the HO setting and is plugged directly into the digitrax super chief DCC base station. This particular power supply can do N scale and G scale. I just need a smaller supply for 2 or 3 trains. I plan on using this setup for a Christmas train display the club that I belong too sets up each year at a local mall. I do not want to take my DCC system with me this year and with it being automated using the GUI controller would be a perfect setup. Would this motor controller work better you think? https://www.pololu.com/product/2503 it states that it is arduino stackable and the pins look to match up. What do you think?
     
    papahnash likes this.
  19. Gregg

    Gregg TrainBoard Member

    237
    307
    18
    Scott - thanks for identifying this alternative shield! Based on the specs, I think it can be used for DCC++ and happens to be designed to handle even more current than the Arduino shield. More importantly, it seems to be rated up to 28 volts, which provides more flexibility for powering higher-voltage decoders (I use 15V for my N-scale, but 18V is probably better for HO).

    The Pololu specs also show that you can customize the pin mapping which is important because the defaults do not match what we need for the DCC++ base station.

    The base station assumes that for each output channel, there are two control pins --- one that enables and disables the motor power, and one that controls the direction. The one that enables and disables the motor power is usually defaulted to a PWM-enabled pin on the Arduino. We are not going to use PWM for this control line, so it doesn't matter which pin we use on the Arduino. You'll see in the DCC++ header file that there are two defined constants labeled SIGNAL_ENABLE_PIN_MAIN and SIGNAL_ENABLE_PIN_PROG. The base station software uses these to simply enable or disable overall track power. MAIN is set to 3 and PROG is set to 11 in the software to match the Arduino Shield. The Pololu specs indicate that these control lines are connected to pins 9 and 10, respectively. The pin 9 line is not a problem -- you can either cut the Pololu trace and rewire as per the Pololu instructions to map this control line to pin 3, thereby matching the DCC++ software --- or, simply change the software so that the SIGNAL_ENABLE_PIN_MAIN is set to 9 instead of 3 (which is a bit simpler).

    Unfortunately we can't use the latter simple method for the other control line on the Pololu pin 10 since we need pin 10 on the Arduino to produce the bi-polar DCC signal. So you'll have to cut the pin-10 trace and re-wire to pin 11 to match the DCC++ software.

    Then, for the two control lines that separately set the direction of each output channel, instead of using jumper wires to connect pin 10 to 12 and pin 5 to 13, as per the DCC++ instructions when using an Arduino motor shield, you'll need to connect pin 10 to pin 7, and pin 5 to pin 8, which are the direction controls for the two channels on the Pololu. If you want you can also cut the traces on the Pololu so that pins 7 and 8 are no longer connected to Arduino pins 7 and 8, but it's probably fine to keep them as is provided you never use pins 7 and 8 for anything (may want to add two lines of code in the DCC++ software that sets pins 7 and 8 to "Input/Low" which ensures they are floating and the pull-up resistors are disabled --- this is the default for the Arduino when it is powered up, but sometimes it's good to be explicit in the software).

    In sum, I think you can use the Pololu as a motor shield with only one main modification of cutting the pin 10 trace and moving it pin 11. The other three modifications just require jumper wires to connect the pins differently than done with the Arduino-version of the motor shield.

    Hope this helps!
     
  20. Scott Eric Catalano

    Scott Eric Catalano TrainBoard Member

    205
    57
    6
    Thanks for the detailed explanation Gregg! I will order one of those motor shields and follow your directions and I will report back as this looks very promising. I currently use an Arduino and optical/reflective sensors to determine block occupancy and basic red/green signals on a demo section of track for an On30 layout I am working on. These models are plain DC and I've used an Arduino to control station stops and starts. I've got accustomed to using several input/output IC chips aka shift registers to hook up all of my signal leds and sensors and the DCC++ base station will add another level of operation capabilities. I guess you could say that this is what the DCC manufacturers do NOT want you to know ;-)
     

Share This Page