Mardec

MARDEC, the Multifunctional Arduino DCC Decoder

Mardec 5.1 is released:

  • The Arduino pin numbers 3 up to 19 are replaced by port numbers 1 up to 16. So it is now optimized for the DCCNext.
  • The input function is extended. Now you can control accessories with analog switches and DCC.

NOTE: because the storage of the configuration in EEPROM is changed Mardec must be reconfigured after updating from 4.0 to 5.1

What is Mardec

MARDEC is a program(aka a sketch) for the Arduino microcomputer. It uses the DCC-signal from the DCC-central to control all kinds of accessories on your model railway. Optionally you can also use analog switches to control accessories.

Two modes of operation

MARDEC runs in two different modes. A configure mode and a run time mode.
In configure mode you specify for each pin of the Arduino the DCC address and the required action to perform.
The Arduino is connected via USB to your computer. With only your keyboard and monitor you can easily, with a simple question and answer ‘game’,  specify all the functions that you want to perform with MARDEC. Therefore MARDEC uses one-character commands. See the manual for examples. It communicates with you by using a terminal emulator program called Putty.
No complex puzzling with CV’s!

With the E-command (Exit) you change to run time mode.
In run time mode MARDEC ‘listens’ to the DCC signals on your track.
If an address passes by that you have configured for one of the Arduino pins, MARDEC will execute the action that was configured for it in configure mode.

All MARDEC features one by one

  • Controlling up to 12 servos for turnouts without frog point polarization or up to 8 servos with frog point polarization. The frog point polarization is realized by means of an external relay. Of course you can use a servo also for other purposes like opening and closing doors or signal arms
  • The control of accessories in 10 different ways, including activating turnout coils and variable PWM control.
  • An Arduino pin can also be configured as an input. By triggering an input three other (output) pins can be activated. Two of them with a time delay.
  • Interactive, so via monitor and keyboard, configure the servos and accessories.
    That is completely independent of the used DCC Central. The Arduino software is not necessary.
  • Of each servo the start and end angle can be set accurately on the degree.
  • A random DCC address (1-2048) can be assigned to each servo and accessory.
  • Each servo (max. 8) can be coupled with a relay for frog point polarization.
    When rotating the servo, halfway through the twisting, this relay will be converted.
  • For each servo a separate rotation speed can be set. This enables servos easier for other purposes than just turnouts
  • A test option. All the servos will rotate twice. The accessories are also activated.
  • Capture of ‘ inversion ‘. With this option you can set whether a turnout is set to straight or rounded when the servo rotates to either angle. This is required because the servo can be mounted in several ways.
  • A documentation option to show all settings.
  • Assign an administrative number to each connected device
  • A reset option to clear all settings from the MARDEC memory.
  • Adjustable default speed of the servo (5-50 ms. per degree). But each servo can be set separately.
  • After a restart the servo’s and accessories are restored to the last settings
  • Return to configuration mode by connecting the USB cable, start configuration program and press ‘C’.
  • Option to correct the address offset of Roco command stations (MM, z21, Z21)
  • Accessories have the following options:
  1. Single steady. Sets an output pin permanent high or low.
  2. Double steady. Same as single steady, however a second pin has the inverted value.
  3. Single flashing. A pin switches continuously  between high and low. The high and low times can be set separately.
  4. Double flashing. Same as single double, however a second pin has the inverted value.
  5. Single one shot. An output pin is activated for a short, configurable, time on the low to high transition of the DCC signal.
  6. Double one shot. Same as Single one shot. But a second output is also activated on the high to low transition of the DCC signal. This can used for turnouts with coils
  7. Analoge (PWM=Pulse Width Modulation) An output pin is set from a configurable minimum value (1 sec.) to a configurable maximum value (1000 sec.) in a configurable time on the low to high transition of the DCC signal and from the maximum value to the minimum value on the high to low transition of the DCC signal.
  8. Flicker mode. A connected led can flicker to simulate fire or welding.
  9. Random long. A connected led goes continuously on and off. The on/off times are randomly chosen between two configurable values (1-1000 sec.)
  10. Random short.  A connected led goes continuously on and off. The on/off times are randomly chosen between two configurable values (5-5000 millisec.) .
    Same as Random long but 1000 times faster.
  • A Help option shows all the availabale commands for configuring Mardec
  • A log option saves all configure and run time actions on disk.
  • Independant of used bus structure (LocoNet, S88 etc).
    But the input for Mardec is always DCC.

Hardware requirement:

The standard DCC signal can’t be used directly to an Arduino.
A small electronic circuit is required to adapt the DCC signal for the Arduino:

DCC circuit

You can make this circuit yourself on a piece of veroboard.
But it is much more convenient to use a dedicated shield for the Arduino UNO:

This shield contains the DCC-circuit and also a 9 Volt power supply for the Arduino and an additional 5 Volt for e.g. leds, relays or servo’s. However it is strongly advised that you use an external 5 Volt power supply for multiple relays and servo’s.
The same shield is used for the Arsigdec

A print and the components (only €4,25!) can be ordered here.

DCCNext

You can also use the DCCNext. The DCCNext combines an Arduino and the DCC shield on a single pcb. A separate Arduino is no longer required.

For more info look here.

Addtional useful hardware:

When using the DCC shield you need an Arduino:  Get your Arduino’s here

If you need more power to switch an accessory (e.g. a turnout coil or led strip) you can use a MOSFET transistor. A simple and cheap solution is a complete print like this:

MOSFETprint

You can get them here
You can connect them directly to your Arduino.

Quit often you may need a relay for switching purposes. E.g. frogpoints
Here is an other simple and cheap solution:

Serv2blok

You can get them here
They are also available with 4 and 8 relays on a single print.
You can connect them directly to your Arduino.

Download manual and software.

29 thoughts on “Mardec”

  1. This is absolutely Genius, the Mardec is so easy to operate, even for electronic illiterates like me. Works like a charm. I definitely going to use the software and the shields to operate all servos on my layout.

  2. Hello,
    Looks like the perfect solution for me !!!!!
    Question : can you link more DCC/Power boards so I can operate about 60 servo’s ???

    Would be glad to hear from you.
    Rudi.

  3. Hello.

    Great job on this software.
    Is it also possible to control motors, using a dual h bridge?

    Thanks in advance
    Filipe

  4. Hi again.
    I am still a newbie on Arduino and the Mardec but I already got it working with an Uno.
    Fantastic. Thanks for the software, it is very easy to use.
    Now I also have a Nano that I would like to test.
    I added a “new Arduino” on a different Com port and it was well detected. I tried loading and configuring Mardec on the Nano but it fails. It says on avrdude that arduino is “not in sync”.
    Probably I need to select to upload to Nano instead of Uno, but how? Can you help me?
    I know that the Nano is workling properly because I can upload sketches to it using IDE.

    Thanks in advance.
    Filipe Almeida

    1. You need the Nano version of Mardec. In the installation folder. you will UploadNano.cmd. Use that to upload the nano version (Mardecn.hex)

      Nico

  5. I know this will work with servos but will it also work with Tortoise type stall motors, please?
    Cheers, ted

  6. Hi Nico,

    Thanks for making this project available. I’ve built one of the DCC shields I ordered and I was wondering if you could steer me in the right direction on an issue I’m having? I’ve set up an Arduino UNO as my base station and use JMRI as my control programme. I’ve set up some relays (to control layout lighting) and a flickering led (welding simulation) via Mardec and it works fine through JMRI. I also set up a couple of servos (address 200 and 201) that test fine using Mardec but won’t work with JMRI or the base station command window. I believe it’s an issue with addressing and nothing at all to do with Mardec. I have tried several addressing combinations including sub-addresses, but to no avail. Any idea what addresses I should use to get this working. Please excuse my ignorance as I’ve only just started looking at DCC and JMRI and again, this issue is to with my ignorance and not your project.

  7. This is really cool, also thanks for providing the code.

    Are there any plans to modify the software to use all the pins on the MEGA2560

      1. Nico, I too would like to utilize the Adriuno Mega. Would you consider such an update? In fact, at the current cost, a lot of people are migrating to the Mega as the standard. Currently, I just purchased 3 Megas for less than $3.00 more than I could have gotten the Unos. Also, possibly a video example of implementing more than one Arduino Mardec system would be of great value.

        Thanks for listening,

        Jim

  8. Man this is awesome must have for Arduino and DCC geeks
    Thanks for the efforts I was recommended by Rudi

    I am able to run my servo and a led with this using Mardec and easily able to configure the address and Pins .I am using DCC++ as my Decoder and tried to run the servos using the commands as per documentation but I see no movement
    I think my Breadboard for DDC signal with Optocoupler is working as I ran the DCC monitor and send commands from DCC++ and I was seeing the value DCC monitor.

    Can you please advise if I am doing some thing wrong

  9. Je viens de tester “MARDEC” sur un ARDUINO UNO et celà fonctionne du premier coup. Bravo, c’est super à utiliser.
    J’ai 2 questions:
    – est ce que l’utilisation de l’EEPROM n’est pas limité en nombre d’écritures?
    – pour l’installation dans un NANO, j’ai bien trouvé UploadNano.cmd, mais je ne vois pas comment l’utiliser. Si je clique dessus, rien ne se passe.

    Un petit commentaire: dans votre documentation, vous parler de “point de grenouille”, je pense que la traduction française exacte est : “pointe de coeur” pour un aiguillage.

    Cordialement

    1. I will fix the French document.
      Yes the EEPROM has a limited number of writes. But that is very big.
      But Mardec uses EEPROm.Update commands instead.

      Use the Upload tool in the Start menu. But the Nano requires first a new boorloader.
      See manual.

  10. Hello,

    I just tested “MARDEC”, and it works the first time.
    Very good job. It’s very friendly to use.

    I have two questions:
    – I suppose, you are using EEPROM to keep the position of the servo.
    Is there a maximum times of writing in EEPROM?
    – I wish to load the software in an ARDUINO NANO. I have found the “UploadNano.cmd”, but when I click on this file, nothing happens.
    What is the good handling?

    Just a little thing in the French translation: you talk about “point de grenouille”, the best traduction in French is “pointe de coeur”.

    Regards

  11. Hi Nico.

    I have build several DCC / Power boards now and all are tested via a laptop computer and I must say that they work like a charm (with the computer connected).

    But now comes the problem, when I connect the Arduino (with the DCC / Power Board) to the DCC of my train layout instead of the computer, the servo will not react.

    I have a Z21 (the black box with white router) but I do not understand how to go further so that the two systems communicate.

    Maybe a clear instruction sheet could be added to your MARDEC manual. I know it should work, but i am not such a bright light in this matter.

    Can you please help me out ( or somebody else perhaps who has already his turnouts operated by servo’s and MARDEC).

    With my best regards,

    Roel Lambrechts.

  12. This is a really great package. It took just a bit of getting in to, and Nico was extremely helpful. Mainly lack of familiarity with DCC slowed me down, once I got to grips with it, it was so easy to set up accessory ports, change parameters and add functions.

    By comparison, I have a DR4024 which was tricky to set up and did some strange things. I wish I’d found Mardec first.

  13. Hi Nico,
    I live in the middle of Germany and I must give you my congratulations for those marvellous programs.
    I use Mardec and Arsigdec and in the meantime I´ve build more than 20decoders which all work fantasticly.

    Thank you for you help.

    Best regards

    Carl Jaeger

  14. On the double shot mode can you limit the time in the high state?
    On Kato turnouts you need to apply 12v with the polarity in one direction to switch the point and to return you need the opposite polarity.

    However you must not leave the 12V on or the motor overheats.

    About 250mS is as long as the 12V needs to be active.

    I expect to use a H bridge driver to actually switch the 12v as I don’t think the DCC next will switch it.

    So one output will be connected to enable on one half of the H- bridge and the other to the enable on the other half of the H-bridge.

    I have tested this on an arduino and it works but I don’t have the DCC interface.

    1. Hi Dennis,
      Yes you can specify the length of both ‘shots’.
      Have a look at the third video on the VIDEO’S menu.
      For the DCC interface you can order a DCC shield or the DCCNext.

      Nico

Leave a Reply

Your email address will not be published. Required fields are marked *