SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos

geoffb's picture

One of my earlier entries:  SMA10 – Build a 17-Function DCC Decoder for about $5 ( http://model-railroad-hobbyist.com/node/19070 ) generated a considerable amount of interest regarding the possible enhancement for controlling Servomotors (Servos). This is my next version of a 17 Channel Multifunction DCC Decoder based on a low cost $2.56 Arduino Pro Mini. This version supports configuring each of the 17 function pins for On/Off (LED/TTL) Control, or Configurable Blinking Control, or Configurable Servo Control, or Configurable Pairs Blinking Control. Yes, that does mean it can support 17 servos, each with rate, start point, and end point setting via DCC CV’s, per pin, as well as new LED configurable functions. Read On. Additional doc found here: http://model-railroad-hobbyist.com/node/19775 There is another decoder version added herein. Look for "New Decoder Version to Control Lighting Groups" in Page 12 of the Comments: http://model-railroad-hobbyist.com/node/19446?page=11   The most recent Update 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

Comments

Newbie needing help

Hello.

My name is Roberto and I just registered to make this help request. I'm completely new to Arduino, and with little experience with DCC. I've been following this thread with interest, but it seems I'm getting lost very easily.

I will start saying what I did until now:

1) studied the circuit reported in the beginning of the article

2) acquired all the components

3) Mounted the circuit on a breadboard in a led only configuration, connecting only F0 to F4

4)Downloaded the SW from the link in the page and copied the 2 directories NmraDCC and Softwareservo in the Arduino libraries directory

Here is where I get the first problem. My configuration should be contained in the dir examples/Decoder_17LED_1Function but in this directory there is another file named "DecoderNmraDcc_4.ino". If I try to open it in Arduino IDE it says is not possible and wants to put it in another directory. If I let it do it and compile, I get the following error during compilation:"exit status 1 redefinition of 'int tim_delay'" and it aborts. What is this?

I've tried opening other versions, but I get several errors about NmraDCC library not being correct.

I've also tried to compile the "AceesoryDecoder_17LED_1Function" (I'm using a PL2303 USB/TTL cable using Arduino IDE 1.6.10 on Win10 Home Edition), and after some failed attempts, I successfully  loaded the SW into the Arduino Pro Mini. It seems like a hit and miss procedure though, not consistent, as sometimes I get error and some times I don't.

I then put the Arduino on the breadboard, connected the input to the tracks and fed the circuitry with a +5V power supply.

When I switch on, the 4 leds I´ve installed to monitor the function, all correctly cycle once.

I've tried to control the decoder with my NCE Powercab to see if i could switch the leds on and off separately, but if I use the accessories decoder function, after inserting the decoder address, the Powercab only lets me switch it on by pressing 1, or off by pressing 2.

Needless to say that it's not working.

As you may see, I've got several problems on several different stages.

To make things work, I suppose we must restart from the basics, and here is where Geoff can help me.

I need to have all the files you supplied in the zip file all checked by you in their working version. I've tried to download the updates posted in the comments but I get a file not found error.

I need to confirm that the latest circuit of this version (SMA12) is the one at the beginning of the article. I'm pretty confident it is, since the startup of the circuit works as expected, but it sdeems I cannot communicate with the decoder via tracks signals (don't know if it's something inherent to the decoder or to the powercab) 

I need to know in what the  "AceesoryDecoder_17LED_1Function" version differs from "Decoder_17LED_1Function", and if i can use the former to test the decoder or if the latter is mandatory.

This will help me to avoid macroscopic errors, and maybe some of the experienced people here can give some clues on how to proceed to make things work.

I know that I'm asking alot of things all at once, and please forgive me for this long message, but I would really like to come to an end (a happy one) with these issues because I think that this project has alot of potential.

Thank you very much in advance. Best Regards,

Roberto

 

 

geoffb's picture

@Roberto re: Questions and Updates

Hi Roberto,

I'm sorry you are having difficulties. The library you downloaded was an old version. I have updated the link in this Blog entry to the correct and current library: /sites/model-railroad-hobbyist.com/files/users/geoffbfiles/new-dual-multifunction-decoderv5_3.zip

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

SMA10 – Build a 17-Function DCC Decoder for about $5  http://model-railroad-hobbyist.com/node/19070
SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos  http://model-railroad-hobbyist.com/node/19446
SMA 13 - Update to the 17 Pin Configurable Multi Function Decoder / Accessory Decoder Version Added  http://model-railroad-hobbyist.com/node/19775
SMA15: New Dual Accessory-Multifunctionl 17 Channel Configurable DCC Decoders for about $5 with Configurable Servo Support  http://model-railroad-hobbyist.com/node/20739
Scale Model Animation 18: DCC Control for Random Building Lighting  http://model-railroad-hobbyist.com/node/23026
SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features

The last entry SMA20, is the most up to date and is referenced in this entry SMA12, in the intro.

The Decoder file you are looking for is now Dec_17LED_1Ftn

Accesory decoders use Track Switch DCC commands (Closed/Thrown) instead of DCC Function commands. Read up on these with whatever DCC command station you use. The decoder can be configured either way. More details are in the writeup -- see SMA20.

The circuit has not changed since the beginning. I f you use the same circuit and the same components, it should work quite well -- better than any other one I've tried.

Always ask questions-- it is how we all learn.

Have fun!  smiley

Best regards,

Geoff BUnza

@Geoff: thank you

Hello Geoff.

Just an hour ago I received an update warning from the Arduino NmraDCC libraries. I updated them, tried to upload the 17LED 1FTN and it loaded succesfully on the Pro Mini. When i power up the circuit it now cycles the lights correctly.

Still have to figure out how to communicate with the decoder. I'll have to study thoroughly the SMA20.

Thank you very much for your help and will to share your huge knowledge with fellow unexperienced modellers like me.

Grateful,

Roberto

Too good to be true. More errors on the way.

Hi Geoff,

After the initial enthusiasm injection, here I am again with problems.

As i said in the previous post, the first upload to the Pro Mini was successful.

As you mentioned, to retain the values in the EEPROM memory, is recommended to overwrite the program by enabling the #define DECODER_LOADED by toggling the // characters

When I compile the second version, i get the following error

'CV_DECODER_MASTER_RESET' was not declared in this scope

pointing at line 83

82| #if defined(DECODER_LOADED)
83|  if ( Dcc.getCV(CV_DECODER_MASTER_RESET)== CV_DECODER_MASTER_RESET )
84| #endif

Am I missing something?

UPDATE: I finally succeeded in communicating with the decoder. I made a mistake in the circuit setup (reversed the polarity of the 1N4148 input diode) which I corrected and used the Powercab throttle with Loco address #24 to switch on/off the functions. Works like a charm!!!

Now I need to solve the above compiling error. I started to debug it, but i'm completely ignorant with C++ commands, so I may require a lot of time to learn the correct syntax and logic of commands to find the error.

Is it correct that the DECODER_LOADED variable is declared but unassigned (no value?)

Thanks

Roberto

geoffb's picture

@Roberto re: Error

Hi Roberto,

Yes, there is a line missing! Somehow the definition for CV_DECODER_MASTER_RESET got dropped in editing. Here is what it should look like:

const int FunctionPin13 = 16;     //A2
const int FunctionPin14 = 17;     //A3
const int FunctionPin15 = 18;     //A4
const int FunctionPin16 = 19;     //A5
NmraDcc  Dcc ;
DCC_MSG  Packet ;
uint8_t CV_DECODER_MASTER_RESET = 120;
#define This_Decoder_Address 24

I have fixed and uploaded the new library here:

/sites/model-railroad-hobbyist.com/files/users/geoffbfiles/new-dual-multifunction-decoderv5_3.zip

FYI, as of this instant in time the above linked library is more current than the NMRAdcc library that will auto update.

This was entirely my mistake, not yours. I re-looked at the other decoder files and they also look OK. Thanks for catching this for everyone. Have fun!  smiley

Best regards,

Geoff

Update working

Hello Geoff,

I'm glad I could help to find out a little bug. The installation was successful.

I also tried the version with 6 functions with blinking and fading lights and it works great . I've noticed although that if contiguous lights (i.e. F0 and F1)  are set to blink or fade, if both activated simultaneously,  the second one only really activates after i release the button of the the previous to deactivate, and only then it starts to blink or fade. Is it supposed to work like this? It would be nice to have something that allows alternated blinking or fading lights, like ditch lights on locomotives, or a railroad crossing.

Thank you for your invaluable support once again.

 

Roberto

geoffb's picture

@ Roberto re: Dual Blinking LEDs

Hi Roberto,

I'm glad you have your decoder working.

if contiguous lights (i.e. F0 and F1)  are set to blink or fade, if both activated simultaneously,  the second one only really activates after i release the button of the the previous to deactivate, and only then it starts to blink or fade. Is it supposed to work like this?

For Dual Blinking LEDs, you should not attempt to set or control the second LED in the pair -- leave it alone and operation should proceed just fine. Attempting to control the second LED will temporarily confuse the decoder timing.

Have fun!  smiley

Best regards,

Geoff

change blink rate

Hello Geoff,

thank you for your explanation. Double blink function is working correctly now. I've found the instruction on how to configure the CVs. This is a very smart project!!!

Best regards,

 

Roberto

Servo controlling

Hello Geoff,

Just going on exploring. I converted the circuit from test protoboarding to PCB layout, and after some debugging (forgotten tracks, short circuits, anyone?) I'm ready to go.

I just received two 9g Arduino compatible servo motors and was testing functionalities. I set the servo controlling channel to F6, by programming the following CV with the values you suggested

CV60=2(setting servo)

CV61=1(rate)

CV62=28(start position, F disabled)

CV63=140(stop position, F enabled)

CV64=28(default position)

It happens that the servo is not moving. I just hear a faint tick sound when pressing the function number, but no visible movement. The servos are working because they shake when i connect them. I also tried to set up a different channel (F7) with the same result.

Could you please explain the CV effects, especially CV61 (value range and relationship with actual angular speed), CV 61 and 62 ( what zero is and what 255 is, such like 0=0deg and 255=360deg)?

I'm so excited to see this project working  at full steam.

Thank you.

 

Roberto

geoffb's picture

@Roberto re: CV settings for Servos

Hi Roberto,

First I am going to state some assumptions for my response: I assume you are using a Mobile/Function decoder and NOT an accessory decoder. I am also assuming that your "two 9g Arduino compatible servo motors" are likely the cheap, generic, 9G servos -- not name brand, nor metal gears.

The CV's for F6 are:

  {60, 2},      //F6 Config 02=Servo control
  {61, 1},      // Rate  control values from 1== slowest --  255==instant change
  {62, 28},      //  Start Position of the servo arm traverse with  Fx=0  Max range 0-180
  {63, 140},    //  End Position  of the servo arm traverse with  Fx=1  Max range 0-180
  {64, 28},      //  Position --don't bother to set internal use only and possible future use

In the later version of the library a new parameter was added:

#define servo_slowdown  3   //servo loop counter limit

Near the beginning of the decoder sketch (look around line 22). With the servo_slowdown set to 3 the servo will move fairly slowly. Setting servo_slowdown higher will slow it down even more. You might trying setting it to 1 to speed things up. Note this is the opposite range effect of the CV rate setting (CV 61) where the lower number is slower. If you haven't read through SMA20 you really should, as it has all the updated info.

The vast majority of cheap 9G servos will not move 0 to 180 degrees (the max limits); mechanically they are just not built that well! Hence my starting suggestions of 28 and 140 which I have found to work well for most servos. It would be of general benefit for you to read through the comments in these decoder blogs regarding general operation problems and issues with these servos concerning maximum current craw (over 1 Amp) excessive nose, rattle, and stickiness at the end of arm travel attempted beyond the mechanical stops. On another posting group it was reported that some 5-10% of all received cheap 9G servos simply did not work, and another 15% did not work well. I have had pretty good luck with mine: only 2 failed in operation after installation, and none dead on arrival.

When I install any servo, I make sure that physically near the servo power feed (4.5-6V) a small pair of filter capacitors is placed across the +/- power leads (like +10uf 15V and .05-0.1uf ceramic cap) to limit the electrical noise generated by the servo motor. Some engineers will consider this overprotective design.

In you particular case check the power leads to the servo that they are at least 5 Volts or so, If you are trying to power the servo from the decoder 5V source it should work for a couple of servos, but it is possible that you will see some erratic behavior from time to time. Most of the time this works for me, but not every single time in the last 4 years!

Have fun!  smiley

Best regards,

Geoff Bunza


>> Posts index


Journals/Blogs

Recent Blog posts: