Simple Code Example -- Arduino to DCC++ Arduino ???

Joey Paul Jan 13, 2019

  1. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Well done Joe! I hadn't realised you were stuck like that. The video I posted above (#4) shows my railbus running automatically, using serial command codes sent to the basestation arduino rather like your code does. But as well as having delays, it waits until hall effect sensors at various places detect where the railbus is along the track, so it can speed up or slow down and stop etc.
     
    Joey Paul likes this.
  2. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Folks,

    Just a short video of the project:



    Thanks, Everyone, for the support!!!

    Take care, Joe.

    Code:
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
    
      Serial.print("<1>"); // turns track power on
      delay(10000); //delays 10 seconds
      Serial.print("<t 1 03 126 1>"); // loco #3, 126 speed fastest (0-126 possible) the last "1" is for forward
      delay(10000);
      Serial.print("<t 1 03 16 1>");  // speed 16 slow
      delay(10000);
      Serial.print("<t 1 03 70 1>");  // speed 70  medium
      delay(10000);
      Serial.print("<t 1 03 0 1>");  // speed zero
      delay(1000);  // delays 1 second
      Serial.print("<t 1 03 70 0>"); // the last "0" for reverse
      delay(10000); // delays 10 seconds
      Serial.print("<t 1 03 0 1>"); // speed zero
      delay(1000);
      Serial.print("<t 1 03 70 1>"); // back to forward
      delay(10000);  
      Serial.print("<t 1 03 0 1>"); // speed zero
      Serial.print("<0>"); // track power off
      delay(10000); // delays 10 seconds
    
    }
    
     
    KC Smith and Sumner like this.
  3. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    Ok I admit I wasn't getting it, but seeing your code and video now I totally do. You basically now dont need an interface or computer/jmri.

    You are using it for control (issueing the serial commands) and automation rather than creating DCC packets (which the DCC++ basestation does)

    Totally get it rather than learning scripts in python/jmri this could indeed be much simpler on a smaller layout for sure.
     
  4. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Have you guys seen these position sensors from Geoff Bunza? Ultra small and cheap. Someone is making these assembled, but ordering the boards and parts in quantities of 3 (minimum circuit board order) is a great option if you want to solder.

    https://model-railroad-hobbyist.com/node/26133
     
    Last edited: Mar 29, 2020
  5. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    One of the attractions of writing my own DCC software is that I can do away with using expensive DCC controllers to manage points etc. Spending that much money when all I want to do is control a level crossing is ludicrous. There are far cheaper, non-DCC, Arduino based solutions that I can use.
     
  6. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    This YouTube video was listed in an earlier post. Has anybody got it to work as there appears to be errors in the code? When I get it to work I will post my Arduino sketch.

     
  7. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Folks,

    So I have used this free Android remote control app https://www.roboremo.com and I just discovered that I can just use the DCC++ commands like "<t 1 03 70 1>" from any of the 5 free buttons with the HC-06 Bluetooth module. However, you have to change the baud rate to 115200 on the HC-06 since DCC++ uses 115200. After that, just connect power and Bluetooth TX to RX on the base station. So, all you need is the app, base station, and the Bluetooth module. There is a paid version of that app, but I've never done that it. So not like a full throttle, but a start. Changing the baud rate on the HC-06 took me a while to troubleshoot. I followed this:

    Hope this can help someone.
    Take care, Joe.
     
    Last edited: Mar 29, 2020
  8. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    I downloaded DCC++ to my Arduino Uno and would like to test it running a train. I only have one Arduino and no Pi's, unable to buy extras because of the shutdown. I need to control the train directly from the IDE serial monitor, can you let me know what commands I enter on the serial monitor? Is it the same as what Joe gave a couple of days ago but entered manually? Does not work for me.

    Serial.print("<1>"); // turns track power on
    Serial.print("<t 1 03 126 1>"); // loco #3, 126 speed fastest (0-126 possible) the last "1" is for forward
    Serial.print("<t 1 03 16 1>"); // speed 16 slow
     
  9. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Robert,
    Do you have the baud rate of the serial monitor set to 115200? What motor shield are you using?
    Hope this helps!
    Take care, Joe.

    (edit)
    P.S. Yes, the commands are the same, just remove the quotation marks. J.
     
    Last edited: Mar 30, 2020
  10. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Robert,
    I followed this video to the from 1:52 to the 13:35 mark. Found it very helpful!


    Joe.
     
  11. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    yes and in my opinon an even better option linked below as you can control setting and sensitivity through software rather than hardware pieces.

    http://trainelectronics.com/Crossing_Signal_sensor/DifferentialDetector/ Arduino on bottom of page. I have done this on a ATTiny85 as well once I tested it on an UNO. TIny program so can go on any version (UNo, nan, micro, attiny, etc)
     
  12. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Keith,

    Thanks, good info there!

    Take care, Joe.
     
  13. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    Thanks Joey. Bit late for me to think about this tonight, I probably left the quotation marks in. I am using an Arduino motor shield, and the baud rate is set to 115200.
    Let you know in the morning.
     
  14. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Have you tried it on a small esp9266 board and had it communicate to the base station with wifi? ;)
     
  15. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
  16. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Jimbo20, somehow I missed you comment. I often don't see the forest for the trees! Take care, Joe
     
  17. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Keith,

    I know BASIC Plus, never learned Python, getting better with Arduino code. I am most fond of the Picaxe since it's like the old Timex/Sinclair 1000's BASIC code. I used to use an I/O board with the T/S1000. Loved it.

    Take care, Joe.
     
  18. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    Thanks Joe.
     
  19. Joey Paul

    Joey Paul TrainBoard Member

    34
    11
    3
    Hi Robert, Is it working?

    Take care, Joe.
     
  20. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    The commands seem to work just looking at the lights on the Arduino, the train does not move though. The DCC decoder in my train I am not sure if it is working, I have not run it before. With the shops shut there is not much I can do. I have a spare DCC decoder that will not fit into my train that I will test on my bench when I get time.

    How is your setup going?
     

Share This Page