How to convert DCC decoder signal to Arduino digital in?

drken Dec 1, 2017

  1. drken

    drken TrainBoard Member

    344
    200
    19
    I want to use my DCC controller (DCC++ & JMRI) to send a digital signal to an Arduino, which will then light up LEDs and spin motors on my layout. Basically, I want to offload my town/industry lighting/animation to something designed specifically to do just that. I checked around using Google, but everything I read tells me how to turn an Arduino into a decoder, which is not what I want. So, how do I convert the 12-15V 250mA (or thereabouts) into the 5V 30mA signal my Arduino needs? Does anybody have any experience doing this before I fry some perfectly good electronics?

    Also, in a related question, what decoder has the most functions? The most I can find is 8 (outside of signal decoders, would that work?). I'd like to see one with 20 or so, which I could control my whole town with, but I don't think that exists.
     
  2. PaducahnLouisville

    PaducahnLouisville New Member

    5
    1
    9
    The 5V is what power the board it is not the " signal"
    I think you are getting things mixed. the 12-15v in dcc++ is what the motor shield takes as power supply to drive the power to the track and carry the DCC++ PWM signals to your decoders.

    the main arduino boards can only handle the 5V which is why they have you cut the traces on the motor shield to keep the 12-15 volts off the main board


    I think what you are looking for is to program a micro controller to turn on specific parts of you animation separate form control it from DCC++.
    You would have to write a program to do certain functions ( such as turn on an LED, turn on a circuit that drives a motor etc)
    If you are looking to control this with DCC++ and JMRI you will have to build arduino as a decoder. You would still have to have other supporting electronics to drive the animations and lights no mater what you choose.

    We have a full sized train simulator that takes commands from a real engine control stand at our museum. i am replacing the electronics with two arduino pro minis. I programmed the arduino to take certain switch closures (levers on the control stand activate relays that act as a "push button") arduino reads the closure of the relay to ground and in turn them in to Keyboard letters to drive the simulator software. relays are hooked between an arduino input pin and ground, when the program sees ground on that pin in " presses" a key on the keybaord in the software. The arduinos get power from the PC the relays have their own separate power supply and never the 2 shall meet.
     
  3. drken

    drken TrainBoard Member

    344
    200
    19
    That setup sounds neat, are you using the minis to simulate a USB keyboard, or is there some software interface involved? Don't worry, I have no intention of exposing an Arduino to track current. Here's what I want to do:

    If I put a 5V, 20 mA current to a I/O pin on a nano, it will read that pin as HIGH. If I put a "while digital.Read(pin) == HIGH" conditional in that Arduinos code, I can put everything after that under the control of that pin, which is under the control of the decoder, which is controlled JMRI. Here's the problem. According to Digitrax, its function current rating for its decoder is 125mA but there's no voltage mentioned, so I'll assume it passes through track voltage, in my case 12V. This will kill my Arduino if I wire it directly to an I/O pin. Theoretically, all I should have to do is put the appropriate resistor between the decoder and the Arduino like people do with LEDs and make sure the function is set to on/off. Is building an Arduino based decoder the only answer?
     
  4. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    86
    6
    The best option would be to connect your decoder output to the LED input of an optoisolator, and connect the Arduino to the output of the optoisolator. This will provide full isolation between the DCC decoder and the Arduino while passing the signal.
     
  5. drken

    drken TrainBoard Member

    344
    200
    19
    That's clever. Plus, I think I have an optoisolator lying around here somewhere. Thanks.
     
  6. PaducahnLouisville

    PaducahnLouisville New Member

    5
    1
    9
    Yes I am using the minis as a keyboard emulator.
     
  7. AlexW

    AlexW New Member

    5
    0
    7
    This is a good question and topic. My setup is DCC++ on an Arduino Uno with JMRI. I wanted to control lighting and animation with a second (or third) Arduino and I found a solution by Geoff Bunza on MRH. Basically, he interfaces an Arduino Pro Mini to the DCC controlled track using an opto coupler, as mentioned above. I've replaced the Pro Mini with an Arduino Nano because that's what I had on hand. Geoff has included code for the Arduinos in various configurations of outputs - LEDs and servos. The LED version controls 17 LEDs with various effects (steady, blinking, etc.).

    Here's the neat part - you control the Arduino outputs with a JMRI throttle's Function buttons. You set the address in Geoff's code and it's very simple to change. You can add a second board by simply giving it a different address, just like you would add a second loco.

    These are low cost but effective solutions. You will need the Arduino (about $3 for the Nano), 3 resistors, a small cap, a cheap diode (1N4001), and the opto coupler (6N137). Of course you'll need the LEDs (with current limiting resistor) and/or servos, depending on your requirements, but the control system is under $5. You can do more, such as adding a 5V power source by rectifying and regulating track power. I don't bother with this since I ration track power. Instead, I give the Arduino a separate 5V external supply.

    This solution has worked great for me and I would be interested in any related feedback.
     
  8. drken

    drken TrainBoard Member

    344
    200
    19
    That's actually what decided to go with and just got the boards in yesterday (y). I'm going with the Arduino Pro Mini for now. Might switch to a M0 based board at some point. The plan is to use the LED only sketch and use that to send a signal to another Arduino. That way, I'll have up to 17 boards that I can control from PanelPro per each decoder. I haven't decided to send the pins HIGH or to ground to trigger the sketch, but I have time to play around with that.
     
  9. AlexW

    AlexW New Member

    5
    0
    7
    Sounds like a good approach, let us know how you make out.
     
  10. drken

    drken TrainBoard Member

    344
    200
    19
    Funny story, once I figured out how to link 2 Arduinos using I/O pins, I realized there was a simpler solution. Rather than have a bunch of Arduinos connected to the 17 function decoder in a hub and spoke fashion, I realized it would be simpler to alter the DCC Decoder code so that instead of sending a HIGH signal to an I/O pin, it calls a function that contains the code I was going to upload to the second Arduino. This would turn it into a DCC/Arduino interface, rather than a 17 function accessory decoder. Or, since you could have the decoder respond to as many addresses as functions you can fit in a microprocessor's memory, you could call it an "infinite function" decoder despite the obvious limits. This works great for my purposes as I would be able to light up a structure in many different patterns using a single Decoder/Arduino instead of running a separate wire between the decoder and the Arduino for each one. MUCH simpler.
     
  11. mrtinvan

    mrtinvan TrainBoard Member

    34
    8
    9
    There is the Geoff Bunza 17 Function Stationary decoder that also will serve this exact purpose. Otherwise with some googling, there are many schematics for Arduino based stationary decoders.
     
  12. mikegillow

    mikegillow TrainBoard Member

    116
    117
    13
    Dave Bodnar has a number of things on his site. http://trainelectronics.com/DCC_Arduino/index.htm is using Geoff's 17 function controller code and design. Based off that he created a stationary decoder that supports three servos and a relay (http://trainelectronics.com/DCC_Arduino/Decoder_board/index.htm) and he was offering the circuit board for sale (I bought some from him 2 years ago). My layout has had to take a back seat to other things for most of the last two years so I haven't constructed them.
     
  13. drken

    drken TrainBoard Member

    344
    200
    19
    Well, I haven't back heard from Geoff, so it looks like I'm on my own (aside from the help I'm getting here, which is appreciated). The current plan is to strip everything that isn't necessary from the circuit board leaving only the optocoupler, a diode, 2 resistors, a capacitor, and the Arduino. My personal preference is to give everything its own power supply (or at least its own line off a 5V rail), so I can dispense with the rectifier and attendant components as I power the Arduino directly. There's no reason for this not to work, but that's never stopped me from failing before. ;)
     

Share This Page