Multifunctional ARduino dcc DECoder the Multifunctional DCC decoder for servo s and accessory s with Arduino for everybody (with a DCC central station) Author: Nico Teering September 2017 Mardec version: 3.3 Document version: 1.0 Info: MARDEC@Ziggo.nl or Arcomora.wordpress.com/Contact Arcomora.wordpress.com/Mardec/
Connecting the Arduino
Configuring Mardec If all software is installed correctly and the Arduino is connected to your PC you can now configure Mardec. To do so click on the shortcut Configure Mardec. If you do this for the very first time with your first Arduino, the USB drivers for the Arduino will be activated followed by the upload of Mardec and the start of Putty. Putty is a terminal emulator for the communication between the Arduino and your PC. (see also installation manual). Mardec uses two different modes. Configuration mode and operation mode. By default it starts up in configuration mode. But when restarted in operation mode it will start up in operation mode again. Please Note: Every numeric input must be ended with <enter>. Only one-character commands don t require an <enter> For most inputs the current value does not change with only <enter>. The current value is shown between brackets. In configuration mode the yellow led on the DCC shield (or the built-in led on pin 13) is always on. In operation mode this led is off. Turn on the Numlock key on the numeric keypad. You may use lower and upper characters for commands. Use ONLY backspace key to correct a numeric input. The first time you start configuration mode or after a full reset (with R- Command) you may enter an administrative number for your Mardec. This number identifies your Mardec in case of multiple Mardecs. Mardec also asks you then whether you have a Roco z/z21 or MultiMaus DCC central. In that case Mardec applies an address correction. At every start Mardec shows an overview of the current settings. The Commands There are four types of command: - General commands - Servo bound commands - Accessory bound commands - Input bound commands Therefore the configuration mode has four different states. By entering a? you will see a of the available commands in the current mode. At start up the General command state is automatically activated. Every command can be entered by a single character without <enter>. The most important command is P (for pin). With the P-command you can define an Arduino pin. list
General Commands P-Command (pin) After the P-command a pin number will be asked. If the pin is not in use, you must first specify its DCC address and the required function (servo, accessory or input) If the pin is already in use then its current configuration is shown and the configuration state changes to the corresponding pin type. For accessorys and inputs you can use the pin numbers 3-12 and 14-19. For servo s only the pins 3-12, 14 and 15 can be used. Arduino pins A0 to A5 corresponds to pin 14 to 19. An accessory that uses PWM (mode 7 and 8) is only available on pins 3, 5, 6 and 11. Depending on your selection Mardec will be set to the corresponding command set. T-Command (test) After configuring all the servo s and accessory s you can test all connected devices. They will function, one after the other, for a short time. The T-command is also available as servo or accessory command. It will then only test the selected pin. M-Command (move speed) With the M-command you can set the default speed for a servo. It may vary from 5 (fast) to 50 (slow) ms/degree. This speed is automatically assigned to a new servo. The M-command is also available as a servo command. With that command you can control the speed of the selected servo. D-Command (document) The D-command shows an overview of the configuration of all pins. You may want to make a screen dump of it or copy paste the text to a file. So you always know what the configuration is of Mardec. R-Command (Reset) With the R-command all settings are removed from the Arduino. E-Command (Exit) The E-command starts the run time mode. Now you can control the configured accessories with DCC signals from your command station. The statusled is now off. It will flash when a configured DCC-address passes by. Also an informative text is shown in the Putty screen. However you may also close Putty and remove the USB cable. To return to configuration mode, connect the USB cable again, starts Putty again (shortcut: Configure Mardec) and press C on the keyboard.
Input commands With a pin that is configured as an input pin you can simulate a DCC signal for a servo or accessory that has the same address as the input pin. Example: On pin 12 is a single flashing led configured with DCC address 34. On pin 5 is an input configured with also DCC address 34. By default an input pin is kept high by the Arduino. If it is made low by e.g. mechanical switch or current sensing print, Mardec interprets it as a DCC signal for address 34 and the flashing led on pin 12 stops (or starts) flashing. If there is also a servo on address 34 it starts rotating. Nothing happens when the pin is made high again. Of course you can also stop or start the flashing led by sending a real DCC address 34. The major difference is that by using an input pin nothing happens when the pin becomes high again and with a DCC signal the accessory always toggles on and off. 2- and 3-Commands (second and third address) Also a second and third address can be connected to an input pin. Therefore you can use the 2 and 3 command. By activating the input pin the accessories on these second and third address will also be activated. For the second and third address you can also specify a delay time up to 25 seconds in steps of 0.1 seconds. The accessory on the 2 nd and 3 rd address will then activated after the delay time has passed. Both delay times are relative to the moment of activating the input pin. In the figure on the right first the accessory on address 20 ( own address) will be activated, when activated by pin 5. There is no delay possible. After 5 sec. the accessory on address 25 (2 nd address) is activated and after 7 sec. the accessory address 26 (3 rd address). All addresses must, of course, be configured on the same Arduino. If you only want ' delayed ' actions you can configure a dummy address as ' own ' address of the input pin. Also you can specify the address of another input pin as a 2 nd or 3 rd address! This allows you to start a whole range of actions. Also with a DCC address. An input can also be activated with a 1 0 transition of the DCC signal. But an accessory on the same address will toggle on 1 0 AND 0 1 transition! For the example in the picture above the results are as follows: DCC address from 1 0: Accessory on address 20 is activated. After 5 sec. also the accessory on address 25 and after 7 sec. the accessory on address 26. DCC address from 0 1 Only accessory on address 20 is toggled. Input on pin 5 from 1 0: Accessory on address 20 is activated. After 5 sec. also the accessory on address 25 and after 7 sec. the accessory on address 26. Input on pin 5from 0 1: Nothing happens. For the A, N and D command see at servo- commands
Servo commands A dialog for configuring a servo looks as follows: A new servo is set to angles of 75(low) and 105(high) degrees. An existing servo is set to its already configured angles. In both cases the servo is set to the low position. - (minus) Command The - command lowers the angle with one degree. The high angle must be at least 5 degrees higher than the low angle. + (plus) Command The + commando raises the angle with one degree. The low angle must at least 5 degrees lower than the high angle 9-Command With the 9-command you can set a servo to 90 degrees. This is useful for placing the lever of the servo in the middle. Do this before mounting the servo under the track. C-Command (Change) The C-command lets you toggle between both angles. So you can set both angles individually by using the and + key. I-Command (Invert) It depends on how the servo is mounted under the track whether the turnout goes straight at the low angle or high angle of the servo. With the I-command you can invert the rotation direction of the servo. T-Command (Test) With the T-command you can test the servo. The servo will rotate 3 times back and forth. M-Command (Move speed) With the M-command you can set the individual speed of a servo between 5 (fast) and 50 (slow) ms. per degree. The default is 25 ms, which can be set with the generic M-command.
F-Command (Frog point) With the F-command Mardec will automatically assign a pin number to which you can connect a relay for frog point polarisation. For just one relay select 1. If a frog point is already assigned, Mardec asks whether you want to remove the frog point. The relay will switch when the servo is halfway its rotation. This ensures a smooth change of polarity. When rotating to the high angle the relay will be activated and be de-activated when rotating to the low angle. In case this is not correct you can set this relay to Inverted ; it will switch then reversely. For even more safety you can use 2 relays. Both relays work together as follows: Some relays are active-low (activated with 0 Volt instead of 5 V) Mardec asks you for Inversion. This ensures that the relay is only activated when the servo is rotating.
A-Command (Address) With the A-command you can set the DCC address of a pin. If the address is already assigned to another pin you get a warning. By accepting that you can control multiple accessories with a single address. By specifying address 0 you can reset a single pin. N-Command (Number) With the N-command you can assign an administrative number to a pin. It has no technical meaning. D-Command (document) The D-command shows an overview of the configuration of all pins. <enter>-command With the enter-command you end the editing of a pin configuration. The new or changed settings are now stored in memory. Accessory commands The data of the DCC signal has only two values (0/1, on/off, low/high, straight/rounded, red/green) MARDEC realizes several functions with this data. All the double functions specified below requires the use of a second pin. This is the so called buddy pin. It is automatically assigned when configuring a double function. For a new pin MARDEC asks the required function (mode); for an existing pin the current configuration is shown. The following modes are available: 1. Single Steady The Arduino pin follows the DCC signal 2. Double steady The Arduino pin follows the DCC signal and a second buddy pin gets the reversed value 3. Single Flashing The Arduino pin goes continuously low and high as long as the DCC data is high. The On/Off times can be set separately between 50 and 5000 ms. 4. Double Flashing Same as single flashing, but a buddy pin gets the reversed value. But both pins are low when the DCC data is low Also see commands L(ow) / H(igh)
5. Single One Shot With a single one shot the Arduino pin is set high for a configurable period of 50-5000ms when the DCC data goes from low to high. If the address of a single one shot is equal to that of another pin then both pins are activated; at the end of the pulse the other pin is de-activated. Sample: On address 12 you configured a one shot on pin 5 and a single flashing on pin 7. If address 12 is send to MARDEC, the one shot starts on pin 5 and a led on pin 7 starts flashing. At the end of the pulse pin 7 will stop flashing. 6. Double One Shot. Same as Single One Shot but a second buddy pin will go high on the falling edge of the DCC signal. This can be used for turnouts with coils. But take care! A turnout coil cannot be connected directly to an Arduino pin. It takes too much current and the voltage is too low. Therefore you must use a MOSFET for activating the coil. 7. Analog PWM control. A few number of pins (3, 5, 6, and 11) on an Arduino can produce a PWM signal of which the duty cycle can be varied by software between 0 and 100%. By connecting a led to such pin the amount of light can be varied. When turning on this function with a DCC signal, the PWM value on the Arduino pin will slowly raise from a minimum value to a maximum value. When turning of the function the value will fall from maximum value to the minimum value. You can adjust: - maximum PWM value (min. value to 255) - minimum PWM value (0 to max. value) - the rise time (0-500 sec) - the fall time(0-500 sec A typical application is controlling the amount of light of a LED strip. By using there PWM pins you can control a RGB ledstrip. But you need an additional MOSFET switch as an interface between the Arduino and the LED strip. Also see commands R(ise) / F(all) and L(ow) / H(igh) 8. Flickering mode With this function a connected led will flicker on and off with adjustable on and off times. Can only be realized on PWM pins 3, 5, 6 and 11 By using the proper leds in different colours on several pins you can simulate a fire or a welding light.
9. Random on/off A connected led will continuously go on and off as long as the DCC signal is high. For every on and off period a new random time is randomly generated. It varies from 2 to 500 sec. in steps of 2 sec. 10. Disco light Same as random on/off but a 1000 times faster. So the on/off times vary between 2 and 500 milliseconds. M-Command (Mode) With the M-command you can change the function of an accessory pin. The command has its own help fumction: H-Command (High) With functions 3,4,5 and 6 it sets the on -time. It can vary from 100 to 500 ms. in steps of 20 ms. With function 7 it sets the highest PWM value. With functions 9 and 10 it sets the maximum period time. L-Command (Low) With functions 3 and 4 it sets the off -time. It can vary from 100 to 500 ms. in steps of 20 ms. With function 7 it sets the lowest PWM value. With functions 9 and 10 it sets the minimum period time. R-Command (Rise) Applies only to function 7. It sets the rise time. That is the time in which the PWM value rises from the minimum value to the maximum value. F-Command (Fall) Applies only to function 7. It sets the fall time. That is the time in which the PWM value drops from the maximum value to the minimum value. Other commands T- command test an accessory N-command sets an administrative number A-Command sets the DCC address for the pin or resets the pin (value 0) D-Command shows an overview of all settings Configuraton of analog PWM control
Sample configurations Connecting a turnout with coils and two MOSFETS amplifiers
Connecting an RGB ledstrip with MOSFETS amplifiers
Connecting a servo and a double relay to a turnout