Procedure using software

Beside of DCC/MM2 shield and DSmain

DCC/MM2 shield distributing in this site is writtein the latest firmware. You don't need update and write to DCC/MM2 shield.


DCC/MM2 shield has a micro controller written in firmware writer. Firmware is distributed in this site for non-commercial use. Arduino's micro controller can update using Arduino IDE and via USB.

Beside of Arduino

We provide you the library DSGatewayLib which can control DCC/MM2 shield via Arduino. You need Arduino IDE. Arduino IDE can develop Arduino software using many libraries and upload to Arduino board.

Required external softwares:

  • Arduino IDE 1.0.x or later
  • DSGatewayLib
  • Desktop Station (if needed)
  • Connect Arduino to your PC. Install Arduino's driver software. See Install the drivers.
    Arduno IDE includes Arduino's driver software.


    Download and unzip DSGatewayLib. Copy unziped DSGatewayLib to Arduino IDE's Libraries folder.


    Connect your Arduino board to your PC. Select the type of Arduino board. In this case, Arduino UNO is selected.

    Check serial port number. Also change the configuration of serial port. If you connect only 1 serial devices, Arduino IDE selects automatically this port.



    In this situation, you can make your software freely. If you want to run example, select example menu. You can select DSGatewayLib's examples.


    If you want to connect Arduino board and DCC/MM2 Shield to Desktop Station(PC), Open DSGateway in the example menu.

    Click upload. Your software will upload to your Arduino board.

    How to use DSGatewayLib

    If you use Desktop Station, open the example and select DSGateway. After wrote, see Desktop Station page.
    How to write DSGatewayLib declaration:
    Add includes "DSGatewayLib.h" and "SPI.h". Also add like "DSGatewayLib Gateway;" at the global variable declaration area. After that, write "Gateway.begin();" in the setup() function.

    Determining of locomotive address:
    In case of MM2 locomotive, use word type, the address offset uses as ADDR_MM2. Then you can use as "ADDR_MM2 + locomotive address".
    In case of DCC locomotive, use word type, the address offset uses as ADDR_DCC. Then you can use as "ADDR_DCC + locomotive address".

    Determining of accessories address:
    In case of MM2 accessories, use word type, the address offset uses as ADDR_ACC_MM2. Then you can use as "ADDR_ACC_MM2 + accessory address".
    In case of DCC accessories, use word type, the address offset uses as ADDR_ACC_DCC. Then you can use as "ADDR_ACC_DCC + accessory address".

    Example 1:
    word aLocAddr = ADDR_DCC + 34; /* Set DCC address 34 */
    Gateway.SetLocoSpeed(aLocAddr, 128); /* DCC address 34 locomotive run speed 128/1024. */

    Example 2:
    word aAccAddr = ADDR_ACC_MM2 + 4; /* Set MM2 accessory turnout 4. */
    Gateway.SetTurnout(aAccAddr, true); /* Go straight. */

    Provided functions

    Function name
    SetPower(boolean power)
    Parameter Meaning
    boolean power true : Power on the rail.
    false : Power off the rail

    Function name
    SetLocoSpeed(word address, int inSpeed)
    Parameter Meaning
    word address locomotive address
    MM2: ADDR_MM2+1~255
    DCC: ADDR_DCC+1~127
    int inSpeed locomotive speed (0 to 1023)
    0: stop,
    1023: maximum speed
    Description
    This function supports locomotive's speed control.

    Function name
    SetLocoSpeedEx(word address, int inSpeed, int inProtcol)
    Parameter Meaning
    word address locomotive address
    MM2: ADDR_MM2+1~255
    DCC: ADDR_DCC+1~127
    int inSpeed locomotive speed (0 to 1023)
    0: stop,
    1023: maximum speed
    int inProtcol speed step protocol (0 to 2)
    0: DCC28/MM2 14,
    1: DCC14/MM2 28,
    2:DCC128
    Description
    This function supports locomotive's speed control.

    Function name
    SetLocoFunction(word address, unsigned char inFunction, unsigned char inPower)
    Parameter Meaning
    word address locomotive address
    MM2: ADDR_MM2+1~255
    DCC: ADDR_DCC+1~127
    unsigned char inFunction Function No. (0:F0, 1:F1, ・・・)
    DCC is up to F28, MM2 is up to F16(compatible decoders) or F4 (marklin decoders).
    unsigned char inPower 0: ON,
    1: OFF
    Description
    This function supports Locomotive's function control.

    Function name
    SetLocoDirection(word address, unsigned char inDirection)
    Parameter Meaning
    word address locomotive address
    MM2: ADDR_MM2+1~255
    DCC: ADDR_DCC+1~127
    unsigned char inDirection Direction (FWD: 1, REV: 2)
    Description
    This function supports locomotive's direction control.

    Function name
    SetTurnout(word address, boolean straight)
    Parameter Meaning
    word address turnout address
    MM2: ADDR_ACC_MM2+1~320
    DCC: ADDR_ACC_DCC+1~2044
    byte inSwitch 1: Straight
    0: turn to
    Description
    This function supports turnout control.

    Function name
    WriteConfig(word address, word number, byte value)
    Parameter Meaning
    word address dammy address
    This paramter is ignored.
    word number CVNo. Please check CV specification at NMRA web site.
    byte value CVValue. The value range is 0 to 255.
    Description
    This function supports CV write.

    Example of locomotive run

    1. /*********************************************************************
    2.  * Desktop Station Gateway Sketch for Arduino UNO/Leonard
    3.  *
    4.  * Copyright (C) 2014 Yaasan
    5.  *
    6.  */
    7. #include <avr/wdt.h>
    8. #include <SPI.h>
    9. #include "DSGatewayLib.h"
    10. #define CHANGETIME 5000
    11. DSGatewayLib Gateway;
    12. void setup()
    13. {
    14.     
    15.     Gateway.begin();
    16.     
    17.     delay(5000);
    18.     Gateway.SetPower(true);
    19. }
    20. void loop()
    21. {
    22.     int aSpeed;
    23.     word aLocAddr = ADDR_MM2 + 3;// <- This declaration decides locomotive address and protocol.
    24.     
    25.     // Go forward
    26.     Gateway.SetLocoDirection( aLocAddr, 1);
    27.     
    28.     for( int i = 0; i < 10; i++)
    29.     {
    30.         aSpeed =i * 73;
    31.         Gateway.SetLocoSpeed( aLocAddr, aSpeed);
    32.         delay(CHANGETIME);
    33.     }
    34.     
    35.     for( int i = 0; i < 10; i++)
    36.     {
    37.         aSpeed = (10 - i) * 73;
    38.         Gateway.SetLocoSpeed( aLocAddr, aSpeed);
    39.         delay(CHANGETIME);
    40.     }
    41.     
    42.     // Go reverse
    43.     Gateway.SetLocoDirection( aLocAddr, 2);
    44.     
    45.     for( int i = 0; i < 10; i++)
    46.     {
    47.         aSpeed =i * 73;
    48.         Gateway.SetLocoSpeed( aLocAddr, aSpeed);
    49.         delay(CHANGETIME);
    50.     }
    51.     
    52.     for( int i = 0; i < 10; i++)
    53.     {
    54.         aSpeed = (10 - i) * 73;
    55.         Gateway.SetLocoSpeed( aLocAddr, aSpeed);
    56.         delay(CHANGETIME);
    57.     }
    58.     
    59. }

    Go to top.