Arduino DCC++

Introduction

DCC++ is a Command Station based on the Arduino UNO/MEGA and a L298 Motor Shield.

  • The DCC refresh stack size is 12, on a MEGA up to 50, with 127 speed steps and 28 functions.
  • Programming track
  • Programming On the Main. (Write only)
  • 32 GCA Interfaces compatible I/O.
  • DCC stationary decoder support.
  • 2A Booster power.


Features

Extra features provided by the Rocrail implementation:

  • Slot management with passive slot purge after 30 seconds idle and speed zero. (Can be changed in the setup.)
  • Start of Day directly after establishing a serial connection.


General Setup

The DCC++ library in Rocrail is dccpp.

Sub-Library

Serial-USB

The baud rate is fixed at 115200.
The only thing to setup is to choose the right virtual serial port.

TCP/IP

A TCP/IP connection can be used if the Arduino features an Ethernet Shield.
The TCP/IP Port is fixed at 2560.

The Config.h source must be modified and recompile for using the Ethernet Shield:

/////////////////////////////////////////////////////////////////////////////////////
//
// DEFINE COMMUNICATIONS INTERFACE TYPE
//
//  0 = Built-in Serial Port
//  1 = Arduino Ethernet/SD Card Shield
 
#define COMM_TYPE   0

Example of a connection response with ethernet:

20160315.083459.796 r9999I dccpprea ODCCPP   0772 evaluate message: <iDCC++ BASE STATION FOR ARDUINO MEGA / ARDUINO MOTOR SHIELD: BUILD Mar 15 2016 08:31:58>
20160315.083459.806 r9999I dccpprea ODCCPP   0772 evaluate message: <N1: 192.168.100.153>

Options

Timeout

Serial read timeout in ms.

Slots

The number of slots is default 12. If using the MEGA it can be increased in the DCC++ sources.
The number of slots must be less or equal to the number of registers set in the DCC++ sources.

DCC++ comment:
You can increase the number of registers to greater than 12, especially if running on he Mega, not sure what the max would be, but I'm guessing about 50.

The number of slots, registers, can be changed in the Config.h line 24:

// DEFINE NUMBER OF MAIN TRACK REGISTER
 
#define MAX_MAIN_REGISTERS 12

Slot Purge Time

The minimal idle time in seconds before a slot ist purged.

Sensor off delay

For pin 22..53 on the MEGA only.
Number of ms to wait before reporting an input as off. (The value should be a multiple of 10.)
The delay timer will be reset if an input gets high within this time.

System Info

Poll the main operations track current. (To show in Rocview's status bar.)

Echo commands

Echo switch commands.

Swap gates

Swap the turnout and straight commands.

Reduce IDs

Reduce the generated switch and output IDs to 16. (0…15) Default is 256.
This option allows usage of an Arduino Uno with more than 45 devices addressed on DCC.

Serial device check

Some Windows configurations will crash at Rocrail server startup if the following option is not set:


I/O Setup


Add

Add a new I/O as defined with Type/Pin/Options.
It will be temporary created in the DCC++ CS.

Modify

Modify the selected I/O with the Type/Pin/Options settings.
It will be temporary modified in the DCC++ CS.

Delete

Delete the selected I/O.
It will be temporary deleted in the DCC++ CS.

Query

Query all defined I/O's in the DCC++ CS.

Save

Save all defined I/O in EEPROM.

Erase

Erase all defined I/O from EEPROM.
A new query is automatically issued.

Options

Output

Option Bit Value
Invert 0 0 = forward operation (ACTIVE=HIGH / INACTIVE=LOW)
1 = inverted operation (ACTIVE=LOW / INACTIVE=HIGH)
Restore 1 0 = state of pin restored on power-up to either ACTIVE or INACTIVE depending on state before power-down; state of pin set to INACTIVE when first created
1 = state of pin set on power-up, or when first created, to either ACTIVE of INACTIVE depending on bit 2
Initial 2 0 = state of pin set to INACTIVE upon power-up or when first created
1 = state of pin set to ACTIVE upon power-up or when first created

Sensor

Option Bit Value
Pull-up 0 1 = use internal pull-up resistor for the pin
0 = don't use internal pull-up resistor for the pin


Addressing

Sensors and Outputs are sharing the same address space; Avoid overlapping to prevent unexpected behaviour.

Switches

Accessory

Switches are addressed by the MADA scheme with decoder address and port. (11.158+)

None Accessory

Command Output
straight address + 0
turnout address + 1

None Accessory Single gate

Command Output Pin status
straight address OFF
turnout address ON


Sensors

Free Arduino pins can be used as sensor ports.

Outputs

Accessory

Outputs are addressed by the NMRA scheme with decoder address and port.

None Accessory

Free Arduino pins can be used as output ports.
To map the output for DCC the option “As switch” must be activated.

Signals

The accessory flag is used for Output commands.

Aspect numbers

Aspect number and Aspect Value can be used.
The aspect value represents a bit masks used for the four signal addresses.


G-ASH02

I/O interface for the Arduino MEGA.
dccpp-hw.jpg

Type

Type code Function
N No operation
O Output
I Input

Options

I/O n

The GCA I/O connector selection.
The button layout resembles the PCB layout.


PIN mapping

MEGA PINs GCA connector GCA I/O
22..36 (even) I/O 1 1..8
23..37 (odd ) I/O 2 9..16
38..52 (even) I/O 3 17..24
39..53 (odd ) I/O 4 25..32


The I/O connectors will match all GCA boards like GCA76, GCA77, GCA93, GC94, GCA173 etc

Jumper Function Remark
JP1 Use 5V from Arduino board if placed. Place only if the Arduino is powerless, otherwise it will reset itself.

Files

Programming Track

The rail power must be set to on before using the Programming Track.
Do not forget to add the required jumper wire on the Motor Shield.


Install the Firmware

  1. Install the Arduino Software (IDE)
  2. Download the latest DCC++ Base Station release and unzip the sources:
  3. Open with the Arduino IDE the following file, found in the DCCpp_Uno directory:
    • DCCpp_Uno.ino
  4. Select the Arduino target, the one used, in the Arduino IDE:
    • Tools → Board → Arduino/Genuino UNO or MEGA
  5. Select the USB Port:
    • Tools → Port → COMx or /dev/tty* or /dev/cu*
  6. Write the DCC++ Firmware in the Arduino:
    • Sketch → Upload

HEX File

Trouble Shooting

Loco stops at max.speed

Set the number of Decoder steps to 126 instead of 128 on the Interface tab of the loco properties.

Ethernet Compile Error

If the following compile error occurs:

In file included from /Users/rob/Projects/Arduino/BaseStation-1.2.1/DCCpp_Uno/DCCpp_Uno.ino:179:0:
sketch/Comm.h:11:28: fatal error: Ethernet.h: No such file or directory
   #include ETHERNET_LIBRARY
                            ^
compilation terminated.
exit status 1
Error compiling.

Change line 11 in Comm.h: from

  #include ETHERNET_LIBRARY

to

  #include <Ethernet.h>


Windows crash nach Rocrail start

Some Windows configurations will crash at Rocrail server startup if the Arduino is connected by USB and the following option is not set:


Max. Current

In file CurrentMonitor.h the max. current can be changed on line 16:

#define  CURRENT_SAMPLE_MAX         300
according to
Trainboard.com
math.
correct
Value Max. current Value
300 800 mA 270
600 1600 mA 540
750 2000 mA 675

These values apply to the Arduino Motor Shield R3 with a Current sensing of 1.65 V / A.
The Current sensing of other Motor shield types may vary, especially if its max. current is > 2 A.
See for more information: Trainboard.com www.trainboard.com_highball_data_attachments_171_171670-95fce61ebb745f799c8472bf81c9e6ad.jpg

:!: Important Note: There are Motor shields with Driver chips LM298 which are so mounted that the heat can't pass over to the Board surface.
The picture shows that in this assembly, it may possible to push a Paper strip under the chip.
At full load (2 A) for a unit with this lack can't the heat dissipate and the chip get inevitably to hot and will be destroyed.
See: Trainboard.com


Links


Personal Tools