Geoff Bunza geoffb

With exactly the same low cost hardware and a library of examples ready for anyone to download and use, you can now configure six “mobile or multifunction” decoders to respond to DCC Functions and a similar set of six Accessory decoders to respond to DCC Switch commands. The neat feature is that the Accessory decoders ALSO respond to a programmable single mobile decoder address, so you can configure each of the 17 pins to perform different functions, including their use as a 17 servo accessory decoder driver. This has been updated (Jan 12, 2014) with a Back and Forth Servo configuration in the Examples-- see later comments. The library was updated again Feb.15,2015  to add a new pulsed output function per channel in the Examples folder-- See later comments. As of Sept 16,2015 two new decoder varriants have been built-- See: http://model-railroad-hobbyist.com/node/20739?page=8#comment-209513 (Page 9 of this Blog). Most reccent Update can be found here: SMA20 New Low Cost 17 Channel DCC Decoders with PC Boards & Dual Motor, LED, & Servo Control    https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920

l%281%29.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 0
Tjan70

@Geoff

Hi, Geoff.

Thank you for this, solution is very easy.

Have a nice day.

Best regads,
Sebastjan

My Home Page:   http://potepanja.eu/modelarstvo/

Reply 0
artpier

servo control

Hi geoff.

been hanging out here for a while, but haven't posted before.

I seem to recall a post about using the Arduino for controlling servos for turnouts. I think you were the one that posted it. I believe it didn't use dcc, but controlled them directly(?). it used the code to set limits on the travel. Am I remembering right?

Reply 0
Geoff Bunza geoffb

Servo Control for Turnouts

Hi artpier (name?),

This series is about variations building a 17 function decoder, including servo drives like this:

Bemchtop.JPG 

This work has been going on for some time and now spans multiple entries:

SMA10 – Build a 17-Function DCC Decoder for about $5  https://forum.mrhmag.com/post/sma10-%E2%80%93-build-a-17function-dcc-decoder-for-about-5-12197796
SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos  https://forum.mrhmag.com/post/sma12-17-channel-configurable-multifunction-5-dcc-decoder-for-servos-12198051
SMA 13 - Update to the 17 Pin Configurable Multi Function Decoder / Accessory Decoder Version Added  https://forum.mrhmag.com/post/sma-13-update-to-the-17-pin-configurable-multi-function-decoder-accessory-decoder-version-added-12198262
SMA15: New Dual Accessory-Multifunctionl 17 Channel Configurable DCC Decoders for about $5 with Configurable Servo Support  https://forum.mrhmag.com/post/sma15-new-dual-acessorymultifunctionl-17-channel-configurable-dcc-decoders-for-about-5-with-configurable-servo-12198949
Scale Model Animation 18: DCC Control for Random Building Lighting  https://forum.mrhmag.com/post/sma18-dcc-control-for-random-building-lighting-12200851
SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features

Try starting with SMA20 which is the most recent.

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
Ingo

little Problem

Hi Geoff , I have been following their work , thanks for that with great interest. I've rebuilt several decoders , always with success. Now I have the accessory decoders 17 Pulsed built 5 functions with Arduino Pro Mini , 2 x ULN2803 and 6 relays. Works very well. What bothers me only that the Arduino briefly sets all outputs to active when starting . Can I turn this off ? Sorry , I use a translator Best wishes Ingo
Reply 0
Geoff Bunza geoffb

@Ingo re: Initialization

Hi Ingo,

Quote:

the Arduino briefly sets all outputs to active when starting .
Can I turn this off ?

Yes, you can eliminate this. If you delete the highlighted code below:

void setup()   //******************************************************
{
#ifdef DEBUG
  Serial.begin(115200);
#endif
  int i;
  uint8_t cv_value;
  // initialize the digital pins as outputs
    for (int i=0; i < numfpins; i++) {
      pinMode(fpins, OUTPUT);
      digitalWrite(fpins, 0);   // < ------ delete this line
     }                                          // < -------Leave this line
  for (int i=0; i < numfpins; i++) {
     digitalWrite(fpins, 1);
     delay (tim_delay/10);
  }
  delay( tim_delay);
  for (int i=0; i < numfpins; i++) {
     digitalWrite(fpins, 0);
     delay (tim_delay/10);
  }
  delay( tim_delay);

This will remove the initialization test code.

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
Ingo

Thank you, Geoff

oder_Adr.jpg 

Reply 0
Ingo

Thank you, Geoff

Decoder.jpg 

Reply 0
Geoff Bunza geoffb

@Ingo

Hi Ingo,

Wunderbare Arbeit Ingo!
Das sieht großartig aus. Vielen Dank für Ihre Arbeit zu teilen.

Wonderful job Ingo!
It looks great. Thanks for sharing your work.

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
MikeM

Is there any way consolidated how-to documents for this and

your other terrific projects could be put up in downloadable form on your website?  I've tried downloading some of your project threads from MRH but that's proved to be awkward at best (easily messed up at worst) and for the electronically challenged (at least me) difficult to parse into basic requirements vs. more subtle issues.  Just think, such documents would be invaluable for your next clinic! 

MikeM

Reply 0
Geoff Bunza geoffb

@Mike re: Consolidation

Hi Mike,

Consolidation of many of the projects, particularly the decoder series has been requested before and is a great idea. It is in the queue to be done, but I won't commit to when -- sorry about that. Family and work commitments come first and we have a wedding coming up soon!

Thanks for your encouragement, I will try to raise the re-write priority a bit.

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
PeterBadler

DCC++ and decoders.

Hi Geoff!

First of all, wonderful site and greetings from Sweden!

 

Since I am a newbie to electronics and DCC I am doing something wrong. Aw! Cant get it to work.

Using DCC++ works great with JMRI to run my Kato n-gauge JR trains. Arduino Mega + Arduino Motor Shield 12v 3A. Digitrax z mobile decoders. L9110 motorboards to drive turnouts from DCC++ internal controls via the Arduino mega. (Also tried DCC++ via an Uno. Works fine.)

What I try to accomplish is mobile light decoders for passenger cars and directional lightning for end and fwd cars. Using an attiny85 as decoder to drive leds on custom boards.

 

Uploading your sketch to the pro mini, ok.

But it will not register any output from the 6n137 circuit.

Tried to read the DCC signal using a arduino uno and sniffer sketch. "Unkown command..."

4.6v dc out from sn137.

Could it be the motorshield? Do I need 16v?

Please help and thank you in advance,

Peter.

Reply 0
PeterBadler

The Attiny schematic.

Hi again!

Fixed.

Maybe i should put a capacitator in the led circuit, just in case?

 

Thanks again.

Peter.

Board_01.PNG 

Reply 0
Jim at BSME

re: The ATtiny schematic

Peter,

Sorry I can't help with your question, but you need to resize you schematic in the post so we can see it all.

Edit your post and edit the image properties and set the width to 750, make sure the lock is closed so that the proportions stay the same. You get to the image properties either by left clicking the image and selecting insert image icon in the editor tool bar or right click image and select image properties.

 

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

@Peter re: Decoder issues

Hej Peter,

There are a couple of issues that I see immediately. First, your schematic for C1 across the input to the 6N137 lists C1 as 47uf. That is way too large. The design calls for a 270 pf capacitor. That is 270 pico farad capacitor or 0.000260 uf (micro farad). The large value capacitor used in C1 will filter out most of the DCC signal.

Next, you are using an attiny85 not the mega328P processor on the Pro Mini. The pins and timers on the attiny85 are not arranged the same way, and there are likely other differences. You are in uncharted territory here. I have never tried to use the attiny85 as a decoder, so I don't kow how to advise you as to what needs to be changed. You might want to look in detail at the NmraDcc library to see if there is any advice or documentation there about the use with the attiny85. You might also consider contacting Alex Shepherd the author of the library about modifications for the attiny85.

Last, my decoders will easily work with 12 volt DCC. The latest version of the decoder is covered in SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features  https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920 It is a good idea to direct your comments and questions there.

'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
PeterBadler

Revised ed. Peter. 

Revised ed.

Peter. 

Board_02.PNG 

Reply 0
Geoff Bunza geoffb

@Peter

Hej Peter,

Capacitor C3 is listed as 1pf. That is too low to have any effect on high frequency noise. Try to find something closer to the specified 270pf cap.
 
You have a much bigger problem -- resistor R1 is supposed to be in series with the DCC input, not across C3 and D1. As a result you may very well have damaged or destroyed the input diode in the 6N137. The full DCC 12 Volts waas placed across the 6N137. Please take another closer look at my original schematic diagram in SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features  https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920
 
Again, it is a good idea to direct your comments and questions there. Remember my first set of comments -- the NmraDcc library may not be compatible with the ATiny processor. This needs to be chacked closely.
 
Last, you are driving 3 LEDs through a 270 Ohm resistor directly from the ATiny chip. The max continuous current from most Atmel processors is 20ma continuous. You might want to increase the value of the resistor.
'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
PeterBadler

Thank you extremely much for

Thank you extremely much for the input.

Will do the changes. This was just a idea schematic.

Regarding the lighting of n-gauge japanese trains. The japanese DCC market is very small for n-gauge, Digitrax in conjunction with Kato does decoders for most of their US line. Some have trinkled through to the jap models. Such a lighting decoder working with the standard jap dc lightboards.

This is all very fine but most jap models have the motor in a passenger car as calls for either powercoupling to fwd and aft cars for direction leds even as lighting decoders are installed. Only one function per decoder.

Maybe one could use a transistor to get more outputs but i think its a digital signal. Or search for 2 function decoders to light roof and dir lights.

A thought though, maybe i should use transistors with a cap to get constant dc light? Saw that in Master Rutger Fribergs book. Dont need DCC for rooflight and dir light...

No it wont work with the dir lights since the DCC is ac pulsed. But a rectbridge for roof lights.​

Gives me a headache to think about, but its no fun if it was easy. 

As I said before, being a newbie I had no no plans to go DCC but use Arduinos to drive the layout. Then I stumbled across the suberb DCC++. Now its no end to the fun!

I will redirect next posting of continued test of your decoder and the 6n137 circuit to where you specified.

Thanks for all the help and patience with an amateur.

Peter. 

Reply 0
Heisler wanted

Unwanted sound effects

Hello Geoff, (and others following this interesting blog) !

I have built your turnout decoder, and received a lot of help in the process; much appreciated.

I now have a different question, these tiny servos are very adaptable for throwing turnouts, but the sound

they make is not..... I have screwed my servos to the layout baseboard, which means they make a growling noise

when activated. Has anyone managed to reduce this ?  I realize the problem lies in the tight fastening, but those

servos must sit tight to maintain pressure on the turnout tongues. So, ideas about a soft/tight mounting would be great.

As a sideline I have also installed a DCC++ base station, and built Dave Bodnar's throttle. Next lies controlling turnouts, either from the throttle, which would probably mean extending functions of each button and, as you have

explained before, means somewhat awkward addressing, or by fascia switches. Switches will connect to sensor inputs on the base station(a Mega). Activation of switches will then result in confirmation, in the form of serial data output. This will be sent to the throttle and in turn activate normal turnout control commands. This way all commands will work the "normal" way, and I won't have to touch the BS programming. 

I haven't added the code yet, but the Pro Mini should (?) handle reading serial data and make a "< Q IDID 1> " as serial output, just like throttle code. (or of course < q IDID 0> for the other direction).

Hopefully I will be able to do this reasonably easy.

Regards

Peter

Reply 0
Geoff Bunza geoffb

@Peter re: Isolating Servo Mounts

Hi Peter,

Quote:
I have screwed my servos to the layout baseboard, which means they make a growling noise when activated. Has anyone managed to reduce this ? 
I have had attempts to quiet servos for animation projects. Different kinds of rubber pads to separate the servo from the mount have had some success for me. The type of materials used for your base board and for the mount will definitely have an effect. I have also noticed that different brands of servos generate much less noise than the really cheap 9G servos. Unfortunately, I have always opted for the cheap ones!
 
Peter has a great tutorial on mounting servos in Servos 101 here: https://forum.mrhmag.com/post/servos-101-12203325
You might find some ideas there too, or even ask the same question there or in a new topic (might get more attention).
 
'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
rickygsj

sma15 addressing multiple boards

mr geoff,

built first board and got it running on accessory address 40, using the sketch accdec_7servo_10led_6function.

would like to build and install  2nd and 3rd board using same sketch, but with different accessory address.

what parameters do I need to change in the sketch to get multiple boards running on the same dcc bus?

do you have a table that shows what needs to be changed and their values on the sketch to allow multiple boards to run on the same dcc bus?

I have backread all the posts on the blog and have not come up with a similar problem.

regards,

Reply 0
Geoff Bunza geoffb

@Rick re:Changing Accessory Decoder addresses

Hi Rick,

Accessory decoders addressses can be set by chaning the line (about statement 50 in the sketch):
#define Accessory_Address    40       // THIS ADDRESS IS THE START OF THE SWITCHES RANGE
                                                                // WHICH WILL EXTEND FOR 16 MORE SWITCH ADDRESSES
change the "40" to another address, say 47 for the next group of 17 accessory addresses.
If you need more than 255 addresses you will have to set the CV_ACCESSORY_DECODER_ADDRESS_MSB as well in approximately statement 74:
CVPair FactoryDefaultCVs [ ] =
{
  {CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address},
  {CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
You change the "0" to a number from 0 to 7 for many DCC systems. You calculate the accessory decoder address by multiplying CV_ACCESSORY_DECODER_ADDRESS_MSB that you set by 256 and adding the value in CV_ACCESSORY_DECODER_ADDRESS_LSB which you set in #define Accessory_Address    40
so if you set :
#define Accessory_Address    20
and
{CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address},
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 2},
This would set the accessory decoder address to 2 * 256 + 20  =  512 + 20  =  532
 
You need to understand the limits of your DCC base station. Not all will address up to 2044 addresses.
 
Another issue: my accessory decoder also have a mobile address built into each decoder (currently limited to 1-255 as of Feb 2018). This is used to allow programming of CV's which can define the functions performed by each accessory address/function pin. If you want to use these, then when operating with multiple accessory decoders each of these must be a unique address. This is set in the sketch statement (around 49):
#define SET_CV_Address       24           // THIS ADDRESS IS FOR SETTING CV'S Like a Loco
 
Also please note that this: SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features  https://forum.mrhmag.com/post/sma20-low-cost-17-channel-dcc-decoders-ver-6-01-with-soundtriggered-soundstepperdual-motorled-and-12201920
is the most current revision of this series, and does include most of the information concerning addressing that I provided here. Please post comments to that entry.
 
'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
rickygsj

further inquiry on additional addresses

dr geoff,

thanks for the quick reply

In your response, you said :"

Accessory decoders addressses can be set by chaning the line (about statement 50 in the sketch):
#define Accessory_Address    40       // THIS ADDRESS IS THE START OF THE SWITCHES RANGE
                                                                // WHICH WILL EXTEND FOR 16 MORE SWITCH ADDRESSES
change the "40" to another address, say 47 for the next group of 17 accessory addresses."
 
I believe the next address should be 57 instead of 47, am I correct??
 
I am using an old atlas commander as my dcc base station, the unit can only address up to 99.
 
regards,
 
Reply 0
Geoff Bunza geoffb

@Rick re:More addressing

Hi Rick,

Quote:
I believe the next address should be 57 instead of 47, am I correct??
Yes, you are correct, since there can be aa many as 17 accessory functions per decoder.
Quote:
I am using an old atlas commander as my dcc base station, the unit can only address up to 99.
Remember, that you do not have to start the accessory decoder address at 40. You can set it to start at 1 if you would like, and then increment up by 17 for each additional decoder in sequence (18,35, etc.). Also remember that accessory decoder addresses are independent of mobile decoder addresses (there is no overlap). So you can have an accessory deocder with an address range of 10-27 and still have a non-conflicting mobile decoder with address 20, for example.
 
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
sandovr

Hi, i have been using 10

Hi, i have been using 10 servo 7 led decoder for a while and it really is a very good solution. I have a question - can any servo be set to move continuous from start to end and back until I turn it off?

Reply 0
Geoff Bunza geoffb

@sandovr. RE:sweeping servo

Hi sandovr (name?),

Yes this should be relatively easy.

1. I am literally on a train traveling home so I can’t present you with a solution until Friday.

2. Please address your future questions & comments to the SMA20 article in this blog series as it is the most current.

3. Look for a decoder version that implements a single sweep from end to end, of a servo with each function activation either in the library examples in SMA20 or in the comments/discussion — yes I know it is long. This version, requested by another modeler some time ago, would make a good starting point for you. It will need modifications.

let us know how you do. I will review this again when I return. It should not be too hard to implement.

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