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.
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:
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.
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. |