You're reading ...
Software

New Arduino DCC Servo and Function Decoder Software

Modified Arduino DCC Servo and Function decoders are available for download via this link.

Please note: using this software is at your own risk … 100% fail safe operation is not guaranteed.

The ArduArduinoUnoSmdino DCC Servo Decoder has been ‘streamlined’. It now only contains an ‘on / off’ output function that goes along with a servo. No more flasher and no more analog output. Also the servo angle control code has been simplified. This was all done to make the code lighter and easier to oversee and to configure.

To tune the servo min and max angles, separate Arduino Servo Tune software is included in the download. Find the correct min and max servo angles to switch a junction with this tuning software, then insert those values in the decoder code. I know … I should include tuning in the decoder software … consider that w.i.p..

Then, there now is a separate multi-mode Arduino DCC Function Decoder.
It has max 16 digital outputs, max 6 of which can also be used analog (pwm).
The outputs have 3 different modes of operation:
– mode 0: continuous on / off
– mode 1: one shot with specified pulse length in ms
– mode 2: flasher with separate specified ‘on’ and ‘off’ timeArduino_DCC_Servo_Decoders in ms

Furthermore an Arduino DCC Solenoid Decoder is in development. This can switch dual coil solenoid junctions that need two separate signals. When a DCC address is switched on, a pulse of specified time in ms is given on an output pin. When the address is switched off, a second pulse is given on another output pin. This software is under test now.

The Software Page has links to 3 videos that function as the user manual.

Advertisements

Discussion

47 thoughts on “New Arduino DCC Servo and Function Decoder Software

  1. Hello Rudy Great Work
    I am using DCC++ as Controler and wanted to know how can we use this with DCC++
    Thanks

    Like

    Posted by Farhan | December 12, 2018, 05:30
    • Combined with the little opto couple circuit it works like any other DCC servo or accessory decoder, at 1/10 of the cost. Just connect the DCC track voltage (and of course Arduino power supply) and send DCC accessory switch commands to the configured addresses. If you like you could also use ARCOMORA (Google it).

      Like

      Posted by RudyB | December 12, 2018, 08:04
      • Thanks for the reply Rudy and frankly speaking you have done all the heavy lifting of the code amd make is so simple.

        I am trying to create an accessory /Servo decoder using RB_DCC_DECODER_SERVO software devbeloped by you and have followed instructions and setup 1 Servo SG9 as follows:

        Hardware setup
        On the existing and working bread board setup where DCC Accessory decoder was configured, where DCC mopnitor and Sniffer worked.
        -I connected the Red wire from Servo to the 5 Volt Power wires goes to bread board at the Optocoupler (Pin 8)
        -I connected the Orange wire from Servo to Digital Pin 3 on the Arduino
        -Connected ground from the Servo to Pin 5 of Optocoupler on the bread board.

        Applied follwing changes in the Software:

        For line number 22 no change as I have only one servo but I didnot touch the Group Accessory[0].Address=1
        For line number 49 Accessory 2 Group Accessory[1].Address=2
        For line number 49 Accessory 2 Group Accessory[1]/Output pin=3
        For line number 72 Servo 1 Group servos[1],servo(3)

        Then I uploaded software to Arduino Uno and powered up my DCC++ decoder using JMRI
        I tried the address 2 ans was expected servo to move but nothing happened
        Couple of questions:

        Can I ask you if you can review my setup and see if this is the way it is suppose to be?
        Do you have any Idea how can I register this Accessery decoder to DCC++ at address 2

        Thanks in advance

        Like

        Posted by Farhan | December 13, 2018, 02:34
      • To try things out, use just one servo, connected to pin 3. Delete or comment out all ‘configuration groups’ but Accessory[0], and somewhere at the top set ‘max accessories’ to 1. If you plan to only use servo’s on this Arduino, it’s ‘leaner’ to us the ‘servo decoder’ file that should also be included in the downloaded zip. When this does not work, post here and I’ll send you an email so you can send me your code and I’ll have a look. Alternatively you could use the free to download ARCOMORA MARDEC softwareth which is fully configurable on the PC via a user interface, without the need to tinker in the code itself.

        Like

        Posted by RudyB | December 13, 2018, 08:57
  2. Hi Rudy,

    I’am puzzling how to create a DCC three state light signal (red, green and yellow) using the arduino sketshes.
    In the instructions I do find three possibilities:
    accessory[0].mode = 3; // 1=Continuous, 2=Oneshot, 3=Flasher.

    In the video of the ‘spoorweg overgang’ I saw that the blinking lights and the servo are enabled by using only one icon on the ICOS. So multiple outputs can be configured using only one DCC-adress

    For the three state light signal, I need to use the continous mode, at least one light must stay on.
    Do I need two DCC adresses to do the job.

    Also neeed for Dutch signaling, the lights shuld have also have a bliking state

    How can I create a device that has tree states and blinking?

    Like

    Posted by joop sevenich | March 1, 2017, 15:42
    • Easiest way would be to use two DCC addresses, use one for green / red and the other for yellow or flashing yellow. If you need something else you’ll ave to do some Arduino coding. At the moment I do not have time to help.

      Like

      Posted by RudyB | March 8, 2017, 12:51
  3. You could wire the led’s, hardware wise, such that they are on when the output is low or when the output is high. Changing it from how it is with you now will inverse the bahavior. Alternatively you can modify the code to output a high or a low at the appropriate times.

    Like

    Posted by RudyB | January 5, 2016, 22:32
    • Download section does not work: https://app.box.com/s/9lz8vzxbq2db43enqiaeq5tavx0lu6yj does not give download. The ATtiny decoder software download does not work either.

      Can this be fixed please?
      Thks
      Erik

      Like

      Posted by Erik | November 27, 2016, 13:02
      • Unfortunately box.com often gives trouble with downloads. The software page (top menu) has a link to a .zip file for download that contains all the files out of all posts. That link works.

        Like

        Posted by RudyB | November 27, 2016, 19:16
    • hallo Ruud

      ik ben bezig mijn fleischman draaischijf te besturen met een arduino

      http://forum.beneluxspoor.net/index.php/topic,72796.0.html

      Nu wil ik de sketch die jij gebruikt voor de magneetartikelen gebruiken voor de aansturing
      Ik begrijp echter niet goed wat er in de main loop gebeurt

      er staat

      DCC.loop(); // Loop DCC library

      if( ++addr >= maxaccessories ) addr = 0; // Bump to next address to test

      if (accessory[addr].output == 1)

      dat begrijp ik, maar daarna volgt er een

      else
      {
      accessory[addr].highlow=0;
      accessory[addr].finished = false;
      if (!accessory[addr].highlow2 && !accessory[addr].finished2)

      etc etc statements

      Waarom worden die niet elke keer dat de main loop draait aangesproken

      Blijft de software soms hangen in DCC.loop ?
      Zit er een selectie mechanisme in wat ik over het hoofd zie

      Dick Koning

      Like

      Posted by dick koning | February 9, 2017, 14:36
      • Dick, ik moet er even induiken want het is al weer even geleden dat die code geschreven is. (geheugenverlies :)) Wat je ook zou kunnen overwegen is een goedkoop stappenmotortje (€1,70 Aliexpress met stuurprint) op de draaischijf te zetten en dan een Arduino accessory decoder te gebruiken met een adres per positie en een extra Arduino die de stappenmotor aanstuurt. Dat hebben we qua software helemaal draaiend.

        Like

        Posted by RudyB | February 9, 2017, 16:06
      • hoi Ruud

        ik heb het draaischijfgedeelte al klaar, werkt ook prima met een arduino en wat relais
        Als je het protocol voor bv de LDT decoder opzoekt gaat het om wissel adressen in een bepaalde reeks
        Wat ik niet goed begrijp in jouw software is welke parameter geactiveerd wordt als de DCC library een commando geanalyseerd wordt , wat weer een actie triggert

        Like

        Posted by dick koning | February 9, 2017, 17:13
  4. Hello Rudy,

    First of all thank you for your great sketch!

    I was looking into the sketch how the solution was built and I think I found a minor issue.
    When there is no second output pin defined (accessory[x].output2) the sketch is always writing to pin zero.
    Here below the piece of code (line 299 downwards)including my proposal for change.

    // activate outputpin, based on value of output
    if (!accessory[addr].invert)
    {
    digitalWrite(accessory[addr].outputPin, accessory[addr].output);
    digitalWrite(accessory[addr].outputPin2, accessory[addr].output2);
    // proposed change if (accessory[addr].outputPin2) digitalWrite(accessory[addr].outputPin2, accessory[addr].output2);
    }
    else
    {
    digitalWrite(accessory[addr].outputPin, !accessory[addr].output);
    digitalWrite(accessory[addr].outputPin2, !accessory[addr].output2);
    // proposed change if (accessory[addr].outputPin2) digitalWrite(accessory[addr].outputPin2, !accessory[addr].output2);
    }

    Thanks,
    Ronald

    Like

    Posted by Ronald | December 14, 2015, 16:34
  5. Hello Rudy,
    I have found your software (servo decoder) some time ago. I like it very much. I have downloaded it, and modified it to my needs. I also built the hardware to receive the DCC packets. Everyting works perfect, good job.
    The thing that puzzels me is the issue about the servo jitter at startup. I am reluctant to pull all servo’s LOW with a push button or someting like that. This sets the points in a different position as present in the PC software in my case iTrain. Furtermore I am planning to incorporate frog-polarization in the software. The reason for this is that the hardware frog-polarisation seems to be not relaiable over time (I am using PECO finescale code 55, N-gauge). So now I am building, it is best to make polarisation anyway, to be sure. I use relays to do this, and I want to change the software to do this. But when the servo’s are set to LOW with hardware, that can cause the polarisation to get wrong, causing shortout. So for now I set every point to turn by hand in iTrain. But in the end I will have around 100 points, so that is no option. I am looking for a other way to take care of this problem.
    A problem wigth the polarisation with relays is that the relay must not switch when the point-blade still makes contact to the rails. So I will arrange that the offangle and the onangle are symmetrical aroung 90 degr, which is the middle posision for the point-blade. This means accurate installation of the point, but it is no big deal.
    The sofware knows when the blades are in middle position, and then the relay must switch.I trying to get it all working now, and if it succeeded I will make the software available. But first I want to test if I get everything reliable very extensively. The risk of short circuits is always present.
    I wonder if you have ideas for me on how to tackle the jitter problem in combination with iTrain and possibly the frog-polarization approach. Thanks again for your good work.
    Chris de Groot

    Like

    Posted by Chris de Groot | November 20, 2015, 01:08
    • Chris, the servo startup issue is indeed annoying. In the mean time I make a distinction between a short ‘jitter’ at power up (even if the servo is already in the start angle) and a ‘jerk move’ to the start angle when it was not at that angle after the last power down.

      The hardware ‘solution’ is one that was in the earliest versions of the software. I never used it cause I already thought it not a very nice solution. I do what you do in the mean time … before power down put all junctions in the position that the software starts up with. In Traincontroller that can be done with the press of one button, I think in iTrain too. I also have a 1 s delay between them, to avoid they all start moving at the same time drawing too much current, important when you have 100!). That takes care of the ‘jerk move’. The jitter, I found out, depends on the type of servo. I have a few that have the jitter and a few that don’t. There seem to be ‘digital servo’s’ on the market, and they show less or no jitter at all. I never tried myself though.

      With regard to the frog polarization. The software already has an extra output available per servo to control a relais. I’m not sure why you would want it to switch exactly halway the move? Normally the frog is completely isolated, it does not mater when it is switched. Although … that is the case with Peco HO. With N track switches the isolation wires are not available, but it is possible to cut the track with a Dremel such that you get isolated frogs, which then can be polarity switched freely. Of course, if you can get relais switching exactly in the middle done (need to remove the spring) that is fine too. These are two different solutions.

      Like

      Posted by RudyB | November 20, 2015, 09:03
      • Hello Rudy,
        Thanks for responding.
        I did not think yet of cutting the frog wires, then there is no problem obviously. On the other hand, its seems to work all right, when things are installed neatly, even when springs are installed. Reason to take springs out id mainly to let the points move more realistic, without the click of the spring. On the other hand, then the servo hase to pulle the blade tight to the rails, and then there is more jitter to be expected. I have not decided yet.
        I use arduino nano. €1,3 each at aliexpress. I moved the function of pin 13 to pin 22, so i don’t lose that pin. Then i have 10 pins for servo’s and 10 pins for relays (digital and analog together). I set the servo’s on the uneven pins and the corresopnding relays for each succeeding pin. That makes programming easyer. But i am still testing. Specially dubble crossings are a bit more tricky, and it is not always possible to install the servo’s in the same position. That also complicates secure frog polarisation.
        I have not yet discovered the possibility in iTrain to put all points in position thrown yet. I will ask that on the iTrain forum. That would help very much. And indded i saw you deleted the hardware solution in your last software.
        I will keep you informed of my progress, and keep up the good work, i like your posts very much.
        Greetings, chris de Groot

        Like

        Posted by Chris de Groot | November 21, 2015, 00:32
      • In iTrain it is possible to create a route. Add all the switch positions you need to that route and you have it covered. Here’s a video on the subject:
        https://rudysmodelrailway.wordpress.com/2015/05/10/itrain-switch-panel-with-routes/

        Like

        Posted by RudyB | November 21, 2015, 09:26
      • Hello Rudy,
        Thanks for your hint and your good video. Of course this is the way to do it. I had not yet played around with track routes yet, because you really don’t need them when you are running trains automated. In future I want to run automated and manually together, so I will look into track routes more in detail then.
        Chris de Groot

        Like

        Posted by Chris de Groot | November 21, 2015, 16:00
  6. I want to make this dcc servo decoder but wich electronic components i need? i have seen the schematic but there are 100000 different components and wich one is the good one?

    Were can i get the right components?

    Like

    Posted by Bramnspoor | October 28, 2015, 13:49
    • If you have seen the schematics from the Software page (via top menu) then I do not understand the question … the components are mentioned on the drawing.

      Like

      Posted by RudyB | October 28, 2015, 19:53
      • Oh sorry, i didnt see that i have ordered the optocoupler. I hope to make a digital dcc servo controller. I want to make a servo in a lok depot for open en closing the doors.

        Like

        Posted by bramnspoor | October 29, 2015, 11:19
  7. Hi Rudy,

    I almost sure, that my issue is my fault. I have Rocrail and CS z21. Seems, everything is OK. The signal at outlet of optocoupler looks good, checked by scope. Unfortunately, Servo doesn’t respond at all. At the Interface of the turnouts, adders is according the sketch, the port is 0. Can you give me some direction how I can proceed fro here.
    Thank you in advance!

    Like

    Posted by Evgeny | October 8, 2015, 21:14
    • I’m afraid I don’t understand what is meant by ‘At the Interface of the turnouts, adders is according the sketch, the port is 0.’

      If you’d first try the DCC function decoder sketch (Don’t know when you downloaded, today new files were uploaded, best to go to the Software page and download the latest files) and you’d configure a function in that sketch that outputs at pin 13, which is the on board LED, can you switch that LED on and off using the z21 interface? That is the best test to see if all hardware in between works. If that works, I bet we’ll get the servo’s working too!

      Like

      Posted by RudyB | October 8, 2015, 21:56
      • Thank you so much for your reply.
        Yes you are correct, this is my first try. The sketch has been downloaded out of “software” of this page. Regarding the “At the Interface of the turnouts, adders is according the sketch, the port is 0” I just meant the parameters in Rocrail, under Tables –> Switches –>> Interface.
        The sketch has been uploaded without any modifications, no warning and errors. I tried it, using android z21 interface as well. The LED is not switching.

        Like

        Posted by Evgeny | October 9, 2015, 06:08
      • The DCC Function Decoder file needs to be configured first.
        For the most basic function, to turn the on board LED on/off, enter this:

        Line 22:
        const byte maxaccessories = 1;

        Line 48:
        accessory[0].address = 1; // DCC address
        accessory[0].mode = 1; // Continuous: HIGH until DCC switches the address off again
        accessory[0].outputPin = 13; // Arduino pin to which this function is connected. 13 is on board LED

        Comment or delete the other two arrays. Now if you send out address 1 via Rocrail and /or z21 the LED should switch on/off. If it doesn’t there is an issue in the Rocrail/z21/track/opto coupler/Arduino chain. Sometimes with Roco, there is a shift of 4 in the addresses. Then try to use address 5 and send out address 1 or 5 or 9 (I forgot to which side the shift of 4 is).

        Like

        Posted by RudyB | October 9, 2015, 10:13
      • Thank you, Rudy,

        My apologies for misunderstanding in advance, if so. Seems, I don’t understand what you mean “send out address 1 via…”. Which parameters should be sent? I tried the sketch from http://model-railroad-hobbyist.com/node/19446. Everything is working, this is activating servo if some function F0, F1 and etc under Loco menu is used., means the hardware is not my problem. Unfortunately, it can not be used for me, since Switch menu Interface Tab doesn’t has the FUNCTIONs option. May be I have to clarify, what I need to activate. I have to activate the servo via switch tables in Rocrail.

        Like

        Posted by Evgeny | October 10, 2015, 07:38
      • Steps to test if the ‘chain’ works:
        1: In the Arduino sketch, configure a function for DCC address 1, that outputs at Arduino pin 13 (see previous message)
        2: In the Z21, configure a turnout to switch at address 1 (forget Rocrail for now)
        3: Operate the turnout on the z21, the LED on the Arduino should now switch on/off.
        Can you get this working?

        Like

        Posted by RudyB | October 10, 2015, 19:35
      • Hi Rudy,
        Thank you very much for your reply!

        I tested, according your recommendations, the LED is not responding,
        By the way, I tried two the same sketches from the mentioned site, one with lib “NmraDcc” and second one with lib “NmraDcc1”. It’s working with the lib called “NmraDcc1” only, (under locomotive menu F0,F1 and etc)

        Like

        Posted by Evgeny | October 11, 2015, 08:22
      • Thank you, Rudy!!!

        Alleluia!! That’s working, the sketch RB_DCC_Decoder_Servo. You are right, there is a shift up of 4. It was tested with Rocrail as well.
        Thanks a lot for your efforts and support!!!

        Like

        Posted by Evgeny | October 11, 2015, 17:32
      • Hi Rudy

        I would like to use the flasher of the accessory decoder for Cross Level Signals. Unfortunately, the LEDs are ON when the barrier is open and are flashing if the barrier is closed. How I can to change the condition of the LEDs (OFF) when the barrier is open?
        Thank you in advance!

        Like

        Posted by Evgeny | January 5, 2016, 20:20
      • For the Z21 there is a fix for Firmware greater than 1.21, it can adjust the +4 DCC adress setting 🙂

        Like

        Posted by Alco Post. | May 28, 2016, 21:06
  8. Hello, i want to try this but i have 0 electronics knowledge (maybe almost 0).

    I know that i need the arduino, fast optocouplers and some resistors, however i have no ideea how to connect them.

    Do you have a drawing of the pcb board connections please?

    Thank you,
    Lucian

    Like

    Posted by Lucian | September 17, 2015, 14:42
  9. Hi Rudy,

    Thanks for all your efforts in making DCC posible without paying a million euros for electronics 🙂

    I have made the Mynabay setup with your code running – it all works fine with the Roco 10764 booster and Multimaus.

    I just found out, that the R1 1K ohm is getting really hot. My resistor is a 0,25 w.

    What can be the problem or is it ok?

    Keep up the good work!!!!

    Thanks,
    Michael

    Like

    Posted by Michael | September 8, 2015, 18:59
    • Yes, a 1/4W can be close to the limit, specially if your track voltage is somewhat in the higher regions above 15 V. You may try to increase the R to say 1.5k and see if it gets less hot. Probably the circuit will still work ok. Too large an R will limit the current through the opto too much making it somewhat slower.

      Like

      Posted by RudyB | September 8, 2015, 19:28
  10. Hi Rudy,

    I used your latest decoder version on my Arduino board together with the adServo board of Timo Engelgeer.
    You can find the results over here: http://forum.beneluxspoor.net/index.php/topic,63567.msg3221552394.html#msg3221552394

    Like

    Posted by Nico Teering | March 8, 2015, 23:25
    • Nico, that looks good! I understand that right now Timo’s board is only in use for the opto-coupler circuit? Like you mentioned, I plan to solder those 3 components (opto, R, led) on a 20 mm small board. Then, if I can find the time, maybe add the tune software, and the use of EPROM to store the angle values, in the DCC servo sletch.

      Like

      Posted by rudyb2014 | March 9, 2015, 08:36
      • Rudy,

        Indeed, I use Timo’s board only for the opto-coupler circuit.
        But when my Pro mini arrives and the extra ordered servo’s I will test it with the pro mini mounted on the adservo and load it with your software. I assume it wil run also on the Pro mini.

        Like

        Posted by Nico Teering | March 9, 2015, 10:38
  11. Hi is anyone else having problems with the DCC Decoder, I have reinstalled Arduino ide 3 times, all of the examples that come with it compile ok, but I can not get the DCC_Decoder to work, I get a ‘Type Error’ I have tried placing the DCC folder into the libraries folder, I have tried in both the Sketch folder Library and the Arduino Library folder and I have also tried importing it, but I still get the same error, Arduino: 1.6.0 (Windows XP), Board: “Arduino Uno”

    In file included from DCC_Monitor.pde:1:0:
    C:\Users\Adam.Whitehouse\Documents\Arduino\libraries\DCC_Decoder/DCC_Decoder.h:131:11: error: ‘prog_char’ does not name a type
    const prog_char* ResultString(byte resultCode);
    ^
    Error compiling.

    My library structure seems ok, is there anything else that I can try to resolve this, please?

    Like

    Posted by Adam Whitehouse | February 27, 2015, 12:05
    • Hi Adam. It’s always frustrating if things won’t work. The errror seems to point to some problem with the library. Maybe if you download and ‘install’ the mynabay library as described on their website and then give their DCC-monitor a try. Does that work for you? If it does, then upload the DCC decoder sketch into your Arduino … with the library in place it should not complain with errors. If it does not … then I would not know what could be the issue here.

      Like

      Posted by rudyb2014 | February 27, 2015, 13:54
      • Hi Again RudyB, think I have found the problem, prog_char is no longer supported and has been depracated, had to redefine char* and change all of instances of prog_char to just char in the header files and cpp file, this seems to work now, at least it compiles with no errors but I will know more when my board’s arrive.

        Regards
        Adam

        Like

        Posted by Adam Whitehouse | February 27, 2015, 15:00
      • Hi Adam. Sounds good that you managed to find the probale cause of the issue and have a clean compile now! I was not aware of this deprication. With me it still works ok, but I bet I better check this and modify the software here too!?

        Like

        Posted by rudyb2014 | February 27, 2015, 17:34
      • Hi Rudy, As I mentioned the type prog _char has been deprecated in at least the latest version of Arduino ide and needs replacing with char PROGMEM, the results of this function (3 of them in .cpp)also require a second constant, I have made these changes to mynabay source files and have attached them for use.

        Regards

        Adam

        Like

        Posted by ADAM WHITEHOUSE | March 2, 2015, 10:01
      • Thanks Adam for your post and for the work you put into bringing the dcc library up to date. I could not find the attachment though, sent you a mail.

        Like

        Posted by rudyb2014 | March 2, 2015, 10:43
      • Hi Rudy,
        I encountered the same problem in DCC_Decoder.h with the new IDE 1.6.1. No problem with version 1.6.0.
        Unfortunately Adam did not publish here the required changes he made in the library.
        Did you get the changes by email from Adam?
        If so please fix the library and publish it again.

        Thanks,
        Nico

        Like

        Posted by Nico Teering | March 28, 2015, 11:46
      • Nico, I sent you an email with the software. I’ll publish here as soon as I found the time to test the updated library software I received from both Adam and from someone else.

        Like

        Posted by rudyb2014 | March 28, 2015, 14:40

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: