New library DCCpp

Trusty Dec 24, 2017

  1. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    Ho, ho, ho...

    This is my small gift for this special day :LOL:, and my first message on the board (i dont count my introduction...).

    I have developped a library version of DCC++, named DCCpp, based on the Gregg's work of course, and adapted to be more configurable and easier to use for programmation beginners. See the joined samples to be convinced !

    This work has been done for the Locoduino french site, and the related article in french also was just published today, but internally, all is written in english and the associated documentation in extras/Doc of the library is also in english.

    So fell free to get it (on github), test it, critic it (not too much, its christmas !). Tell me also if my poor english can be improved...
     
    Simon Mitchell likes this.
  2. Simon Mitchell

    Simon Mitchell TrainBoard Member

    97
    97
    4
    Hi Trusty,

    This could suit me as a novice, however the github link doesn’t seem to be working?

    Cheers, Simon
     
  3. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    Sorry, but it seems to work for me...
     
  4. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    I (try to) post the zip file here...
     
  5. Atani

    Atani TrainBoard Member

    277
    271
    7
  6. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    Thanks for the help, but a direct link to the last release is not very good. If a new release is done, the link has to be updated too... I note the first suggestion, a link to the release list... Even if I continue to say that my direct link to the zip is working, and the best way to be sure to download the very last version !
     
    Atani likes this.
  7. Gary Menzel

    Gary Menzel New Member

    2
    1
    1
    I've been following DCC++ for a while and am just about stocked up on the parts (I didn't even have a train set until a week ago and am waiting on a motor shield and decoder to arrive). I've had the Arduino Mega for about 12 months and have continued to play around with it (in a non-train setting). I had intended to enhance Gregg's code eventually but am only just about to get my first DCC++ system up and running. Now I find this....

    I've had a quick look and I like what you've done with the code. I did want to check though if this can work as a complete plug and play for the base station (at least). For example, if I start with the most recent version of the original and then update my system with your code, will it just plug and play - or should I just start with with your repo? I guess I want to know if there are any subtle differences and also what your plans are for maintaining beyond this initial release.

    I'll probably just end up forking your code into my own repo (I already have Gregg's) - just so I have it moving forward.

    Regards,
    Gary

    [My ultimate goal (for now) is a Kato shelf layout with an end-to-end line double track using double cross-overs at each terminus and detectors to ensure correct down/up lines and have it fully automated with multiple engines running]
     
  8. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    Hi Gary. Nice project !

    The main goal of this library was to simplify the access to DCC++. From the point of view of the user, the main difference is in the .ino file, the sketch. In the one from Gregg, the main part is the internal code of the DCC motor. And to be able to use it, you have to add your own code to handle buttons, Lcd or Wifi communication (for instance). Some other files must also be modified to match your physical configuration (pins, ethernet...)

    In my point of view, the library must give an easy access to the configuration, and let you do what you want with your sketch. Some lines in setup and loop functions are of course necessary to configure pins, and only one file of the library have to be adapted to your needs : DCCpp.h, mainly for Ethernet purpose.
    This is the reason why my kind of sketch is a lot simpler -and very different- from the Gregg one. Take a look to the sample, there is some common cases conform to DCC++ traditional work with text commands (SerialDcc / EthernetDcc / Autotest), but there is also new ways to command DCC++ through C direct functions (MiniDcc and MaxiDcc).

    This library was developped at first for internal use on Locoduino website. All members (those in digital...) will use it, and some new versions with fixes and improvements will probably arrive soon ! From my part, I would add support for STM32 and/or ESP32... So, at least for several years, I will maintain it if God gives me life.

    At least, we (the website) have projects for an article about an automatic coming and going at defined and controlled speed with detectors at both ends... This program is already working in a club, we just want to publish this work !

    Please fell free to test DCCpp, and give me ideas to improve my work !

    Thierry.
     
    Simon Mitchell likes this.
  9. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    75
    72
    3
    Thierry, I haven't had a chance to run and test this yet. I should be able to get it within the next couple weeks but I will say I'm impressed with the work and agree it's a nice way to do it to put it in a library and then we can tweak for ourselves.

    I look forward to what gets developed in the future for it! If you haven't already you should visit the DCC++ throttles page here http://www.trainboard.com/highball/index.php?threads/dcc-hardware-throttles.90315/page-23 and here http://www.trainboard.com/highball/...ttle-design-ideas-to-finished-product.111737/ fro some really interesting stuff as well. Might help spur some thought for your ESP32/STM32
    Nice work and thanks for sharing!

    As an aside what program do you use to edit the library since can't be done in the IDE directly?
     
  10. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    I work on Windows with Visual Studio 2017 Community Edition (the free one...), and an Arduino Emulator I have developped to avoid physical tests. The main benefit of this approach is the use the Visual's debugger. I know it very well because I develop professionaly with it since the beta version of the first Visual (yes, i am not young...) ! The emulator is available under extras folder of the library as a complete Visual Studio solution. Of course, some physical real tests are always done before posting a new library, but the main part is done on Visual.
     
  11. Shdwdrgn

    Shdwdrgn TrainBoard Member

    42
    14
    4
    I pulled a copy from git today but haven't had much time to look through it yet. I saw you have several examples in there, could you tell me if one of those is specifically for a locomotive? I'm waiting for some optoisolators to arrive in the mail so I can pull a signal from the track, but in the meantime I might just poke at seeing if I can add in the wifi functionality to the code.
     
  12. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    This library is exclusively for locomotives ! Its main goal is to build a DCC controller, which will create the DCC signal on the rails and send orders to control speed and lights of locomotives. There is ways to control accessories, but either by sending DCC orders which can be received by an external stationnary decoder, either by controling directly a motor or a light through a pin of the Arduino. This library is not the right one if you want to receive DCC orders and command accessories. You should see my other library Commanders and its part DccCommander for that.
     
  13. Shdwdrgn

    Shdwdrgn TrainBoard Member

    42
    14
    4
    Ah ok, I misunderstood then. I already have DCCppESP32 set up as a base station so now I'm looking specifically for software to load on to the esp8266 I have installed on my test loco, and also something to set up on an arduino to receive orders for controlling turnouts. And you're saying that can be found under your commanders library? The terminology for DCC is really baffling to me.
     
  14. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    The DCCpp library is exactly the same as DCCppESP32, but for classic Atmel Arduino (Uno, Nano, Mega...) and under the form of a library, easier to use than the original work of Gregg DCC++ (imho) .
    To be clear, DCC is a protocol, a way to send information and/or orders through the rails. In this protocol, you have only one sender, the controller, and one or more receivers like the locomotives decoders, the decoder of functions for wagon lights or lightning, and the stationnary decoders to control turnouts and traffic lights.
    DCCppESP32, DCCpp or my other library DcDccNanoController (yes, i have produced a lot of libraries these years...) can be used to build the controller.
    My library Commanders handles buttons, CAN bus, I2C bus, serial input and/or DCC reader to get orders in a standard way. With its help, it is very easy to decode the DCC signal to retrieve the DCC orders and do what must be done with accessories.
    Of course, there is also a library to drive classic accessories like motors, turnouts, and lights named ... Accessories ! But this is another story...
     
  15. Shdwdrgn

    Shdwdrgn TrainBoard Member

    42
    14
    4
    Thanks for the info. I'm looking under the Accessories project now, and the LMD18200 example seems to be the one that works with motors but I'm not following your definitions. What does "left' and 'right' mean as applied to driving a motor? Where do you define which pins connect to the motor driver chip? In my experience with motors and arduinos there is generally one pin which defines direction (0 spins one way, 1 spins the other way), and a second PWM pin which controls the speed. Is there a different setup in your code?

    I also wanted to ask about how you set up the speed rate change for the motor. For example, if your loco is stopped and you set the throttle to full speed, how do you set it so the speed climbs slowly instead of just instantly applying full power? Or is that something which is managed by the throttle? And if the loco stops receiving a signal will it slow down to a full stop, or just keep running until it finally receives a new command?
     
  16. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    A classic DC motor or a classic turnout can go in two directions. Clockwise or counterclockwise, left or right, first position or second position, A or B, blue or green ... Left and right are just a way to have a better understanding of what your are coding in your sketch. This is the names i consider the more universal on motor movements... But it applies to all motors, even those who only turn... In a Accessories program, each accessory must be associated to a 'port'. Because there is a lot of ways to bring power and informations to motors or lights... For a LMD18200 driving a motor, the best port will be a PortSpeedDirBrake. A class dedicated to H-Bridges like the LMD18200. The sample is using this kind of port.

    Are you still speaking about Accessories ? Because this library is not a good choice to drive a loco !
     
  17. Shdwdrgn

    Shdwdrgn TrainBoard Member

    42
    14
    4
    I'm speaking of locos... always of locos. I thought you were recommending in your previous post that I use the accessories library to drive a loco? Let me try again...

    I have a base/controller set up already (using DCCppESP32). Now I have a loco with an arduino on it. I want to program the loco's arduino to receive DCC++ commands through the rails. So what arduino software should I use on the loco? Like I said I'm still trying to learn the terminology for DCC, but I *think* I need some kind of decoder on the loco?
     
  18. Simon Mitchell

    Simon Mitchell TrainBoard Member

    97
    97
    4
    Shdwdrgn, you certainly need a decoder on the loco, but if you are going to receive the commands through the rails, you should just go buy a cheap off the shelf decoder.

    You mentioned above that you have an ESP32 in your loco. That suggests to me that you would receive the commands via WiFi. In which case, the sketch you want is buried in my thread http://www.trainboard.com/highball/index.php?threads/dcc-wi-fi-receiver-trackside-or-onboard.99820/. The sketch is loaded on github here https://github.com/SimonME30/DCCpp. You would need to power your ESP32, which you could do via the rails, or via battery power (my choice).

    Here’s the thing though. The ESP32 DCC++ base station per is designed to RECEIVE throttle commands and transmit them ONLY via the rails. You only need that if you will be running trains with conventional decoders, receiving commands and power via the track.

    I designed my onboard decoder to RECEIVE the throttle level commands.

    If you want a WiFi solution, then you need a DCC++ throttle of some sort, and the onboard sketch I developed. You may want some sort of a chat server if you have more than 1 throttle or loco.
     
    Last edited: Jan 13, 2018 at 7:45 PM
  19. Trusty

    Trusty TrainBoard Member

    19
    6
    2
    I got it ! I have'nt understood that you have an Arduino embedded in the loco (did you say that ?), and want to receive loco's speed and functions DCC orders to drive the loco motor. I dont have the right library to do that. Commanders only looks for stationnary decoder orders, and Accessories can drive motors, but i am not sure that this is the best library for a loco... I have no solution for you for the moment... Sorry for the mistake.
     
  20. Shdwdrgn

    Shdwdrgn TrainBoard Member

    42
    14
    4
    @Simon -- Thanks for the link, I'll give your code a try! My understanding is that Atani's DCCppESP32 base station code sends commands both through the rail AND via wifi? I actually do wish to have both, with the idea being that static objects like turnouts and lights could receive their commands through a direct connection from the rails, while the locos would receive via wifi. I know that trying to pick up anything from the rails is a very noisy business, so it seemed like it would be more reliable for the locos to communicate through wifi.

    I plan to eventually have an ESP32 on my loco, but at the moment it is fitted with an ESP8266-12F. It has a nice little converter to provide straight DC at 3.3V and also provide DC track voltage to the motor. The one thing I am still waiting on is a package of optoisolators so I can read DCC from the track, however since your code will read from wifi then maybe I can get something rolling before the chips come. Along with those chips, I am also waiting on orders for some servos and a 16-servo control board, so eventually once everything arrives I will also be working with the 'accessory' code, which Trusty's library is probably perfect for. But at the moment I just want to get a loco running again and see if I can get the whole collection of equipment talking together.

    I did receive one package today... a 16V, 4.5A power supply. I was reading that 18V is actually too much for most HO DCC equipment and 16V seemed to be more appropriate. All of the power converters I've been using are actually rated up to 36V but I do want to try and stay compatible with commercial DCC equipment just in case I ever use any of it (like maybe sound boards). I have a lot of parts on order that will keep me busy learning how DCC works once it arrives, but that could be another month. For now I'll be happy to control my loco. I was previously writing my own (non-DCC) code for the loco, using MQTT and a web page to control speed/direction from my phone, so I know the existing hardware is stable, I just thought it would be better in the long run if I used DCC++ as my base so I don't have to reinvent every little feature.

    @Trusty -- no worries, as I said above I'm sure your library will be great for me to set up the servos to control my turnouts, and once the parts arrive in the mail I will certainly be asking questions again! :)
     

Share This Page