Model Rail Digital DCC Command Station Arduino and Free App

5,344

11

93

Introduction: Model Rail Digital DCC Command Station Arduino and Free App


Updated 5 may 2021 - For LMD18200T use sketch 'locomotive_dcc_lmd_onboard_v13.ino'
------------------------------------

Updated 11 April 2021 - For LMD18200T use sketch 'locomotive_dcc_lmd_onboard_v12.ino'
This now include full read/write for CVs 1-1024 and a fail safe feature

Replace 10k resistor connected to 10uf capacitor with a 470 ohm.
----------------------------------------------------------------

Updated 24 March 21: replace 10k resistor connected to 10uf capacitor with a 1k ohm.
This provides improved CV read operations along with the updated Arduino sketch
locomotive_dcc_lmd_onboard_v10.ino

----------------------------------------

Updated 10 November 2020 - compatible with new App 'Locomotive DCC 2' - new sketch 'locomotive_dcc_lmd_onboard_v9.ino'

Updated 17 July 2020 - new sketch for Arduino Pro Mini - 'locomotive_dcc_lmd_onboard_v6.ino'

Updated 21 March 2020 to include new design of PCB with on-board LMD18200t IC

Update 15 Feb 2020: Amended sketch to suit CV reading of Hornby decoders (all other types OK)
Use latest sketch
'locomotive_dcc_v1_2.ino'

Update 8 October 2019: On some phones running Android android 6, 7 or 8 there is a bluetooth issue to be aware of. The phone will pair OK but may not connect through the App. When this happens try switching the phone Bluetooth setting off and on again then close the App before opening again - the BT connection should be OK. - see link for possible answers here.

Update 14 September 2019:
Updated sketch to extend read/write of CV's to match Lenz, ESU, Hornby, NCE and TCS decoders.
Please use sketch 'locomotive_dcc_v1.ino'

Update 6 September 2019:
Updated sketch to extend read/write of CV's to match NCE and TCS decoders.
Please use sketch 'locomotive_dcc6_Sep_2019'

Update 3 September 2019:
Corrected error in sketch whereby CV write only worked properly on CV1 - 9 e.g. CV29 could not be written. Please use sketch 'locomotive_dcc3_Sep_2019'

Update 21 August 2019:
New App released includes CV read/write facility now available on Google Play Store

Update 20 May 2019: please download improved App version 2 making DCC o/p active only when Bluetooth is connected. Updated sketch available here.

Update 18 May 2019: New App released with much more functionality - up to 28 functions with editable titles, visibility and momentary switching. Increase to 16 turnout/accessory buttons. On screen speed control bars added allowing 1 to 4 locos to be controlled at once.
New App on Google Play Store 'LocoMotive Control'

Update 17 Feb 2019: You may have to modify the HC-06 Bluetooth module to extend its range of reception.
I added a solid copper wire (from mains earth wire) 31.2 mm in length (1/4 of wave length for 2.4 GHz). See attached photo in Step 2.

Update 29 Jan 2019:
Addition of momentary option on F2 and F3 for horn sounds
Preset max speed for each loco

This is the most efficient DCC command station possible to build.
No other system can do so much with so few components.
An easy to assemble fully functioning DCC Command station with PCB available on eBay plus requiring only a few parts.
The Apps are designed to operate on Android phones running version 8.0 and upwards.

No need to purchase any propriety systems, this is a stand alone unit operated by a free App called
'LocoMotive Cab'
Works with NMRA compliant decoders. This system compiles the operating DCC packets within the App which are sent to the Arduino interface to combine with the DCC clock signals.
Purchase this PCB on eBay PCB or here on eBay DCC kit for modular kit.
Get free App LocoMotive Cab on Google Play Store or full version 'LocoMotive DCC'
New release of 'LocoMotive DCC 2' with 4 digit address, program on the main and consist control.
System Features include:

Roster list allowing multiple engines with short or long address
Ideal for small to medium size layouts
2 Amps load drives up to 12 of OO/HO locomotives using H-bridge specified
Short circuit protected
Automatic over current cut-out, adjustable in the code
Lights and directionFunctions 1 to 8 (1 to 28 on full App)
Turnout / points / accessories 8 pairs of outputs (16 on full App)
Custom naming of your locos
Programming the CV1 loco address
Full App has read / write CV's 1 to 255
Add your own accessory addresses
Free App - Change F2 and F3 from momentary to on/off switches
Full App has editable titles, visibility and momentary options on 28 function buttons
Full App has 4 on-screen speed bars for control of 4 locos at a time
Add max speed for each locoLong Address (Locomotive DCC 2 App)
Program on the main (Locomotive DCC 2 App)
Form a consist (Locomotive DCC 2 App)

Further to previous work on DCC wireless systems, I have developed a Bluetooth Command Station linked to a receiver Arduino based circuit with a HC-06 BT module and a LMD18200 H-bridge Motor driver delivering 2.5 Amps.

The overall cost of parts is around £20 with parts purchased from eBay.

Step 1: Arduino Sketch

Updated 5 May 2021 - For LMD18200T use sketch 'locomotive_dcc_lmd_onboard_v13.ino'
This now include full read/write for CVs 1-1024 and a fail safe feature

Update 24 March 2021 - For LMD18200T use sketch 'locomotive_dcc_lmd_onboard_v10.ino'

------------------------

Update 10 November 2020 - For LMD18200T use sketch 'locomotive_dcc_lmd_onboard_v9.ino'

To load a sketch on to the Arduino Pro Mini you need a USB- TTL adapter such as the CH340 available on eBay or here on Hobby Components website :

https://hobbycomponents.com/usb-interface/586-ch34...

The Android App sends a complete packet to the receiver and is decoded here into an array of data. Depending on whether 3 or 4 bytes are received the code will generate the correct DCC packet format for the train track.

For more information on the NMRA packet standard refer to:
https://www.nmra.org/sites/default/files/s-9.2.1_2...

The LMD requires the DCC signal on the DIR pin and the PWM pin held HIGH.

This latest version includes the Read Write of CV's facility. The sketch has additional code to create the required packet formats to enable reading and writing of CV values.

Step 2: Using PCB With LMD18200t IC On-board

Updated 2 Sept 2019: Fritzing circuit diagram updated with change in Tx Rx BT connections

The Arduino Pro Mini receives the Bluetooth data via the HC-06 module. The Arduino generates the NMRA standard clock cycles of data in packet format. The received data interrupts the sequence when new data is received and the DCC packet is updated to send instructions to the train tracks.

Note: The Arduino must be a Pro Mini ATmega 328 16MHz 5v version

List of parts required:

1 off Arduino Pro Mini Atmega328P 5V/16M eBay
1 off LMD18200T H-bridge IC available from:
Farnell : order code 1468979
RS Components : stock num 534-4276
Aliexpress : HK IC Center Technology Co Ltd
(beware of other sellers on Aliexpress who supply faulty parts)

1 off HC-06 Bluetooth module eBay
1 off 0.1 ohm 2W Metal Film Resistor 0.1R 2 Watt (11.5 mm x 4.5 mm) eBay
7 off Capacitor 0.1uf eBay
2 off 10kΩ Resistor eBay
1 off Capacitor 10uf 25v; eBay
1 off Capacitor 470uf 25v or 35v ; ebay
1 off 4.7kΩ Resistor eBay
1 off L7805 CV Positive Voltage Regulator IC eBay
1 off 4-pin Female Header Edge Pins Strip 0.1" 2.54mm eBay
2 off 12-pin Female Header Edge Pins Strip 0.1" 2.54mm eBay
1 off 6 pin 2.54mm PCB Universal Screw Terminal Block eBay
1 off Zener Diode (any value between 3.0 and 4.7v) e.g. BZX79C3V6. 3.6V; 0.5 W eBay
2 off 2-pin PCB mount screw terminal 10 amp 5mm spacing
1 off Aluminium heat sink for TO220 (as designed for L298N)

Wire

Power `supply:
Do NOT use a DC train controller as these do not provide a true DC voltage.

Power `supply: voltage of 14 to 16 volts DC
Ensure correct polarity of output plug before connecting.

15V 2 Amp version with a 2.1/2.5 x 5.5 mm plug, search for eBay item # 401871382681

To extend the range of the HC-06 Bt module, solder a wire onto the end of the antenna on the module. I used a solid copper wire (from mains earth wire) 31.2 mm in length (1/4 of wave length for 2.4 GHz). See photo above.
This wire should be covered in sleeving to avoid accidental shorting to other components.
Please note - the HC-06 connections are Rx (on PCB) to Rx (on module) and Tx to Tx

For the use of a LMD18200 h-bridge IC, I have added current sense components to provide protection from short circuit or overload issues on the train track, The updated circuit diagram and Arduino code now includes the current sense function. The code limits the max current to 2 Amps when reached, the LMD18200 h-bridge is shut down by applying a HIGH signal from D13 on the Arduino to the 'Brake' input on the h-bridge. The use of a 0.1 ohm current sense resistor gives an analog input range of 0 to 200 mv on Arduino sensor pin A0 for up to 2 Amps load. For approx 5mv per analog step input (1023 total steps or divisions) gives 0 to 40 divisions or 2 Amps / 40 = 50mA per division. The measured current precision is 50 mA however we are protecting the h-bridge when 2 Amps is reached. The LMD18200 also has in-built over temperature protection as a back up.

if(C >2000){ // 2.0 amps

Serial.println("Over Current");
digitalWrite(13, HIGH); }

The value of the current drawn is sent to the Android App via Bluetooth every second.

void send_c(){
t = millis() - lastmillis;
if (t >= interval){
bluetooth.write(sensorValue);
bluetooth.write('c');
lastmillis = millis();
} }

Step 3: Android App

Download the FREE version of the App from Google Play Store - 'LocoMotive Cab'

Download the FULL version (£5.99) of the App from Google Play Store - 'LocoMotive DCC'
Instructions attached for full version with enhanced features including read/write of CVs, full function control 1-28, 4 off speed control sliders, buttons with fine control of speed steps up and down.

Download the 4 digit address version (£8.49) of the App from Google Play Store - 'LocoMotive DCC 2'
Instructions attached for full version with enhanced features including read/write of CVs, full function control 1-28, 4 off speed control sliders, buttons with fine control of speed steps up and down, 4 digit loco addressing, program on the main and consist control.

Be the First to Share

    Recommendations

    • Clocks Speed Challenge

      Clocks Speed Challenge
    • Toys & Games Contest

      Toys & Games Contest
    • Big vs Small Challenge

      Big vs Small Challenge

    93 Comments

    0
    scubabeme
    scubabeme

    3 months ago

    Ok, so I FNALLY got all the pieces together and assembled. But, when I go to compile the sketch I am informed of some variables "not declared in this scope". In truth, I can't find them defined in ANY scope. Two of them (TCCR2A, TCCR2B) do not really appear to be used at all except where a value is assigned. I don't know what type they are supposed to be, though as they are not used (that I can find...) those lines should be safe to comment out. Right? The next is TCNT2, which is used, but I'm not sure what data type it's supposed to be or at what level it should be declared. I rather expect I will encounter more. Am I maybe missing a header file?

    0
    BillC35
    BillC35

    Reply 3 months ago

    Hi, these variables are part of the clock sequence in the microcontroller and are vital to create the DCC signal.
    If you copied and pasted the sketch into your Arduino IDE, there will be some errors. You should re-type the lines that are "not declared'
    Can you load other sketches on to the Arduino Pro Mini ok ?
    Try some simple sketches just to ensure correct set up.

    Bill

    0
    R_ask
    R_ask

    Question 10 months ago

    I’m using the full Bluetooth version, and it’s working fine with my locomotives, but the solenoid switches will not work properly, according to my sniffer the code is not coming out all the time from box when I press the button on my phone. Timing errors???? My system works perfect when I’m using dcc++. Any suggestions what’s wrong?

    0
    BillC35
    BillC35

    Answer 10 months ago

    Hi, did you build this yourself or did you purchase system from me ?
    Please ensure you have the latest version of the App LocoMotive DCC v17
    Go to the 'Address' layout and enter 6 into the 'Qty of Packets sent' field
    - if that does not work, try more than 6

    Bill

    0
    R_ask
    R_ask

    Reply 10 months ago

    I’m using a purchase version, and your tip really made the trick. Thank you. But I also have another issue, on my sniffer it shows two and sometimes three trains, although I only have one train configured, any suggestions??
    Richard

    0
    BillC35
    BillC35

    Reply 10 months ago

    Hi Richard
    Glad that worked for you.
    The system does automatically transmit loco numbers 1 and 2 with zero speed, in addition to your current locos. This is required to ensure constant data is seen by the decoders otherwise they may stop responding to DCC packets.
    It should not interfere with your normal operations.
    Bill

    0
    jarable1
    jarable1

    11 months ago

    Thanks very much for this - working nicely. It's also better at programming CV's than the other Arduino/motor shield combinations I've tried ( likely the LMD18200 ).
    I'm finding the Android app is a little unresponsive sometimes - not sure if it's my tablet or what, but sometimes it takes multiple taps to make a command change.
    I'd like to build a handheld controller similar to your DCC Command station - probably from a Raspberry Pi zero sending Bluetooth commands. Any chance of getting the command code you use to communicate to the Bluetooth receiver? I've can see the serial output to the BT and can guess at the parameters, but thought I'd ask
    Sean Lavery
    Canada

    0
    metradio
    metradio

    Reply 10 months ago

    Hi Sean, as a fellow LocoMotive DCC user I must comment that my Samsung mobile phone using the Android app has no lag on Bluetooth and commands work first time every time..
    Mike Burgess
    UK

    0
    BillC35
    BillC35

    Reply 11 months ago

    Hi Sean, glad to hear you have successfully built the system.
    If you are familiar with Arduino code, the required commands can be extracted from the sketch on my Instructable on the hardware version of dcc controller. Or you can get the DCC packet details on the NMRA website.
    Bill

    0
    Klaus M
    Klaus M

    Question 10 months ago

    Hi,
    I also bought the complete set. For some days it worked fine, now I have the problem that the bluetooth connection failes, see my video: https://www.youtube.com/watch?v=SGQhWt5rl3A . What can I do?
    Regards
    Klaus

    0
    BillC35
    BillC35

    Reply 10 months ago

    Hi klaus, on looking again at your video, I think there may be a short circuit on your track. The red led on the Arduino flickers on and off meaning there is a fault, please check.
    Regards, Bill

    0
    Klaus M
    Klaus M

    Reply 10 months ago

    Hi Bill, you were absolutely right. There was a short circuit, that I didn't see. Now everything is fine again.
    Thanks for your help.
    Regards Klaus

    0
    BillC35
    BillC35

    Answer 10 months ago

    Hi Kaus, sorry to hear of this problem. Please try pairing the Bluetooth device again with your phone. Delete the original pairing and start again.
    Contact me directly on:
    billc at john-lewis dot com

    Thanks
    Bill

    0
    hagen.sroka
    hagen.sroka

    11 months ago

    I have this part now, I dont know how I can use a loco with adress example 27.
    Can somebody help?

    0
    BillC35
    BillC35

    Reply 11 months ago

    The Locomotive DCC Controller is limited to loco ID 1 to 20
    However, you can change address on the App from 27 to an address within this range.
    If you have the free App go to 'Address' on main menu, then press 'Address' on CV1 page and select a number 1-20 then press Go. The loco will now have this new address.
    If you have the full App you can also read and write CV's including CV1 (loco address)

    Bill

    1
    Spicesimmer
    Spicesimmer

    Question 1 year ago

    Hi Bill,
    I have your LocoMotive DCC and the full Android app.
    At present, I only have an analogue train. How do I setup the app please for it?
    (Loco just buzzes and does not move).
    Kind regards....Spicesimmer

    0
    BillC35
    BillC35

    Answer 1 year ago

    Hi, did you build the DCC system or purchase a fully assembled PCB ?
    You will need to purchase a decoder for your analogue train. The controller only works on DCC and has no analogue output. The train will just buzz as it is fed with +/- 14v AC and will not move.
    I do not know where you live, but I can give you a link to and eBay source for a decoder. Once you purchase one, follow the instructions to install in your train.
    The cheapest decoder here:
    https://www.ebay.co.uk/itm/192696880266

    0
    Spicesimmer
    Spicesimmer

    Reply 1 year ago

    Hi Bill,
    Thank you for such a prompt answer :)
    I bought the fully assembled PCB from Ebay.
    Thank you for clarifying about my analogue train.
    I have ordered a Laisdcc 2 function 6 pin NEM 651 plug DCC decoder for N gauge already, just waiting for it to arrive. I can't wait.
    Kind regards....Spicesimmer

    0
    cvetkov.alexander
    cvetkov.alexander

    1 year ago

    Hi Bill. The new PCB looks great. Maybe it's a good idea to order one. I want to ask is it possible to connect the dcc station to a computer with JMRI? I tried, but failed. Maybe you tried? Would you share how the tram from the clip changes direction? Is it DC or DCC?

    0
    BillC35
    BillC35

    Reply 1 year ago

    Hi Alex, I hope you are keeping safe and well.

    For JMRI, I use a SPROG device found here:
    https://www.sprog-dcc.co.uk

    My DCC system is stand alone via Bluetooth and an Android App and does not connect to JMRI.

    In the video, the tram changes direction using a Lenz decoder and a ABC braking module found here:
    https://www.aandhmodels.co.uk/abc-braking---automa...
    I have an ABC module placed at both ends of the tram track (across a cut in the track at about 20cm from each end)

    Bill