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

Servos now working

Hello Geoff,

thank you for the thorough explanation of the servo functionality.

About your initial assumptions, they are both correct (Mobile/function decoder + cheap noname servos). I discovered that the two servos were kind of stuck in one of the end positions. I realized that plugging and unplugging them several times, they both started to crawl towards a more ideal position of the gears, so that when i reset and powered again the decoder they finally started moving between the programmed range.

Since you mentioned the fact that I was using the decoder as a mobile function decoder instead of an accessory decoder, I would like to understand which is the difference between the two versions. Is the accessory version allowing to use it as an NCE accessory (by setting the address n. and then by pressing 1(ON) or 2(OFF) on the PoweCab enabling and disabling the corresponding actuator?) I'm a little confused...

About servo powering, I'm using a switching power source of 5V (actually measured 5.3V) 1Amp to power the decoder. I don't think I will require to move many servos simultaneously, since I still want to operate them manually, although electrically assisted, via JMRI.

Finally, I would like to understand if and how I can use this multifunction decoder to control lights (mainly buildings, roads, etc.) and servos for turnout throwing ( which are presently mechanically operated by hand with rods in my switching layout) by means of JMR, by building control panels. Presently I can only operate locomotives through the JMRI WiThrottle, web interface, or with an Android mobile phone using Engine Driver and Digitrains. Even the multifunction decoder is seen by the system as a  locomotive in the roster.

I've tried to create turnout or light tables, but they seem to be disabled since they don't appear when I call the corresponding windows in the JMRI menu. I'm afraid that the NCE USB interface I'm using is not compatible with these functions...

Still have a lot to learn, but I'm presently enjoying the journey, and it's good to have some experienced tutors like you to clarify the doubts and show the way.

Best Regards

 

Roberto

geoffb's picture

@Roberto re: Questions and Comments

Hi Roberto,

I am glad to hear you made progress with your servos.

About your initial assumptions, they are both correct (Mobile/function decoder + cheap noname servos). I discovered that the two servos were kind of stuck in one of the end positions. I realized that plugging and unplugging them several times, they both started to crawl towards a more ideal position of the gears, so that when i reset and powered again the decoder they finally started moving between the programmed range.

It sounds like your servos were driven hard to the end of their traverse. The binding/friction on the gears and arm would make it more difficult to reverse the servo out of its position past what would be considered the maximum limit of its travel. When this happens, you may also get the servo drawing larger than normal current (I have measured this to be more than 1 Amp on some servos). This should be avoided for normal operation.

Since you mentioned the fact that I was using the decoder as a mobile function decoder instead of an accessory decoder, I would like to understand which is the difference between the two versions. Is the accessory version allowing to use it as an NCE accessory (by setting the address n. and then by pressing 1(ON) or 2(OFF) on the PoweCab enabling and disabling the corresponding actuator?) I'm a little confused...

You actually do understand the basics of this. Accessory decoders respond to different DCC commands than mobile/function decoders. I do not use the NCE system, so read up in your NCE user documentation about using accessory decoders with NCE. Accessory decoders are often associated with setting/using track switches, and the nomenclature of Thrown and Closed is often used instead of On and Off (or Off and On -- I never keep these straight!). The addressing for accessory decoders is different too and often accessory decoders are simpler and lack CV settings (unlike the way I set these accessory decoders up-- read SMA20 for more detail).

Finally, I would like to understand if and how I can use this multifunction decoder to control lights (mainly buildings, roads, etc.) and servos for turnout throwing ( which are presently mechanically operated by hand with rods in my switching layout)

You can use these decoders to turn on and off LEDs for lighting easily, by using a limiting resistor in series with a LED connected to any function pin. There are many ways to control these with different features and groupings. Again read SMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Ftns/Pin & New Features  http://model-railroad-hobbyist.com/node/24316

for details. For more applications I'll refer you to my blog: http://model-railroad-hobbyist.com/blog/geoff-bunza

for more elaborate use. Also there are many great modelers in the MRH forum that are doing great things with LED lighting and Arduinos and other controllers, like Dave Bodnar for one. Use the Search box on the top left of each MRH page for help.

by means of JMR, by building control panels. Presently I can only operate locomotives through the JMRI WiThrottle, web interface, or with an Android mobile phone using Engine Driver and Digitrains. Even the multifunction decoder is seen by the system as a  locomotive in the roster.

Don't be bothered by JMRI's equating mobile decoders to locos, nor by the relatively primitive JMRI interface for accessory decoder control. There is a wealth of other JMRI resources that can be applied, although there is a steep learning curve. Have a look at JMRI scripts to control lighting via decoders, for a start.

Last, I should have a new blog or blogs coming out soon regarding DCC control that may be of interest to you too. Stay tuned! Have fun!  smiley

Best regards,

Geoff Bunza

Accessory Decoder version

Hello Geoff,

still messing around with the decoders. I recently joined the JMRI group on Yahoo, and I was suggested to try out the Accessory version of your decoder.

Since I built two decoders, I would like to reserve one for lighting, and the other for servos.

I loaded the code AccDec_15Servos_@LED_6Ftn into the Arduino and tested it. It went all right, so now I can control the servos turnouts via the ACCY button on Powercab.

I was also able to control the servos via JMRI, by setting up a small test panel. Wohooooooo... it seems I'm on the right way!!!!!!

But.....all went well till I tried to modify the program. I changed the decoder address from 40 to 20, and the CV decoder address from 24 to 19, and then modified the CV parameters of the last two functions from the CV table so that the decoder can control 17 servos. As soon as I modify any of these parameters, no matter if one, two, or all, the decoder doesn't respond anymore to controls.

I've tried re-uploading several times, with no success. Only a clean version of AccDec_15Servos_@LED_6Ftn seems to work. It sounds strange to me, because I'm not messing with the code, only some declared parameter which are clearly identified in the code itself.

Am I doing something wrong? Can I change the addresses only by changing the values of

#define SET_CV_Address       24

#define Accessory_Address    40

to whatever value I want (I would like 19 and 20, respectively)?

Can I change the values of CV associated with the two last functions to change from LED to Servo?

I'm pretty baffled by this behaviour, but I suspect that the last two pins, which are connected to A4 and A5 of the Arduino board are kind of special and don't behave like the othersso that servos may not work on these two specific channels.

On the other hand, I was able to  successfully change the decoder address to 20 via Powercab by setting CV1=20 when programming the decoder as a loco on address 24.

Could you please help me to set up a version fully Servo and a version fully LED for the Accessory decoder? What am I supposed to change to have them work the way I want?

Best Regards

Roberto

geoffb's picture

@Roberto re: CV Changes

Hi Roberto,

As soon as I modify any of these parameters, no matter if one, two, or all, the decoder doesn't respond anymore to controls.

Since you are trying to modify the CV's, did you remember to follow the directions as posted:

Open one of the sketches (programs), set your decoder address, and you are good to go!  Once you have loaded the Pro Mini, remove the “//” in  the line: “//#define DECODER_LOADED” so it looks like below:

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

And then RELOAD the Pro Mini. This will set up all the default CV’s and then permit you to modify them with your DCC controller of choice. You can even reset the short address in CV 1.

Not following these directions your decoder will reload the original settings every time you power up your decoder.

Can I change the addresses only by changing the values of

#define SET_CV_Address       24

#define Accessory_Address    40

Yes, you can, and these are the correct statements to change. Editing the sketch is the easiest way to set the decoder up.

Have fun!  smiley
Best regards,
Geoff Bunza

CV Changes

Hi Geoff.

I followed the mentioned procedure religiously:

1) Choose a sketch (in my case the Accessory 15Servo 2 LEDS)

2) Upload to Arduino

3) Remove the comment // in front of #define DECODER_LOADED

4)Upload again

To be sure that I was doing things right, I even uploaded the blink sketch to Arduino to be sure I was dealing with a clean install, and then repeated the above procedure.

If i leave everything as is in the examples directory you supplied, everything runs fine, but as I mentioned, if I change the CV address and decoder address, the hardware doesn't respond anymore to commands.

It seems a pretty foolproof procedure, but still, I can't make it work the way I want.

I'll try again doing things slowly, one by one, and look for what I'm doing wrong.

Regards

Roberto

 

===UPDATE===

I repeated the procedure by changing firts only the two addresses (CV and decoder) and it worked. Then I proceeded to change the CV values relative to functions F15 and F16 and it finally works. I don't know what I was doing wrong, since I used the same process. The important thing is that now finally works as I wished.

Thank you once again for you wonderful work.

Roberto

geoffb's picture

@Roberto re: CV Changes

Hi Roberto,

What addresses are you changing them to? The mobile address must be a short address.

Did you change them via editing the sketch or with your DCC throttle/base station?

What exactly is the DCC setup you are using?

Do you understand that accessory decoders are accessed by track switch and DCC accessory commands from your throttle/base station? I have not had any trouble reports like this before. Please try to add more specific details about what you are using, what you did, and what the responses were. I have to guess at everything you leave out.

Best regards,

Geoff Bunza

again on cv changes

Hi Geoff,

I understand that accessories decoders behave different wrt mobile decoders.

As I said in the update in my previous post, the Servo decoder is now fully functional with 17 Servo channels and the decoder was setup as address #19 (two digits) for CV change on the Powercab throttle (or JMRI, which is much faster to reprogram the decoder's CVs) and decoder address #20.

Now, if I select for example accessory #21 from the Powercab throttle, I can move the servo from thrown to close and vice versa.

So this issue was completely addressed and this decoder is working correctly.

When I reprogrammed the Arduino, I changed the addresses from sketch (CV for channels 15 and 16 as well) and it works. Now I can change the decoder starting address by setting the CV1 also via Powercab throttle by selecting loco#19.

Just to answer your questions about the setup, here it is:

DCC Station: NCE Powercab v1.65

PC Interface: NCE USB

Software: JMRI v.4.5.2 with Java 1.8.0_101

Accessory decoder: Geoff Bunza "fantastic decoder" SMA12 laugh

 

Right now I'm testing the 17LED lights version of the accessory decoder, and I get a strange behaviour on function F1 and F2. I programmed the decoder to work as a simple switch on/off by setting all the CV 30, 35, 40...105 to value=0. But when I switch on F1, the corresponding LED lights on dimmed by half and it also lights the LED corresponding to F2. If I activate F2, then the two LED go full power as the other channels.I changed manually all the CV of these two functions to work as switch on/off,  but they still light as one. I tried also to set as blink CV35=1, and still F1 and F2 blink together as one. I tried to program also the double blink function CV35=3 CV36=1 CV37=1 CV38=35 CV39=2, and instead of alternating, the two leds blink simultaneously.

This strange behaviour only happens on this specific couple of pins, as I tried on F3 and F4 and the leds work as expected by the programmed function (on/off, blink, double blink).

I checked the perfboard to see if there was a soldering problem like a short, and also checked pins 4 and 5 of Arduino Pro Mini board, but the two channels seem to be perfectly isolated. Is it possible that I have a malfunctioning Arduino?

Any hint?

UPDATE: I've found the problem. There was a microscopic tin spike that I discovered with the the multimeter acoustic buzzer continuity test. It was so small that I had to use a  strong loupe to detect it. It was sufficient to cause a short circuit between the two channels. Removed with an X-acto knife and now everything is working...wooohooooooooo!!!!!!!

Thank you

Roberto

geoffb's picture

@Roberto re: Success !!

Hi Roberto,

That is great! yes

I've had that happen to me too -- a small splash of solder or a small piece of wire gets lodged in the wrong place and it can be frustrating to find... but the joy of success puts that frustration behind you. Good job,

Have fun!  smiley

Best regards,

Geoff

@Geoff: Great!!!

Hi Geoff,

thank you!

Without all your great job and support it would not be even remotely possible for me to succeed. Although it can be frustrating sometimes when you deal with something you don't fully understand, when things finally work it's very rewarding. Now I can look at the decoders and say:"Hey, I DID IT!"

Looking forward for other great ideas from you, and having big fun with the decoders I have now thanks to your efforts and generosity.

Best Regards

Roberto

Problems with servo again

Hello Geoff,

I'm here again th ask you some help with the servo decoder.

Everything was working and I spent the last week experimenting with JMRI, panels, etc. I helped the developers to discover a bug in one of the java libraries that was causing JMRI to freeze on my machine, and found a workaround to it.

Yesterday I spent the whole day setting up a demo turnout with motion and signaling. If you are interested, you can see it here.

Everything was working perfectly. Today I came to the layout to experiment more, but i found that the angle limit that I carefully set yesterday, were all off. I started tweaking with Decoderpro to set again  the corrects limits, but it seems that the decoder doesn't retain the changes after a reset, or a power off.

I decided to proceed to reprogram the Arduino Pro and used the modified version of the 15servos_2LEDS to set programming address#19 and accessory address#20, as it was till yesterday (I have another lighs only decoder wich I set to adresses #39 for programmin and #40 for functions). As happened last week, when I already called out for your help, it seems that when I change a single character of the sketch, it doesn't work, making the decoder unresponsive to DCC commands. I wonder If i'm doing things right, and I'm thinking that the successful upload of last week  was a random success. This process seems really a "hit and miss", and I don't think I got the hang of it, yet.

The intriguing thing is that if i take your version and upload without changing  anyting, it works. As soon as i put a finger in the sketch, it doesn't. My problem is that I would like to set different addresses to the decoders (as I plan to use alt least 4 in my layout) directly during programming with the corrects addresses and CVs.

Here is what I do in detail.

1) open the sketch 15Servos_2LEDs in Arduino IDE

2) upload to Arduino Mini Pro

3) Upload again toggling the // in front of the define command, as per instructions, to make the decoder retain successive CV changes

4) Connect to DCC bus, and via Powercab, operate the accessory #40 (first of the list), which works OK.

5)Reintroduce the // in the sketch, change programming address to 19 and accessory address to 20

6)upload to Arduino Pro

7) repeat step 3

8) repeat step 4, and via Powercab, operate, this time, accessory #20 (first channel of MY new list)

The communication fail and decoder doesn't seem to work.

I would like to know if there's something I'm not doing correctly. After a lot of trials, I've some doubts

about the uploading procedure in Arduino IDE

a)If I customize the sketch and change its name, it forces me to create a new directory. Is Arduino loosing some connection between the sketch and the NmraDcc.h and SoftwareServo.h? Do I have to teach him find the new path to the libraries? I've seen that there is a specific command to include the libraries. Is it sufficient to simply reposition the sketc or do I have to manually make the links again?

b) The programming of Pro Mini is a little tweaky. If I simply send the sketch to the Arduino, it stays forever transmitting until a timeout happens. I've learned that depending on the used USB-TTL interface (mine is a 4 pins PL2303), it's required to push the Arduino reset button in a specific moment just before the uploading takes place. I wonder if the exact moment in which i press reset is so critical to invalid the upload, although no errors appear and it says transfer complete at the end.

c)Between  the first upload and the second upload with removed //, is it good to reset the Arduino and the USB -TTL interface by unplugging and replugging? I've experience a few times (2 or 3) some random transmission errors in the second attempt if I do the uploads one immediately after the other.

d) Is it possible to read the CV values? I've trried both via Powercab and JMRI and reading from the decoder fails. With my locomotives is possible to read CVs. Am I doing something wrong or the decoder cannot give a feedback because of its programming?

.I'm really feeling unsure, as this upload procedure seems  very precarious...

Do you have any advice for me?

Best Regards

 

Roberto


>> Posts index


Journals/Blogs

Recent Blog posts: