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
Jim at BSME

Other options

There are a couple other USB cable options, which have the pins individually broken out so you can hook them up to the ardunio pins appropriately:

sb_cable.jpg    or you can get this:  b_to_ttl.jpg   this has the pins on the USB to serial adapter labeled so you just have to match the pins one for one to the pro mini.  The first cable will still require checking where you bought it for the pinouts, but likely the red/black wiil be the +5v and gnd.

Another option that you don't have to worry about pinouts of cables is using the Ardunion nano:

nano.jpg  This will need a cable that has a mini usb to standard usb, but if you have an older digital camera you probably already have that kind of cable lying around.  Also you will have to change the build target for the nano if I recall correctly and they are slightly more expensive than the pro mini.

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

A quick Thank You

Hello Geoff

I had time today to load your "released servo" version onto one of our Nano's, currently it's tasked to move 13 turn outs. Wow what a difference, the load was reduced and they all worked so smooth!

But the best bit! No servo noise ......  all my "badly adjusted"

Reply 0
Geoff Bunza geoffb

@Martin

Hi Martin,

Glad you liked it.   I really should have considered the release/detach option before, but I thought that the continued force applied to the points by the servo may be an advantage. With the 9G cheap servos I use, when released/detached they really don't move much at all, so I think that the "always powered" feature is not only not needed, but not desirable. (It was also more work!  )

Look for a new blog entry, SMA20, this weekend. There will likely be some things in it that you and your club could use.

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
Don C

Released version question

Geoff,

Using a modified version of AccessoryDecoder_15ServosReleased_2LED_4Function sketch.

One issue I have noticed is, during the power up routine when each servo is set to its initial position, each servo positioning causes all servos that have already been set to move slightly until setup is finished. I don't know if this is caused by crosstalk on my board wiring, my feeling is not likely, or something in the Arduino itself. Could this be fixed by detaching each servo after setup before going to the next servo? If so, where in the code would the detach statement go? Also might need a delay of 1-2 seconds between setup and detach to allow time for the servo to move to default position.

Another board I have built using the same sketch as a starting point has been modified for 8 servos with 8 led outputs on or off depending on the position of the servo, the code works good. As the switch commands are sent to the board the servos move and the adjacent led lights or goes out. The question is, can the board be set to accept only 8 switch commands versus the current default settings 40 to 55? IE. output 3 to servo 1, output 4 to LED 1, output 5 to servo 2, output 6 to LED 2, etc. thru LED 8 on pin A4. Where sw040 corresponds to output pin 3, sw041 corresponds to output pin 5, sw042 - pin 7, sw043 - pin 9, etc. Im sure these can be assigned to each output pin but I'm unsure how to do it.

Let me know if you need further explanation.

Don

Reply 0
Geoff Bunza geoffb

@Don re: Servo Startup

Hi Don,

There are 2 things that are issues with servo starts: first, without regard to the decoder sketch, I've noticed that when the servo lib first initializes the servo there is a tiny jiggle in the servo. I don't know how or why it occurs. Most of the time I notice it because I hear it rather than notice the motion. Next, completely contained in the decoder sketch there is a sequence that directly effects the servos. First, I originally put in a "self test" feature that turns all the pins on in sequence, then all off in sequence. This is likely now outdated and irrelevant, but was included because the first decoders were built only for LED (digital) control. It made for a neat display, and I would know that everything was hooked up correctly. Worse, I received feedback that people liked it! So I left it in. But... Turning a control line full on to a servo then off jiggles the servo-- often. Next, since decoders nominally don't remember their "state" prior to power up, and that Functions are assumed to power up to "OFF" I wanted to set all servos to their start positions. But turning on all the servos (remember it could be configured to support 17 servos) would generate a power surge that I wanted to avoid. So each servo, in turn, would be returned to their start position. This would conclude the decoder initialization sequence. I doubt very much that crosstalk is a problem for you. I think you are seeing the initialization side effects!

I will be releasing a new set of decoder sketches that incorporate the release/detach feature accross the board (so to speak). I now see no big reason why one would want to leave a geared servo active after its transition stops. Originally, I thought the continued force applied to keep it in place was desirable. As you've seen already the power savings and "servo chatter" elimination are more desirable.

Quote:

The question is, can the board be set to accept only 8 switch commands versus the current default settings 40 to 55?

Absolutely, yes! You would have to limit the number of Switch addresses the decoder responds to by changing the loop ranges it will search for upon receipt of a DCC accessory /switch command. By telling it only look "in a particular range of addresses, you limit what it will respond to. The code was set to maximize the coverage per decoder and it's not set up to change just one variable to do this -- another unforeseen evolution!    Accessory decoders do this differently, I would have to go back and have a detailed look to make sure I covered everything. If you want to have a go at it, please do, otherwise I'll put it on the to-do pile.

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
Don C

@Geoff

Thanks for the quick response.  I'll give it a go and let you know if I figure it out.

Don

Reply 0
Don C

@Geoff

I have a working version of Accessory Decoder setup with 8 servos and a slaved pin for LEDs or whatever per Servo starting with switch addresses 1-8.  I think the only thing left to do would be to eliminate the servo movement during the initial load.

I'll upload the file with a picture of the board when I figure out how to do it.

Don

Reply 0
Don C

@Geoff

What would be the best way to learn C++ as it applies to the Arduino chips? Is there a library or .h file based on the Arduino instruction set? I would have to learn from scratch so.......

I know there is a way to do just about anything you want the chip to do but.. 

In the sketch for 8 servos with a slaved output pin, the syntax for setting individual outputs to "1" or "0" as power on defaults eludes me. Would setting each pin happen in the same place as the tests you setup on power up?

I would like to setup a run once or a run until reset procedure to center servos for initial mounting/setup on a layout or a way to setup each servo as it is installed, combining programming I've seen for the function decoder and the accessory decoder.

As always, I look forward to your response.

Thanks, Don

Reply 0
PetrOs

Hi, I am a hobby DCC Scale TT

Hi,

I am a hobby DCC Scale TT beginner, and I never had something to do with Arduino before, but being an IT guy it should not be a big issue. Time to learn Could you maybe reference a wiring diagram which is to use for attaching arduino board to the rails? Have seen the parts list, but no board layout or wiring plan...

 

 

Reply 0
Geoff Bunza geoffb

@Don re: Questions

Hi Don,

Quote:

What would be the best way to learn C++ as it applies to the Arduino chips?

There are hundreds of ways to approach this, depending on your background. I usually recommend learning the language in the context of using the Arduino, rather than as a separate computer language. Two good places to start are with the language reference:
https://www.arduino.cc/en/Reference/HomePage
/> and by looking through the library examples:
https://www.arduino.cc/en/Tutorial/LibraryExamples
/> Start with examples that you may be interested in or familiar with -- like servos. All of these can be found through the general tutorial page:
https://www.arduino.cc/en/Tutorial/HomePage

If you feel compelled to look at the C/C++ language independently, I like the O'Reilly "Nutshell" books, but they are usually not geared for beginners. The C Programming Language Book by Brian Kernighan and Dennis Ritchie was the best reference I used when learning C.

Quote:

In the sketch for 8 servos with a slaved output pin, the syntax for setting individual outputs to "1" or "0" as power on defaults eludes me. Would setting each pin happen in the same place as the tests you setup on power up?

First, remember that decoders (and base stations) usually power up assuming all functions are set to zero or off. So if you power up the decoder (with servos) assuming functions set to anything but zero/off your decoder will not be set the way your base station/throttle thinks it is.

With that said, servos are initially set in the setup() code. Look for the loop that starts:
for ( i=0; i < numfpins; i++) {
    cv_value = Dcc.getCV( 30+(i*5)) ;   
    //Serial.print(" cv_value: ");
    //Serial.println(cv_value, DEC) ;
    switch ( cv_value ) {

This goes through each possible function pin:  for ( i=0; i < numfpins; i++)
and then keys off the the first of 5 CV values stored for each function.
case 2:   //servo    is for a function that is a servo control.
This code reads the assumed current position, stopping position, starting position, and change increment (regulating speed) for every servo.
switch ( i ) {     picks the particular sevo and this code:
case 0: servo0.attach(FunctionPin0);  // attaches servo on pin to the servo object
           ftn_queue.inuse = 1;
           servo0.write(ftn_queue.start_value);
           for (t=0; t< servo_start_delay; t++) {SoftwareServo::refresh();delay(servo_init_delay);}
           break;

moves the servo to its starting position, slowly, regardless of where it was at last power down.

Quote:

I would like to setup a run once or a run until reset procedure to center servos for initial mounting/setup on a layout or a way to setup each servo as it is installed

OK. If you want to "center" the servos for initial mounting, that is easy. For each servo you want to set, find the table in the sketch that starts with:

CVPair FactoryDefaultCVs [] =
{
  {CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address},
  {CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
  {CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
  {CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
  {CV_DECODER_MASTER_RESET, 0},
  {CV_To_Store_SET_CV_Address, SET_CV_Address},
  {CV_To_Store_SET_CV_Address+1, 0},
  {30, 2}, //F0 Config  0=On/Off,1=Blink,2=Servo,3=Double LED Blink
  {31, 1},    //F0 Rate  Blink=Eate,PWM=Rate,Servo=Rate
  {32, 28},   //F0  Start Position F0=0
  {33, 140},  //F0  End Position   F0=1
  {34, 28},   //F0  Current Position
  {35, 2},  //F1 Config  0=On/Off,1=Blink,2=Servo,3=Double LED Blink
  {36, 1},    // Rate  Blink=Eate,PWM=Rate,Servo=Rate
  {37, 28},   //  Start Position Fx=0
  {38, 140},  //  End Position   Fx=1
  {39, 28},  //  Current Position

...
find the function pin associated with your servo(s)-- look at F1 here. 28 is the default start value in a range of 0-180, so choose 85. 140 is the default stop value in a range of 0-180, so substitue 95. and SAVE the values in your sketch and reload your decoder. Now when the decoder powers up it will be near the middle of the throw! You can change the start and stop values of the appropriate CV's with your throttle until you are happy, BUT WRITE DOWN THE START/STOP VALUES YOU SET, and then you can save them in your sketch. When you set the CV's with your throttle, THEY ARE SAVED in the decoder IF you removed the "//" in the               #define DECODER_LOADED  code as I advise.

// ******** 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

I would recommend you put the values you set for your decoder in the skecth and save it under a separate name specific for your decoder.

'Hope this helps.  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
Geoff Bunza geoffb

@PetrOs re: Wiring Diagram

Hi PetrOs (Peter?),

Quote:

Could you maybe reference a wiring diagram which is to use for attaching arduino board to the rails?

You likely didn't realize it, but you entered into a series of blog posts on the evolution of these decoders. The current and most up to date post can be found here: SMA20 New Low Cost 17 Channel DCC Decoders with PC Boards & Dual Motor, LED, & Servo Control    http://model-railroad-hobbyist.com/node/24316

It includes an updated schematic diagram and also provides a low cost way for you to get PC boards to make it easier to build these decoders. Here is the original diagram:

derSmall.jpg 

and here is the updated diagram:

chematic.jpg 

You might be interested in the evolution of these decoders as found here:

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

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
Don C

@Geoff

Another question. I think I've read that you can run the decoders using railsync out of the loconet cable and that it is less noisy.  Could I hook it up directly to the input of the opto isolator using the same components or would changes need to be made? I know that railsync is not the same voltage levels as the DCC rail signals, around 8 volts under load.  Would I hook it up to pin 1 and pin 6 of the loconet cable?

Thanks, Don

Reply 0
Geoff Bunza geoffb

@Don re: Railsync connection

Hi Don,

Railsync is  supposed to be a duplicate of the amplified DCC signal sent via the rails, so you should be able to connect to it (pins 1 & 6 -- the outer pins of the 6 wires). However, the spec I have read for loconet says that railsync is */- 7 Volts (so its lower than track DCC). I would not recommend using the DCC signal powered powered version of the decoder on Railsync. Only connect it to the resistor (R18) and the 6N137. Leave the diode and the 270 pf capacitor in place, and use an external +5 Volt supply. Since the Railsync voltage swing is almost half the HO track DCC swing, if you don't get reliable data into the decoder, try lowering R18 to 820 or 560 Ohms.

Please note too, I have not tried or experimented with is configuration, but as you point out, others have. I do not remember how successful they were or if they reported their successes.

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
Don C

Thanks Geoff

I'll give it a try. I do use a separate 5 volt power supply to power the project.

Don

Reply 0
Tjan70

@Geoff

Hi, Geoff.

I woul like to download library Pulsed Output Function bu I get error 404. Can you please upload again or send me new link.

I have also question regarding Accessory decoders. Is it possible to change address for Accesory decoder with CV. I know that I can change address for loco address. 

For example. I have Accessory decoder with Address 24 for changing CV's, and Accessory address 40. Is it possible to change that address with DCC comand station?

Thank you for help and answer.

Best regards,

Sebastjan

​

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

Reply 0
Jim at BSME

Link error?

Sebastjan, not sure what link you are using, but the one on the first page of this thread in the first "comment" works fine for me, no 404 error.  Its the link in the paragraph about the new library and examples.

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

@Jim

Hi, Jim.

Thank you. I have overlooked this link.

 

Best regard,
Sebastjan

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

Reply 0
Geoff Bunza geoffb

@Sebastjan re:Accessory Decoder Address Change via CV

Hi Sebastjan,

It looks like Jim pointed you to a working link. Thanks Jim!

Quote:

Is it possible to change address for Accesory decoder with CV. I know that I can change address for loco address.

The way the decoders are currently built, you can only set the starting Accessory address in the code. However, this is a great idea and could easily be done the adding a CV (or two) that holds the address and reading it in the startup code. It should be an easy change, and I'll put it on my to-do list for the next release (no ETA commitment). What decoder version/sketch are you using?  I may be able to change and post that independently without changing all the decoder examples.

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
Tjan70

@Geoff re:Accessory decoder Address change via CV

Hi, Geoff.

Thank your for replie.

I am using AccessoryDecoder_15servos_2LED_4Function.

Here you can see your decoder working with Conrad Switching Mascine in combination with Servos.

 

I am using relay for controling Switching machine. In future I will use L293 for H-Bridge control for Switching machine. I will control Conrad and Tortoise Switching Machine with H-Bridge.

For that i need to group Functions in software, so I can control 8 Switching Machines with one decoder.

Thank you for help, have a nice day.

 

Best regards,

Sebastjan

 

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

Reply 0
Geoff Bunza geoffb

@Sebastjan

OK Sebastjan,

That will be the first decoder version/sketch I will modify.

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
Jim at BSME

Link needs updating?

@Geoff, I try to help where I can.

I was just fooling around and noticed the link at the beginning of this thread might need updating as it points to v4 of the decoder.zip file. I accidently clicked the link and since didn't mean to download it again, went to my downloads to delete the extra copy and noticed I have a v5 of the decoder.zip file.

So maybe one of your other threads points to another version that you have deleted and is where Sebastjan got the 404 error from.

- 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

@Jim B. re:Updating Link -- Now Updated!

Hi Jim,

Thanks for the pointer. I updated the link you found-- much appreciated, again!

I'll take the time and check the other blog entries.

Have fun! 

Best regards and happy new year!

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
Tjan70

@Geoff re:Accessory decoder Address change via CV

Geoff, 

Thank you.

I wish You all the best and alot of happy moment with model trains.

Happy New Year 

Best regards,
Sebastjan

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

Reply 0
Tjan70

@Geoff Grouping funtions

Hi, Geoff

I would like to group few Functions on Accessory decoder.

For example I am trying to group F1 and F9. I am trying with ON-OFF. I need this for H-Bridge for moving Tortoise Switcing Machine. I need to group 2 Funtions because I need two different states on exit of Arduino.

For moving Tortoise in one direction I need a High signal on exit of F1 and Low on exit of F9, for moving Tortoise in different direction I need Low signal on exit of F1 and High signal on exit of F9.

I would like to make 8 groups for that

F1 and F9, F2 and F10, F3 and F11, F4 and F12, F5 and F13, F6 and F14, F7 and F15, F8 and 16

I hope I have write ok, so you can understand.

Thank you for you answer.

Best regards,
Sebastjan

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

Reply 0
Geoff Bunza geoffb

@Sebastjan

Hi Sebastjan,

I do not quite understand what you are trying to do.

Quote:

I am trying to group F1 and F9. I am trying with ON-OFF. I need this for H-Bridge for moving Tortoise Switcing Machine. I need to group 2 Funtions because I need two different states on exit of Arduino.

I do not understand "states on exit." I understand that an H-Bridge needs 2 lines to control it. Why not use a single function (say F1) to control 2 output lines, say FunctionPin1 and FunctionPin9 and have the sketch (the software) always have each pin inverted (FunctionPin1 = 0 and FunctionPin9 = 1 or FunctionPin1 =1 and FunctionPin9 = 0). Would this work for you?

Does this make sense? If not, ask again, and/or add a diagram of what you want to have happen.

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
Reply