Geoff Bunza geoffb

This article describes a small, simple interface to convert DCC signals allowing a wide variety of Arduinos, PICS, Raspberry Pi’s or other processors, to utilize a native DCC signal straight from your layout bus. With this you can build DCC decoders with the likes of an Arduino Mega2650 which has 67 input/output pins available for decoder use, or try using a Teensy 4.0 with 600MHz clock speeds. A low-cost printed circuit board is offered, as well as a couple of interface tips for the modeler. A new library is provided for the use of Arduino Mega2650's as very large pin count decoders.

                               DCC_FEs.jpg 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 1
Geoff Bunza geoffb

A DCC Front End for Arduinos and More

The basic design used here was first presented for use with the SMA20 series decoders - SMA20 Low Cost 17 Channel DCC Decoders Ver 6.01 with Sound,Triggered Sound,Stepper,Dual Motor,LED and Servo Control   https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920  as an integral part of the decoder hardware. It was also used as the hardware platform for the IDEC library described here: SMA35 Interactive DCC Decoders IDEC The Next Generation - Sequencing Movement Sound & Lighting v1.08  https://forum.mrhmag.com/post/sma35-interactive-dcc-decoders-idec-the-next-generation-sequencing-movement-sound-lighting-v1-08-12216854   Here it has been separated for use as a stand-alone board, power by 5 Volts DC, usually from the accompanying processor board, like an Arduino. Header pins can be applied with 0.1 inch spacing for the DCC inout connection and for the connection to your porcessor/Arduino in DCC-Signal, +5 Volt Power In, and Ground (GND) connection just like a servo or sensor would be wired. This has been tried with several boards like the Arduino Uno, Pro Mini, Mega2560, Nano, Micro, Pro Micro, Leonardo, ATTiny167, Tinyzero, Teensy3.x and Teensy4.x series.

The following shows the DCC_FE2 schematicchematic.jpg 

                        DCC_FE2 Schematic

0labeled.jpg   _Labeled.jpg                                                                              DCC_FE2 Board
A New Front End Decoder Board

The new, zipped Eagle board file (.brd) can be downloaded from here:  http://mrhpub.com/files/users/geoffbfiles/DCC_FE2.zip

  As per the directions laid out in SMA20, you can use the Eagle .brd  file to get your boards made at your favorite fabricator. I still use OSHPark.com and have never been disappointed.

%20Board.jpg 
                                 DCC_FE2 Board Wiring

Here is a example using the new DCC front end board with a Mega2650 to create a 67 switch (possible LEDs) accessory decoder with  pin re-assignments. This is based on the AccDec_17LED_1Ftn.ino decoder in the SMA20 library (rebuilt). The DCC signal out connects to the Mega2650 pin 2:

// Production 67 Switch Acessory DCC Decoder    MAccDec_67LED_1Ftn.ino
// Version 7.01  Geoff Bunza 2014,2015,2016,2017,2018,2019,2020
// Now works with both short and long DCC Addesses for CV Control Default 24 (LSB CV 121 ; MSB CV 122)
// ACCESSORY DECODER  DEFAULT ADDRESS IS 40 (MAX 40-106 SWITCHES)
// ACCESSRY DECODER ADDRESS CAN NOW BE SET ABOVE 255
// BE CAREFUL!  DIFFERENT DCC BASE STATIONS  ALLOW DIFFERING MAX ADDRESSES
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
//#define DECODER_LOADED
#include < NmraDcc.h>
int tim_delay = 500;
#define numleds  67
byte ledpins [] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
                   23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,
                   43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,
                   63,64,65,66,67,68,69};          // 67 Pins Available
NmraDcc  Dcc ;
DCC_MSG  Packet ;
#define SET_CV_Address       24           // THIS ADDRESS IS FOR SETTING CV'S Like a Loco
#define Accessory_Address    40           // THIS ADDRESS IS THE START OF THE SWITCHES RANGE
                                          // WHICH WILL EXTEND FOR 16 MORE SWITCH ADDRESSES
                                          // THIS CAN START ABOVE ADDRESS 256
uint8_t CV_DECODER_MASTER_RESET =   120;  // THIS IS THE CV ADDRESS OF THE FULL RESET
#define CV_To_Store_SET_CV_Address    121
#define CV_Accessory_Address CV_ACCESSORY_DECODER_ADDRESS_LSB
struct CVPair
{
  uint16_t  CV;
  uint8_t   Value;
};
CVPair FactoryDefaultCVs [] =
{
  // These two CVs define the Long Accessory Address
  {CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address&0xFF},
  {CV_ACCESSORY_DECODER_ADDRESS_MSB, (Accessory_Address 8)&0x07},
  {CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
  {CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
  // Speed Steps don't matter for this decoder
  // ONLY uncomment 1 CV_29_CONFIG line below as approprate DEFAULT IS SHORT ADDRESS
  //  {CV_29_CONFIG,          0},                                           // Short Address 14 Speed Steps
  //  {CV_29_CONFIG, CV29_F0_LOCATION}, // Short Address 28/128 Speed Steps
  //  {CV_29_CONFIG, CV29_EXT_ADDRESSING


  {CV_29_CONFIG,CV29_ACCESSORY_DECODER
  //  {CV_29_CONFIG, CV29_ACCESSORY_DECODER

  {CV_DECODER_MASTER_RESET, 0},
  {CV_To_Store_SET_CV_Address, SET_CV_Address&0xFF },   // LSB Set CV Address
  {CV_To_Store_SET_CV_Address+1,(SET_CV_Address 8)&0x3F },  //MSB Set CV Address
};
uint8_t FactoryDefaultCVIndex = 0;

void notifyCVResetFactoryDefault()
{
  // Make FactoryDefaultCVIndex non-zero and equal to num CV's to be reset
  // to flag to the loop() function that a reset to Factory Defaults needs to be done
  FactoryDefaultCVIndex = sizeof(FactoryDefaultCVs)/sizeof(CVPair);
};

void setup()
{
   // initialize the digital pins as an outputs
    for (int i=0; i< numleds; i++) {
      pinMode(ledpins, OUTPUT);
      digitalWrite(ledpins, LOW);
     }
  for (int i=0; i< numleds; i++) {
     digitalWrite(ledpins, HIGH);
     delay (tim_delay/10);
  }
  delay( tim_delay);
  for (int i=0; i< numleds; i++) {
     digitalWrite(ledpins, LOW);
     delay (tim_delay/10);
  }
  delay( tim_delay);
    
  #if defined(DECODER_LOADED)
  if ( Dcc.getCV(CV_DECODER_MASTER_RESET)== CV_DECODER_MASTER_RESET )
  #endif  
     {
       for (int j=0; j < FactoryDefaultCVIndex; j++ )
         Dcc.setCV( FactoryDefaultCVs[j].CV, FactoryDefaultCVs[j].Value);
     }  
  // Setup which External Interrupt, the Pin it's associated with that we're using and enable the Pull-Up
  Dcc.pin(0, 2, 0);
  // Call the main DCC Init function to enable the DCC Receiver
  Dcc.init( MAN_ID_DIY, 61, FLAGS_OUTPUT_ADDRESS_MODE


}
void loop()
{
  // You MUST call the NmraDcc.process() method frequently from the Arduino loop() function for correct library operation
  Dcc.process();
}
extern void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint8_t OutputPower ) {
  if ( Addr> = Accessory_Address && Addr < Accessory_Address+67)  //Controls This_Decoder_Address+66
      digitalWrite( ledpins[Addr-Accessory_Address], Direction );
}

This does provide 67 outputs. There are still a few issues. The Mega cannot power that many LEDs at full power. It is limited to 40ma total. If you found ultra bright, ultra efficient LEDs that you could power at 0.5ma each (which do exist) you will have a chance. Next, the NmraDcc library will support 29 functions for the Mobile decoder but you will need to implement the Accessory decoder to get you the broader direct addressing range in one decoder.

I have had need to build these for my own efforts, primarily to use Mega2650’s large pin counts, and also to try the new smaller footprint Arduinos so I can cram them into smaller model spaces. For those modelers who like to try out the Mega2560 as a new decoder platform I have collected some straightforward Mega2650 conversions of both SMA and IDEC decoder sketches that I have experimented with. They work as far as the limited testing I have tried, but have not seen the more extensive testing I usually put my libraries through. These can be downloaded here:   http://mrhpub.com/files/users/geoffbfiles/MDEC.zip    Unzip and copy the MDEC folder in its entirety into your …\Documents\Arduino\library\NmraDcc\examples\  folder.

A complete SMA-IDEC-MDEC library can be found here:  mrhpub.com/files/users/geoffbfiles/NmraDcc-SMA-IDEC_MDEC.zip
and be unzipped and the NmraDcc-SMA-IDEC_MDEC folder be copied to your …\Documents\Arduino\library\  folder in its entirety. If you use this option delete any other NmraDcc library folders you had previously.

Please remember they the MDEC example decoders are specifically set up for the large pin count Arduino Mega2560 board.

I hope this is of help to some of the many modelers who have found the SMA and IDEC decoder series of help to them. As always, appropriate comments and suggestions are always welcome.

Have fun!  [smile]
Best regards,

Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
ErieMan47

@ Geoff- question about R3

First, thanks so much for the great contributions, that continue with this one!

Can you explain why R3, a 5K pullup resistor on the open drain output of the 6N137 optocoupler, is needed?

I see that you enable the internal 20K pullup resistor on the Arduino pin 2:

// Setup which External Interrupt, the Pin it's associated with that we're using and enable the Pull-Up
  Dcc.pin(0, 2, 0);

Is the issue that without R3 the time constant governing the voltage rise on pin 2 from a logic 0 state to a logic 1 state is too long, causing spurious interrupts?

best regards, Dennis

Modeling the Erie RR Delaware Division in the early 1950s in HO
Reply 0
John P

Need an opto-isolator?

Anyone looking for "Device B1" and the 5V regulator should look on the other posting Geoff linked to, the node/24316 one.

I saw there that the resistor R18 was changed to a larger one (physically) as it was getting warm. But I'd have thought that if this device is powered off the DCC system as opposed to having an independent power supply, there's nothing gained by isolating the input signal. Just have the DCC line control a transistor; it could even drive a logic gate (or a processor pin?) via a large resistor.

Reply 0
Jim at BSME

B1 and IC1

These two components (B1 & IC1) are not part of the schematic and/or board, so I guess by what John is saying that they really belong to one of your other threads?

- Jim B.
Baltimore Society of Model Engineers, Estd. 1932
O & HO Scale model railroading
Check out BSME on: FacebookInstagram
Reply 0
Geoff Bunza geoffb

@Dennis reull ups

Hi Dennis,

Quote:

I see that you enable the internal 20K pullup resistor on the Arduino pin 2:
// Setup which External Interrupt, the Pin it's associated with that we're using and enable the Pull-Up
  Dcc.pin(0, 2, 0);

Actually the second zero says to not enable the internal pullup. A "1" like: Dcc.pin(0, 2, 1); would enable the internal pullup.

Quote:

Can you explain why R3, a 5K pullup resistor on the open drain output of the 6N137 optocoupler, is needed?

The specifics of this design originated in 2 1/2 weeks of very frustrating, intermittent failure years ago, trying to get this to work consistently. I put all this together on my bench and initially, unbeknown to me, had a very electrically noisy DCC bus. So after very close reading of spec sheets and application notes, I found that most published DCC interface circuits would not consistently work on my bench. One of the things I realized was the inconsistency of the internal pullup circuitry in the Arduino processor -- which was in reality a misnomer, because many processors are used in the different Arduino board variations, and they so not implement the pullups the same way. From the arduino.cc site:

On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board.

I was trying to optimize the speed of the 6N137, having tried 3 other much slower optocouplers without success. The application notes for the 6N137 all used a 10K pullup but the specs said it could handle a 5K pullup reducing the RC time constant in the rise time. So I chose the 5K pullup R3.

The other side effect of that frustrating time led to the addition of the 270pf capacitor C1, which together with the 1.3K resistor R1 acts as a low pass filter to remove much of the high frequency noise on the incoming DCC signal. I settled on this after a long discussion with a fellow engineer, Gordon Hoffman. I had been worried about putting any filter there for fear of distorting the DCC waveform. The low value cap came after more experimentation and consistently worked. Other designs on the net leave this cap out, and some put an even more elaborate filter after the optocoupler. The problem anyone may have in substituting for the components around the 6N137 is that the circuit may work only in certain "clean" situations and give intermittent results sometimes. I like to say: "It will work every time except when it will not."

I hope this helps you understand this a bit more, and thanks for your kind comments.
Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@John re:Comments

Hi John,

Quote:

Anyone looking for "Device B1" and the 5V regulator should look on the other posting Geoff linked to, the node/24316 one.

Good catch, thank you. These references have been deleted from the article now as they were hastily copied from SMA20 without finishing the edits. These components are irrelevant to this design.

Quote:

I saw there that the resistor R18 was changed to a larger one (physically) as it was getting warm.

I originally changed R18 from 1K to 1.3K to reduce the load a tiny bit on the DCC bus. I never saw this resistor get warm, nor was it changed to a physically larger component. When I build my decoders I stick whatever I have around in that fits the job.

Quote:

there's nothing gained by isolating the input signal. Just have the DCC line control a transistor; it could even drive a logic gate (or a processor pin?) via a large resistor.

Actually there is quite a lot to be gained by using an optoisolator. First, the DCC bus by definition does not have a ground reference. It is driven "differentially." It is the difference between the two bus wires that comprise the signal and the power delivered. The moment you sense the DCC signal with a ground reference (and remember that this would be a local ground at the decoder with the corresponding local power source -- not likely a floating source too) you run the risk of ground loops and forcing a ground reference for the DCC bus. Such risk could be compounded by other decoders in other locations, all with different local ground references. In one case with a small DCC++ base station, this led to the failure of the bus driver in short order. Remember that DCC buses run long sometimes. Also, as a designer of decoders, you just simply don't know what people are going to attach to their DCC buses! It is a far better design, far safer, and far more reliable to optoisolate the decoder from the bus.

If you controlled the entire DCC environment -- always -- and were completely conscious of every decoder, driver, and attachment, you would have a better chance of successfully implementing your suggested approach. However, I would not recommend it, as it is prone to error in the common case.

'Hope this helps. Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Jim Correct (with a blush)!

Hi Jim,

Thanks for the catch. You are correct, as usual.
As explained above, I copied and did not edit out the obvious... duh! 

Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
ErieMan47

@Geoff- pullups

Thanks for the explanation.  Makes sense.  I did not know that the Arduino pullups were so varied, and even if they were an honest 20K ohms, that feels like a pretty large pullup value for a signal that you want to have a fast rise time.  My bad for not realizing that the comment "enable the pullup" did not match the actual argument passed in the function call.  (you might want to edit a correction to the comment in your code?

Modeling the Erie RR Delaware Division in the early 1950s in HO
Reply 0
Geoff Bunza geoffb

@ErieMan47 re:Wrong Comment

Hi Dennis,

Thank you very much for pointing out that the comment doesn't match the code!
This is likely another ancient artifact of my battle with the DCC front end, and I should have fixed it a long time ago. It's on the list (and I bet propagated to a whole bunch of sketches too!) Yuk!

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
John P

Isoolation

Geoff, I agree with what you said about the need to maintain isolation from the DCC bus. But unless I'm massively misunderstanding it, your DCC_Decoder3 isn't doing this. What you're doing is rectifying the DCC voltage via B1, then regulating it down to 5V relative to the low side of the rectifier, and powering your Pro Mini off that. To have an isolated system, you'd need to couple to the DCC bus via a transformer, or eliminate the rectifier and power the DCC_Decoder3 independently. What's called "GND" in that circuit will actually be at a voltage one diode drop above the lowest voltage that the DCC bus gets to. If anyone connected other equipment to that GND, they might run into problems!

That's the way it looks to me. Or have I missed something important?

Reply 0
Geoff Bunza geoffb

@John P Not Isolation but Floating the whole decoder

Hi John,

Correct, yes and no. Absolutely rectifying and filtering the DCC signal is deriving power delivered, but typically that power supply is not grounded to anything outside the decoder circuit, so the entire circuit is "floating" and the "Ground" reference in the schematic is merely a common reference point in the circuit. If I were to tie that ground to another power supply ground, or earth ground, then it would no longer be a floating reference. If you note in this article for the DCC front end, there is no power derived from the DCC bus, only the translated, and optoisolated DCC signal is used. This front end is indeed isolated (relative to the DCC bus) and can be attached to any locally powered device. When I use the SMA series of decoders to power a bunch of servos, I never use the DCC-on-SMA20-board power source, especially since it could not be made to source more than 2 amps, but use the 6N137 to isolate the DCC bus as described.

'Hope this makes things a bit more clear.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
FrightRisk

Beat me to it yet again!

I was just in KiCad trying to see how small I could make a board just like this from the original from your decoder since I didn't want to waste the 17 function decoder boards just to have a DCC interface. I spoke to one of the other DCC-EX team members if he could finish it. And good thing we didn't waste too much time on it Thanks again Geoff.

Fred

Reply 0
DavidJones

this is amazing stuff, but I'm confused- have a real beginner ?

I'm fairly new to the arduino world, but have had a few, small, minor projects succeed.  As I understand it, you're using an arduino with many output pins to output an on or off, low power signal decoded from the DCC bus.

I'm wondering how you can use this for things other than turning on or off a couple of LEDs.  Specifically, I'm contemplating adding a yard to my layout with a multitude of turnouts.  I would love a solution that doesn't involve group after group of expensive stationary decoders that operate 4 switches each.  I think I have a better conceptual understanding of how this could be used by the arduino to turn on and off animations/sound et (eg- if dcc accessory address 941 gets a cv 79=1, then make this sound, start this motor to turn this many degrees) .  As I understand it, a turnout switch requires an electrical current (more than an LED's-either between a ground and one wire, or a current that can flip positive to negative (peco/tortoise vs kato).  I THINK I could make an arduino project that could direct a current in either direction for a fixed length of time, but as I'm thinking of it, I'm going to need a round of arduinos and presumably some transistors to make this happen (I'm assuming the output of these wonder pins won't come near the power to trip a turnout- I know the stationary decoders I have have capacitors that discharge to do this).

Is there an easier way to do this?  Easier way to think of this? I want to use the kato type of turnouts.

Thank you

Reply 0
mijnmodelbaan

Amazing stuff

Hi Geoff,

Amazing stuff, again! Thanks to your blog posts (and those of others) I dived into the Arduino stuff after my retirement. In several schematics on the net I noticed the 1N4148 (D1 in your schematic) is replaced with an LED. This would give one a visual indication the dcc signal is coming in. Like to know your thoughts about that.

BR//Willem.

  

Willem from Rijen, the Netherlands.

Modelling the Wiesentalbahn, Zell im Wiesental, mid-century in N (that is, after we move to the new house).

read my blog

Reply 0
Geoff Bunza geoffb

@David re: Arduino based decoders

Hi David,

I think you need to start your exploration with: SMA20 Low Cost 17 Channel DCC Decoders Ver 6.01 with Sound,Triggered Sound,Stepper,Dual Motor,LED and Servo Control  https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920  and start with the simplest decoder in the library: Dec_17LED_1Ftn which is a 17 function mobie decoder or the AccDec_17LED_1Ftn which is a 17 function accessory decoder. Then look at Dec_17LED_6Ftn and AccDec_17LED_6Ftn to see how the 17 pins can be reconfigured beyond simple switches to control servos and the like. The other variations in the library will enable you to control DC motors, sound modules, stepper motors, and groups of LEDs. When you master those you can have a look at the IDEC decoders here:  SMA35 Interactive DCC Decoders IDEC The Next Generation - Sequencing Movement Sound & Lighting v1.08  https://forum.mrhmag.com/post/sma35-interactive-dcc-decoders-idec-the-next-generation-sequencing-movement-sound-lighting-v1-08-12216854  which are more configurable, complicated, and readily adaptable to animation projects.

In the SMA20 library there are decoders capable of generating short pulses on pins which can control solenoid-equpped track switches where the Arduino pin connects to a small 5 Volt realy to carry the high currents those switches require. Read through the comments in the SMA20 article. Other modelers have done this before.

For more projects beyond the individual decoder, have a look at the rest of the projects here: https://forum.mrhmag.com/journals-was-blogs-891775

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Willem re: A LED for the 1N4148

Hi Willem,

I noticed the 1N4148 (D1 in your schematic) is replaced with an LED. This would give one a visual indication the dcc signal is coming in. Like to know your thoughts about that.

This is an interesting question. The 1N4148 is a fast diode used to protect the LED inside the 6N137 optocoupler from high reverse voltage. The raw DCC signal presents itself to the 6N137 as a voltage changing from roughly +14 Volts to -14 Volts. With the 1.3K dropping resistor this allows the 6N137 to detect the positive side of the DCC signal. the specs for the 6N137 diode specify a maximum reverse voltage of 5 Volts, so the 1N4148 is needed. Substituting a LED for the 1N4148 will likely work -- most LEDs are pretty fast, likely fast enough, and the forward ("ON") voltage will range from about 1.7V to 3.2V depending on the color of the LED, and assuming that one does not use one of the newer ultrabright multi-LEDs in a single package. The forward voltage drop of the 1N4148 is more like 0.6V, but the higher forward voltage of most common LEDs are still within the 6N137 spec.

Because the DCC signal is generating an idle pattern on the DCC bus whenever there are no commands being sent, the LED substituting for the 1N4148 will be ON as long as the DCC bus is powered. It would not necessarily indicate that DCC commands were being sent.

Last issue -- the 1.3K dropping resistor was chosen to meet the specs of the 6N137, not some external LED. So if the 1.3K resistor is providing too much current to the substituting LED, it may shorten the life of the LED. Regardles, I would avoid changing the 1.3K resistor to adjust the brightness of the external LED in any way, with some small concern for messing up the DCC detection of the 6N137.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
DavidJones

Thank you

 back in time to the older info mentioned.  The SMA-20 having a library on how to through a relay to send pulses- that is the idea that was eluding me- I'll get caught up on my homework

 

Thanks again

Reply 0
mijnmodelbaan

@David

David,

You could use a relay, a standard one with all the clicking, or a solid state one (no clicking, but quite expensive) or you could build one yourself with an opto coupler and a Fet (or transistor, triac), something like this:

image.png 

The left is coming from the Arduino, right is out to a 'heavy' user, maybe one coil of an electromagnetic point.

The opto coupler is there to separate both power circuits so one can still use the dcc circuit to power the Arduino part.

I'm using these myself, 16 one of them on a single pcb for driving 8 points or some lights. I'm not using a complete Arduino board, but only an ATMega328P with some extra components for the mcu and dcc and power. All aboard the pcb.

As I understand your Kato points need to switch polarity for driving. Maybe you could use an H-bridge for that, like Geoff used in one of his previous SMA posts (20+)? Just an idea, didn't try it myself, but who knows, it might work.

BR//Willem.

 

  

Willem from Rijen, the Netherlands.

Modelling the Wiesentalbahn, Zell im Wiesental, mid-century in N (that is, after we move to the new house).

read my blog

Reply 0
FrightRisk

Substituting an LED

This is exactly what Iowa Scaled Engineering does with their shield version of a decoder/sniffer that stacks on an Arduino. They use an amber LED to indicate the presence of a signal when you connect it to the track. As Geoff said, all it gives you is current in the right direction, so you could hook a battery up to it the right way and the LED would light But it is a nice indication of voltage on the track. With DCC, the LED is actually pulsed at an average of about 8000 times a second.

https://www.iascaled.com/store/ARD-DCCSHIELD

They sell the board, but the schematic, CAD files, etc. are all open source and linked in the page above. Have fun experimenting!

Fred

DCC-EX

Reply 0
Martin Kirkby

Railcom

Hello Geoff

We have been experimenting with Railcom using our ECoS command station and have noticed that our Nano/DCC decoder units are not as reliable at switching turnouts/servos, have you any experience with Railcom?
 

Reply 0
Geoff Bunza geoffb

@Martin re: Railcom

Hi Martin,

Sorry , I do not use Railcom, nor do I have any appropriate experience with Railcom issues.

DCCWiki (https://dccwiki.com/Term:RailCom) shows there have been decoder compatibility problems with Railcom. Unfortunately they indicate the solution was to turn Railcom off. A web search of Railcom problems indicates problems are easy to find.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Dave Hoskins

Clarification please

Geoff

Many thanks for this - it’s really useful.

Sadly, I do not understand the following lines in the sketch.

// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
//#define DECODER_LOADED

Having uploaded the sketch, when and how do I delete the “//“.   Do I upload once then amend the sketch and immediately upload again.   Sorry, just unable to fathom this!

Regards

Dave

Reply 0
Michael Tondee

I must have missed this.

I must have missed this. Could I use this circuit with a H-bridge to build a DCC++ booster?

Michael, A.R.S. W4HIJ

 Model Rail, electronics experimenter and "mad scientist" for over 50 years.

Member of  "The Amigos" and staunch disciple of the "Wizard of Monterey"

My Pike: The Blackwater Island Logging&Mining Co.

Reply 0
Geoff Bunza geoffb

@Dave re: Editing to uncomment

Hi Dave,

Quote:

Having uploaded the sketch, when and how do I delete the “//“.   Do I upload once then amend the sketch and immediately upload again.

When you upload/configure/setup your decoder, you start up the Arduino editor, open the sketch file, and then upload the sketch/code to the Arduino. Before you upload to your Arduino, the sketch you see in the window in front of your eyes can be edited -- characters added/inserted at the cursor set by your mouse pointer. So find the statements in question:

// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOLOWING LINE!!
//#define DECODER_LOADED

position the cursor to highlight the //  at the beginning of the line: //#define DECODER_LOADED
and delete the "//" characters at the beginning, just like you would edit an email or text document.

So,,, the sequence of events for you would normally be:

1.  Completely load your sketch into the Arduino editor from the Examples library unmodified
and
2.  Delete the "//" characters in the line: //#define DECODER_LOADED
and
3. Upload your edited sketch again to your Arduino

The first upload will set up all the CV's for the first time. The second upload will allow you to change the CV's by programming the decoder On The Main (and only On The Main - no service mode programming).

Why do you need to do this, you might ask? Because when  you receive your Arduino from the manfacturer, one doesn't know what the contents of the EEPROM (Electrically Eraseable Programmable Read Only Memory) have been. The EEPROM is the memory in the Arduino where the decoder CV's are saved, and they will be there after powering off and on again.

Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Reply