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.

About RudyB

Hobbyist

Discussion

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

  1. Hiiiii…. just wanna ask about the sound stripe. if i already a member and pay for the licensing the music, is it possible after i made my project and that project for my client, then my client will show the video for commercial ? , for example like you made a video wedding for your client and you licensing one of the music from sound stripe for fill in your video wedding, than your client use the video for commercial…..is it okay for the future? thank you. i need your opinion.

    Holly Hooper

    Like

    Posted by hollyhooper89 | December 12, 2021, 09:10
  2. Hello Rudy,
    i rewrote your sketch and replaced the DCC decoder with a CAN decoder. Can i publish the resulting code (of coursse with reference to your work)?

    Like

    Posted by Florian Gerstmeier | May 27, 2021, 21:22
  3. Hi Rudy,

    it is realy a great work your dcc++ Decoder project, I also have watched your Video´s “Fun with Arduino” hopefully there will come more.

    But now to my question:

    I want to make a pcb to controll some Servomotors, using an Arduino nano with your software. In your Video you told that it is possible to controll up to 12 Servomotors, but wich 12 Pins from the 16 possible pins of the Arduino can I use?

    I hope you will read my comment and give me an answer.

    With best regards from Germany

    Joachim

    Like

    Posted by Joachim Stahl | February 16, 2020, 12:20
    • Hi Joachim. Any pin from 3 to 19 can be used to connect a servo. Before you start to design a board I’d like to point out there already exists an Arduino Nano Extension Board that sets you back $1,- (https://a.aliexpress.com/_UeOyu). You might also want to have a look at the DCCNext board at http://www.arcomora.com, it combines an Arduino and servo- or screw connectors on one PCB for about $7,-

      Like

      Posted by RudyB | February 16, 2020, 12:33
      • Hi Rudy,
        thank you for your fast reply.
        May I get your phone nummber, because for me it is difficult to write here. I have some more questions about your Arduino Projects.
        Hopefully we can stay in contact!!!

        With best regards
        Joachim

        Like

        Posted by Joachim Stahl | February 18, 2020, 18:25
      • I’ve sent you an email, we can talk there.

        Like

        Posted by RudyB | February 20, 2020, 09:24
  4. Dear Rudyb,

    first of all congratulation for all Arduino DCC Projects! Regarding RB_DCC_Decoder_Servo, I have a problem and I Should know if you can Help me. I have a Roco Z21 white DCC station and I followed the schema for photocoupler circuit that you have posted in your article. I use an Arduino Uno original and 2 Servo, but unfortunatelly the sistem don’t work! My question are: 1) the addres of accessories are different to locomotive address? To use it , I select the button on the right of multimous but the servos don’t move they. 2) I try DCC_Monitor example and to Serial Monitor i receive some data. I don’t know if DCC signal is good or if i need to change the 1k resistor for Z21 DCC signal. Do you know these Issues? Thanks a lot, Mauro Bianchi

    Like

    Posted by Mauro Bianchi | April 29, 2019, 07:22
    • Hello Mauro. If the DCC sniffer shows DCC data, that suggests the hardware is OK. If in doubt, there is no way other than to use a microscope to check if your optocoupler circuit works fine. Lowering the 1K a bit might help, but is only necessary if you have a very low DCC voltage on the track. Best use two resistors in parallel then, otherwise it might get too hot.

      The most probable cause for the issue is that Roco decided to shift all DCC addresses by 4. if you press address 1 on the Z21, it sends out address 5 to the DCC on the track. You can change the Arduino software to compensate for this. Look for the line that says: address += (data & 0x06) >> 1; Add a new line below it that says: address = address – 4; (Or should it be + 4? I forgot, just try it out :).

      Yes, the address ranges for loco’s and accessories are unrelated. You can have a loco on address 27 and you can have an accessory on address 27. The DCC commands are different, that is how we know if a command is meant for a loco or for an accessory.

      Like

      Posted by RudyB | April 29, 2019, 08:24
      • Dear Rudyb,

        I followed your suggest and…. WORKS! Come on! Great congratulations and thanks a lot! 😉

        Like

        Posted by Mauro Bianchi | April 30, 2019, 15:22
      • Roco’s Z21 maintenance tool (1.13 or later) can be used to stop the Z21 from adding 4 to accessory addresses. The option is called “DCC turnout addressing according RCN-213”.

        Personally I’d use that option instead of modifying your code.

        Like

        Posted by Chris Ridd | June 1, 2019, 15:04
  5. Hello, I’m new to the topic. I just wanted to ask if I’m also using Lenz Hardware and TrainConroller

    Like

    Posted by Benjamin Bolte | January 20, 2019, 12:58
  6. 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
      • Hello Rudy Sorry for the delay in response
        I have tried the RB_DCC_DECODER_SERVO.ino and modified the file to meet my requirement I have connected 4 Servos only a servo connected to Address 1 works no matter what Pin address 1 is associated to
        here is my code that I modified

        #include
        #include
        #define kDCC_INTERRUPT 0

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Fill in these 2 values …
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        const byte maxservos = 4; //The number of servos you have connected to this Arduino
        const byte servotimer = 40; //Servo angle change timer. Lower value -> higher speed
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        unsigned long timetoupdatesetpoint = millis() + servotimer;

        struct DCCAccessoryAddress {
        int address; // DCC address to respond to
        byte output; // State of accessory: 1=on, 0=off (for internal use only)
        int outputPin; // Arduino output pin
        };
        DCCAccessoryAddress accessory[maxservos];

        struct servoItem {
        byte angle;
        byte setpoint;
        byte offangle;
        byte onangle;
        byte inverted;
        Servo servo;
        byte functionnumber;
        };
        servoItem servos[maxservos];

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Fill in the address and pin for every accessory / function. Servos are ‘coupled’ to accessory[n] in line 72 and further.
        // COPY – PASTE as many times as you have functions. The amount must be same as in line 22 above!
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void ConfigureDecoderFunctions()
        {
        accessory[0].address = 1; // DCC address for this accessory
        accessory[0].outputPin = 3; // Arduino pin where accessoryis connected to

        accessory[1].address = 2; // DCC address for this accessory
        accessory[1].outputPin = 4; // Arduino pin where accessory is connected to

        accessory[2].address = 3; // DCC address for this accessory
        accessory[2].outputPin = 5; // Arduino pin where accessory is connected to

        accessory[3].address = 4; // DCC address for this accessory
        accessory[3].outputPin = 6; // Arduino pin where accessory is connected to

        // Setup output pins for accessories
        for(int i=0; i<maxservos; i++)
        {
        if( accessory[i].outputPin )
        {
        pinMode (accessory[i].outputPin, OUTPUT );
        digitalWrite (accessory[i].outputPin, LOW);
        }
        }
        } // END ConfigureDecoderFunctions

        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Fill in the attributes for every servo
        // COPY – PASTE as many times as you have servo's. The amount must be same as maxservos in line 22 above!
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void ConfigureDecoderServos()
        {
        // servos[0].angle=70; //initial angle of servo. Make this the same as offangle to avoid startup jitter.
        // servos[0].offangle=70; //minimum angle. Do not use value too close to 0, servo may stutter at the extremes.
        // servos[0].onangle=110; //maximum angle. Do not use value too close to 180, servo may stutter at the extremes.
        // servos[0].servo.attach(3); //Arduino pin number where servo is connected to
        // servos[0].functionnumber=0; // CONNECTION BETWEEN FUNCTION AND SERVO ()accessory[functionnumber])

        servos[0].angle=45;
        servos[0].offangle=45;
        servos[0].onangle=135;
        servos[0].servo.attach(3);
        servos[0].functionnumber=1;

        servos[1].angle=45;
        servos[1].offangle=45;
        servos[1].onangle=135;
        servos[1].servo.attach(4);
        servos[1].functionnumber=2;

        servos[2].angle=45;
        servos[2].offangle=45;
        servos[2].onangle=135;
        servos[2].servo.attach(5);
        servos[2].functionnumber=3;

        servos[3].angle=45;
        servos[3].offangle=45;
        servos[3].onangle=135;
        servos[3].servo.attach(6);
        servos[3].functionnumber=4;

        // A servo is coupled to an accessory[n]. It rotates based on accessory[n].output = 1 or 0
        // If you have multiple servos you need to couple them to different accessories. However …
        // accessories may switch the same output pin (e.g. pin 13, which has the on board led attached)

        } // END ConfigureDecoderServos

        Like

        Posted by Farhan Haider | December 21, 2018, 03:00
      • The servos are attched to the same pins as the accessories. Use different pin numbers for the accessories, that should help. If you can’t get it to work, use the sketch DCC_servo … it is simpler since it uses only servos, no accessories … less confusion. Else, try the MARDEC software from the ARCOMORA website.

        Like

        Posted by RudyB | December 21, 2018, 08:45
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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 comment

Archive of all posts