Thursday, April 13, 2017

Cheapest DCC Command Station with Loconet interface

In a previos post I talked about the DCC++ Command Station. This is an open project to build you own DCC command station using the Arduino platform. It's quite simple and easy to mount, and features a full DCC command station with PC interface and compatible with Rocrail and JMRI. This time I want to go a little bit further and be able to build a more standard command station with Loconet interface. There are very cheap and professional command stations like DR5000, for sure much better than this, but building things by your own provides satisfaction, right?

Clicking Here you can read the complete information in my previous post.

Both the protocol and interface of the basic command station project shown in my previous post aren't standard, and despite you can connect to the available Arduino I/O's some sensors, lights or switches, it's not enough for a medium sized layout. Anyway is a good command station to have apart from your layout to program and test locos. It's worth the 12€, for sure.

I took the source code of the DCC++ project (it's open an published in github) and tried (successfully) to add Loconet support, with some goodies like:

  • 3 Led to know the state of the command station (ON, OFF, SHORT CIRCUIT)
  • 2 Buttons to turn on and off the track current
  • 2 relays to switch to the programming track current automatically when a programming command is received
  • Display support, showing CV values when reading or writing and current consumption
  • External emergency button
My new sketch can only work on Arduino Mega. I had to discard Arduino UNO and Arduino NANO support as the program was too big for them, and I wanted to have a better performance with a lower cicle time.

The source code and the sketch to upload to Arduino MEGA can be downloaded from my public GitHub repository:


The PC interface support does not longer exist in this version of the command station, as my intention is to have a pure Loconet command station, exclusively dedicated to manage the trains. I prefer to have individual devices for each function, so for PC interface I use a dedicated Arduino UNO with an Ethernet shield. I'll post the information about how to mount the PC interface for a Loconet network in the next post. All this has the advantage that I can change any device without affecting the other Loconet devices or having to change any setup.

Having an independent PC Interface allows me, for example, to change my Intellibox Basic command station and use my new Arduino Based DCC++, or a DR5000. It's just disconnect one, and connect another. No changes in PC, software, or any other device.

So let's go with the connection diagram:


 You see the base is an Arduino MEGA with the Motor Shield on top and the bridge between pins 2 and 13, exactly as the original DCC++ project.

Then you have the 3 led to indicate "track power connected", "track power disconnected" or "error/fault/shortcircuit".

Two external buttons to turn on or off the track power, plus an extra external emergency button. Pressing this emergency button will provoque sending an emergency stop message through the loconet network, and not a normal power off message like with the normal buttons.

Relays are also optional, but if you use them the isolated track section will have normal current and will switch to programming current just when needed (read or write command received from Rocrail or the program you use). So you don't need to use manual switches or to have a separated track for it.

The display is not exactly the one from the photo, sorry but I couldn't find the right one in Fritzing software, but the connection schema is correct. I'm using an standard Keypad LCD shield from DFRobot (check it here). Two of the keys of the Keypad LCD shield can be used to turn on and off the command station, so the external buttons are not necessary.

Finally, a loconet shield board (like GCA185 from Giling Computer Applications) has to be used, connected to pins 47 and 48 instead of the usual 7 and 8 when you are using an Arduino UNO.

But there is an important issue with Loconet!
Any Loconet network needs a "Loconet Terminator" and a 12V power source to work. This is always provided by the command station, but in this case we need to add this. In this page from RR-Cirkits you can find information about it. 

You can use an old ATX PC power source to supply the 12V to Loconet and build your own "Loconet Terminator".  A "Loconet Terminator" is just a 15 mA pull up constant current source to 12V.:





If you have a LocoBuffer conected to the LocoNet it has also the option to provide this pull up termination by selecting 'Term" option.

Finally there is another solution to the previous issues, this is using a GCA101 from Peter Giling. This a board that provides you 3Amp power to Loconet, so you will never run out of power to connect more and more modules, and the board has also a jumper to activate the "Loconet Terminator" already included in the board. This board also provides you the PC Loconet interface to connect you layout to Rocrail.

This is the command station mounted in a simple electricity box, but we use it in the club and has been proved reliable enough to drive trains during all week end in exhibitions with no errors:



I hope to have more free time to post other Arduino based modules I have developed. Thanks for reading!!!





34 comments:

  1. Hi, thanks for sharing the knowledge!
    is it working now or still a prototype?
    What decoder are you using in the train?

    ReplyDelete
    Replies
    1. Thanks to you for your comment. It is working, this is the command station I use in my second layout. We tested it with Uhlenbrock, LaisDCC, Kato, Doehler&Haas and Digitrax decoders. All types tested (N scale) work ok.

      Delete
  2. Hi Dani, Will this integrate with a Digitrax Loconet command station? I'm thinking about using arduino to capture input from some infrared sensors on my layout built based on Digitrax loconet components.

    ReplyDelete
    Replies
    1. Yes! It will integrate to any Loconet existing system, from Digitrax, Uhlenbrock, Digikeyjs or any other.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi,

    finally I made it running. Great project and work done so far.

    There was a correction needed. The grey line from A0 at the display needs to be read analog and the code says 'analogRead(15)'. This is A0 at Arduino Uno but not working with Mega. I connected it to A4 instead of 15 and wrote 'analogRead(A4)'. Then it works.

    Further I added a Long-Ack-Command as reaction to Slot-Write which enabled us to use FREMO Throttles.

    https://www.youtube.com/watch?v=yfvjpXrHsqk&feature=youtu.be

    BR,
    Philipp

    ReplyDelete
    Replies
    1. There was an error in the schema, now it is corrected. Sorry for the delay answering Philipp!!! Thanks for your advice!

      Delete
    2. This comment has been removed by the author.

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Connection schema has been updated, there was an error with the connection of the gray wire from LCD Keypad Shield to Mega board. A0 from the LCD Keypad Shield is connected to A15 in Mega board.

    ReplyDelete
  8. Hello Dani Guisado,

    how can i dispatch Fremo Fredi with this command station. it´s very interesting and not so expensive like a DR5000. what released you on the proto shield on the shematic. I´m searching for a cheap loconet station for my small narrow gauge projects in fremo for home use

    ReplyDelete
    Replies
    1. I don't use Fremo, so I cannot test it... but check the answer from Philipp some lines above, he managed to do it!

      Delete
  9. hola
    por casualidad,no tendria una tutorial para hacer todo esto.
    soy novato y me lio un poco.
    gracias

    ReplyDelete
    Replies
    1. Hola, he intentado escribirlo de la manera mas sencilla posible y con diagramas, pero realmente no es sencillo. Te recomiendo empezar por la central básica, sin loconet, que es el post anterior linkado en este mismo artículo. También puedes ir a la página original o ver los videotutoriales originales: https://www.youtube.com/watch?v=-nsVdpMhiTU

      Delete
  10. Hi, Dani. I have assembled your DCC++ with Loconet and find it works great except for one thing: I cannot get responses (either from throttle or IDE monitor) for Functions above F4.
    I am using the latest Loconet library. Perhaps your system is based on a different Loconet library?
    Fred Miller

    ReplyDelete
  11. I reported a problem with servicing functions above F4... turns out the problem only exhibits when using Digitrax UT-X series throttles. Works fine with Digitrax DT402 throttle as well as my own Arduino (loconet) based throttles.

    ReplyDelete
  12. Hello Dany, my question is about the GCA185 Loconet interface. Is it fully compatible with Arduino Mega? I tried to run the Loconet Throttle example supplied with the Loconet Library loaded in a Mega, but unsuccesfully. The same sketch works perfectly with Uno.
    Livio Busnelli

    ReplyDelete
    Replies
    1. Hi Livio, it is fully compatible, but you cannot plug it on top of MEGA as you do with UNO because the communications pins are not 7 and 8. Communication pins are 47 and 48 instead as you can see in the schema.

      Delete
  13. Hello Dani
    I have got your loconet version of DCC++ up and running connected to Rocrail and working with locos. Is it possible to control turnouts through DCC with it?
    Anders Thalme

    ReplyDelete
    Replies
    1. If you use Loconet for sure, this is how I do it. But I never tried using DCC to manage turnouts, I'm not sure...

      Sorry I don't have more experience on that.

      Delete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. Hi, would it be possible to connect the Loconet Railsync Lines directly to the motor shield's main track output to connect an additional booster? Or what do you think would be the best way to do so? Great project by the way!
    Tom Stirnkorb

    ReplyDelete
    Replies
    1. I'm sorry I have not tested this scenario... I just use this command station for a small test track, so I don't need any booster. sorry!!!

      Delete
  16. The zip file currently downloadable from Git does not contain the Loconet version nor does it have the two spreadsheets (.xlsx files)

    ReplyDelete
    Replies
    1. Hi Darryl, are you downloading the right one? I checked this and it is complete:
      https://github.com/ClubNCaldes/LNetDCCpp

      Delete
  17. Hi Dani, I was admiring your good work and build the layout as I understood it from your project page. I got the Mega working with DCC (DCC decoder turnouts work properly) in both Rocrail and JMRI. I also got the Loconet Hardware TX and RX working properly. Proof: if I enable the debugging in the Loconet Library I see packages coming from a loconet-throttle.

    Question is: If the DCC++ is configured and uses the serial rs232, how do I configure the Loconet functionality. I want to use the command station to retrieve sensor information from a loconet decoder in Rocrail and JMRI.

    Can you explain if this is a possible use case? Or would I still need another loconet interface to make the connection to the PC?

    ReplyDelete
  18. Hi Dani, I was impressed with your work and decided to build the DCC++ / loconet commandstation. I already build a DCC++ only station and the purpose was to add loconet to retrieve sensor information.

    I think I got the hardware working.
    - I configured the DCC++ interface and could steer a loc and switch a turnout.
    - I also think the hardware for the Loconet should be OK as I turned on the debug code in the loconet library and saw packages being received by the Mega on the serial monitor in the IDE. I used a standard loconet throttle for this from the library with a nano and similar loconet electronics. RX and TX leds light up on both boards if I send commands.

    However if I configure the DCC++ commandstation in Rocrail or JMRI it uses the RS232bus. How do I configure the loconet functionality as an interface to read or write to the LN network? If I try to configure just as a Loconet interface I seem to get no response. Is HW CTS required for this to work, if so how do you implement this on the Mega and then still the question remains how to configure the PC software.

    KR

    W. Bertels

    ReplyDelete
    Replies
    1. Hi, as you can read a loconet terminator is needed. In my case, I'm using a Loconet booster that already has the terminator. I'm using a GCA101 from Peter Giling. This is a board with ethernet connection to connect with the PC and has two loconet connectors, with the needed terminator for the bus to work.

      Delete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Hi Dani,

    the project https://github.com/ClubNCaldes/LNetDCCpp is missing the file LocoNet.h, referenced in DCCpp_Uno.ino and LNetCmdStation.h

    Do I need some of the other projects?

    Thanks,
    Tom


    ReplyDelete
    Replies
    1. Hi, you need to install in your Arduino environment the Loconet libraries. Search them in the library menu of the arduino IDE.

      Delete
  21. Hi Dani!
    I'm a little surprised that I can't find anything about the issue I encountered in this comment - thread: When reading CV values from the Programming track, only values below 128 are parsed (0->127). This is because the data7 - byte may only contain 7 bits of data, not 8. Bit#7 should stay 0. When the value of this data7 - byte is >127 (bit#7 set), it is still send over the LocoNet, but all receivers on the bus ignore the message. The MSB for cvvalue (bit#7) is actually set in the CVH byte, at bit#1 position. This is what Digitrax / LocoNet specifies, and after I implemented this in your code, it indeed now reads CV values from 0 to 255 in Rocrail.
    The other "fix" I applied (according to LocoNet spec), does unfortunately not work in Rocrail; When a CV read action fails (no loc on prog track), the PSTAT bit#0 should be set. This would tell Rocrail (in my case) that the CV read action failed, expecting "-1" for the CV in question, but Rocrail does not recognise the PSTAT value it seems to me, it still reads the CV-value what was in data7 (and CVH bit#1).
    Code added/changed in LNetCmdStation.cpp, line ~410:
    //#1: if cvvalue = -1, then PSTAT bit 0 = 1 ("Service Mode programming track empty- No decoder detected")
    if (cvvalue == -1){
    LnPacket->pt.pstat=1; //(bit 0 = 1)
    cvvalue=0;
    }else{
    LnPacket->pt.pstat=0;
    }
    //#2: Split up data7 if cvvalue >127. Bit 1 position at CVH is used for MSB of data7[LocoNet PUE 1.0 Spec. page 14], so bit 1 at CVH is set "1" when cvvalue >127 and data7 becomes cvvalue - 128.
    if (cvvalue >127){
    //set bit 1 at CVH
    bitSet(LnPacket->pt.cvh,1);
    LnPacket->pt.data7=cvvalue - 128;
    }else{
    LnPacket->pt.data7=cvvalue;
    }
    LocoNet.send(LnPacket);

    ReplyDelete
    Replies
    1. Thanks!!! Very useful information. I took the software from the DCC++ software as it is, this is a nice improvement for long addresses.

      Delete