Automatic Lok Trottle with DCC++EX

Michael Rupprecht Mar 17, 2021

  1. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    For a very simple track I wanted to implement a simple automatic steering of the loc, but with automatically controlled playing of sounds, speed and light. Using e.g. JMRI with additional PC or RP would have been a kind of overkill for what I need. Here is the simple solution, and I hope some people find that a useful add-on.

    I am using a DCC++EX control station and additionally I connect an ESP8266 to the serial port. But it is connected to TX0/RX0 and not to one of the additional serial ports on the Arduino Mega. Then I do not get a Wifi port for a manual controller, but I can issue all steering commands from a programm running in the ESP8266.

    Simple Programm looks like this (I made the example a bit shorter):

    void setup() {

    Serial.begin(115200);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
    }

    void loop() {

    // Track Power on
    Serial.println("<1>");
    delay (50);
    // light inside
    Serial.println("<F 11 7 1>");
    delay (4000);
    // engine start
    Serial.println("<F 11 5 1>");
    //Light front and back
    Serial.println("<F 11 0 1>");
    delay (46000);
    //1. announcement
    Serial.println("<F 11 4 1>");
    delay (15000);
    // 2. announcement
    Serial.println("<F 11 9 1>");
    delay (9000);
    //depart
    Serial.println("<t 1 11 3 1>");
    delay (1000);
    Serial.println("<t 1 11 6 1>");
    delay (1000);
    Serial.println("<t 1 11 9 1>");
    delay (1000);
    Serial.println("<t 1 11 15 1>");
    delay (1000);
    Serial.println("<t 1 11 30 1>");
    delay (2000);
    Serial.println("<t 1 11 45 1>");
    delay (2000);
    Serial.println("<t 1 11 90 1>");
    delay (50000);
    // arrival in station
    Serial.println("<F 11 3 0>");
    delay (1000);
    Serial.println("<t 1 11 0 1>");
    delay (8000);
    // Light off
    Serial.println("<F 11 0 0>");
    delay (5000);
    //Engine off
    Serial.println("<F 11 5 0>");
    delay (6000);
    // Track power off
    Serial.println("<0>");
    }

    Next step will be to integrate a simple Web-server to allow some manual intervention, but very limited steering over a web Page.
     
  2. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    You can still have 2 or 3 serial ports so anything like JMRI or DCCpp CAB that send <DCC++> commands will work.

    You need to create a second instance of the command parser, set the baud rate and call it's loop function in loop().

    So look in CommandStation-Ex.ino and double up on all the Serial lines. Throttle wifi can be Serial1, so we will start with 2:

    DCCEXParser serialParser; // existing
    DCCEXParser serial2Parser; // add

    Serial.begin(115200);
    Serial2.begin(115200);

    serialParser.loop(Serial);
    serial2Parser.loop(Serial2);

    Know that command responses will go back to the serial that sent them... but diagnostic messages ONLY get sent to Serial (USB or tx/rx)

    As for automation, we will be releasing EX-RAIL (tentative name), an automation scripting language to make it easy to do what you are doing for everything on a layout. Triggering sounds too.

    Fred
    DCC-EX
     
  3. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Oh, we also will be releasing an MQTT system. That may be something you would be interested in.
     
  4. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    Hi Fred,

    thanks for the hint with the additional serial line .... I was hopeing it will come someday..... it is already available - GREAT.

    I have seen that you are also planning something like a scripting language ... but I was not patient enough. I will test it as soon as something is available.

    Same for the MQTT.

    BTW: I have a first version of a WebTrottle on an ESP8266 already running. I will put it on Github as soon as it is a bit more mature .... and when I have EX-Rail integrated ....
     
  5. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Great! We look forward to seeing anything you want to share.
     
  6. Sumner

    Sumner TrainBoard Member

    2,836
    5,970
    63
    Hopefully I make this understandable.

    I have the parts to build Dave B's wireless throttle which uses the RX on the Arduino. I also have JMRI connected using a phone throttle. I believe that it also uses the same Rx via the USB cable. It has been posted that they both work at the same time but it also appears that it might not be the best situation.

    If I'm reading your post right it appears now there would be the option to setup a second serial port and use Dave's wireless throttle on it after rewriting his sketch to some degree and connecting the wireless receiver to a different set of pins. If that is the case I will try and dive in deeper to try that out. If it isn't the case I'll just build the throttle and see how the throttle and JMRI coexist.

    Thanks,

    Sumner
     
  7. IronMan1963

    IronMan1963 TrainBoard Member

    161
    173
    9
    Sumner. As you said, It may not be the best solution but mine is still running with a Raspberry Pi 3b+ running an earlier Steve Todd image DCC++ classic on an Uno clone with a Deek Robot motor shield and Dave Bodnar's throttle. I also loaded Steve's image to a Raspberry Zero W. It also worked, but had a bit to much lag running on the Zero.
    Later Richard
     
    Sumner likes this.
  8. Sumner

    Sumner TrainBoard Member

    2,836
    5,970
    63
    Thanks Richard, I still need to take the time to put the throttle together and try it out. Are you running Gregg's original DCC++ or the newer DCC++ Classic the guys have worked on?

    Have you also tried DCC++EX on the Uno. That is what I have on mine now and also putting it on a Mega,

    Sumner
     
  9. IronMan1963

    IronMan1963 TrainBoard Member

    161
    173
    9
    I have run both Gregg's original and the Classic. Presently have the new DCC++ Classic up and running. Loaded on a Mega and an UNO. Did a DCC++ Classic class for my local NMRA virtual meeting a few months back. Looking at the DCC++EX have a couple UNOs and a Mega not being used so will load it on them and try it out. Need to get Dave's booster built. Have the parts just need to set up the camera and document the build for another class.
    Later Richard
     
    Sumner likes this.
  10. Sumner

    Sumner TrainBoard Member

    2,836
    5,970
    63
    Hope you put that video up. I also have the parts but did buy a Tam Valley booster but would still like to put Dave's together also. Did you do a video on the hand throttle?

    Sumner
     
  11. IronMan1963

    IronMan1963 TrainBoard Member

    161
    173
    9
    No just did a PowerPoint on the DCC++ build. Not a bad Idea though. I could do rehash of the throttle build. The classes are all going toward my NMRA Author AP. I did 1 on making your own static grass also. Hope to get my MMR certificate eventually.
    Later Richard
     
    Sumner likes this.
  12. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    well .... you area little bit off-topic, aren`t you ;).

    I can add here only something for DCC++EX. I am only using DCC++Ex on Arduino Mega with a ESP8266 connected to TX0 and RX0. According to my experience you can not use the USB port and at the same time some direct serial connection using TX0 and RX0. Then USB connection to Arduino fails. However the serial connection between ESP8266 and Arduino works no matter what you do with USB. Therefore, so far I remove the jumper cables for the TX0 and RX0 when using USB. But a usage of e.g. JRMI via USB and some trottle connected to TX0 and RX0 can not work at the same time. What Fred proposed is a solution to the problem.

    Unfortunatly it does not solve the issue completely. On the ESP8266 there is only one serial port. Therefore, I still have to remove the jumper cables when I want to upload new software to ESP8266 :(. So I either live with the fact that I currently remove them 20 times a day and put them back to continue testing ....or I finally try out the software based serial port on ESP8266 .....which is a bit slow.
     
  13. rcmodeler

    rcmodeler TrainBoard Member

    47
    40
    7
    Don't know which ESP8266 you are using but all mine have more then one serial port.
    https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

    I use Wemos D1 mini for mqtt communication with DCC++ EX.
    D4 on Wemos (GPIO2) is Tx1 and that I connect to Rx0 on the Mega.
    Thus I can use the USB-port on the Wemos for uploading and monitoring.
     
    Michael Rupprecht likes this.
  14. IronMan1963

    IronMan1963 TrainBoard Member

    161
    173
    9
    My Bad. Didn't mean to side track/Hijack the thread.. Consider me admonished.:( LOL
    Later Richard
     
    Sumner likes this.
  15. Sumner

    Sumner TrainBoard Member

    2,836
    5,970
    63
    Sorry about that. I kind of get in the habit of thinking that forum talk can be like sitting around drinking coffee or a beer with friends and the conversation can drift off topic :unsure:.


    How about a double pole toggle switch in the circuit to the pins to connect or disconnect?

    Sumner
     
  16. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    oh ..... I am using Wemos D1 mini as well ... and even in your reference it does not mention TX1/RX1 for the Wemos D1 mini .... on the other hand they are using anyway just other GPIOs .... I thought there is some special HW support behind TX0/RX0 .... I found somewhere a hint to a "software based" serial port but the hint said it only supports 300 baud .... which might be enough anyhow. Do you have a code example how you use the second serial port? Do you know something about the speed of the serial port?

    Well ..yes, that would work... I always used to think it is the last time I need to switch. But I guess I go for using the second serial port on ESP8266 .....once I have worked out: how?
     
    Last edited: Mar 24, 2021
  17. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    Don't worry .... was just an attempt to get back the conversation with friends to the topic I am currently interested in ;).
     
  18. rcmodeler

    rcmodeler TrainBoard Member

    47
    40
    7
    If you focus on GPIO numbers it may be easier to compare different boards equipped with ESP8266.
    As I mentioned, GPIO2 is Tx1 (D4 on Wemos D1 mini). Wemos D1 mini does not have Rx1.

    You use Tx1 in the same way as Tx0.
    In "Setup":
    Serial.begin(115200); // start serial communication Rx0/Tx0
    Serial1.begin(115200); // D4 TX1 transmit only

    And elsewhere in your program:
    Serial.println(string); // debugging/monitoring
    Serial1.print(stringToDCC); // send via Tx1/D4 to dcc++master Rx

    It's very easy.
     
  19. Michael Rupprecht

    Michael Rupprecht TrainBoard Member

    13
    5
    4
    Thanks a lot ...can not try it immediatly, but I will try it out ....
     

Share This Page