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

Joey Paul Jan 13, 2019

  1. Joey Paul

    Joey Paul New Member

    7
    0
    1
    Hi Folks,

    My first post here! I am a little successful with Arduino but not yet started DCC++ nor do I have a DCC decoder as yet. I think I understand the DCC++ Arduino and motor shield build, but all I want to do (at first) is hard code in an Arduino sketch a few lines that will do very simple things like just start a loco in one direction at a fixed speed, and stop it later. So I guess that means serial out from one Arduino to serial in on the DCC++ Arduino/motor shield set-up. I learn by examples, so if someone can point me to some simple code examples, I would be able to take it from there, hopefully. I looked at Dave Bodnar's examples, but I cannot pick out just what I need. Perhaps I am missing the forest for the trees, or just naively thinking it's going to be simple.

    So once I receive my new hardware (another uno, a motor shield and a decoder that will handle a 0.5 amp motor), I want to see if I can get the JMRI running from a MAC (I am not a MAC aficionado, but it's a new machine), but later all I want to do is very simple control from an Arduino that may also be running other things, like controlling servos for animation, no computer or Raspberry Pi afterward. (I am not a model railroader but on the fringe of the 3 rail O gauge hobby. An HO decoder will work for some of my unusual projects.)

    Thanks!

    Take care, Joe.
     
    Last edited: Jan 13, 2019
  2. Onizukachan

    Onizukachan TrainBoard Supporter

    503
    459
    13
    I have jmri on a Mac mini (my otherwise dedicated home server mac) , running to my dcc++ system to run a short test track and programming track in front of the tv. I chose to use a mega in case I ever wanted to run it via WiFi from the Mac instead of serial.
    I later decided to do JMRI on a 3b+ PI with a 5” touchscreen as the head, and build another mega based dcc++ for table top railroad duty.

    I am not sure what you mean by running dcc on the Arduino itself, to me the benefit of dcc++ is that it is a low cost way to make JMRI useful without having to spend $200 on a manufacturer control system and adapter.
    I think you will find that the Arduino is marginal on performance for what you have planned to do with it, but I may be wrong! Best of luck.
     
  3. Joey Paul

    Joey Paul New Member

    7
    0
    1
    Thanks for the reply and info! Sorry I wasn't more clear. I just want to control a DCC loco from an Arduino which would send commands by serial to the Arduino that has DCC++ installed with the motor shield on top. So, at first, I'd like to just get a loco to run forward at a fixed speed, then stop when I want, hard-coded in a sketch, serial out to the other Arduino running DCC++. So I know this doesn't seem like it's worth the effort, but it is a beginning for more complex automation later, but not a throttle that I control or JMRI automation, just pre-sets from an Arduino sketch. Similar to what is done in this vid, but not exactly, I guess:



    Take care, Joe.
     
  4. Jimbo20

    Jimbo20 TrainBoard Member

    246
    164
    8
    My setup works in a similar way to your suggestion. I have dcc++ running on an Arduino Nano, then I have an ESP8266-01 serially connected to the Nano. The ESP serves two functions:
    1) It allows Wifi access of a modified Dave Bosnar Throttle.
    2) It runs an automatic railbus shuttle sequence. This is done by sending serial railbus operating commands to DCC++ and monitoring the magnetic sensor data sent back from DCC++. The railbus is brought in to platform 1, there it pauses for a minute or so, then drives away again out of site, pauses again. then a couple of turnouts are automatically thrown, and the railbus comes back in to platform 2. The whole sequence repeats continuously and the controlling code that does this is all on the ESP8266-01. There is no reason why the code couldn't be installed on a second arduino instead of an ESP. The reason I used the ESP is that I wanted its WiFi capabilities to allow wireless manual control of a second loco (and also I can stop/pause the railbus manually if wanted).

    I wrote the code over a year ago. It isn't pretty and developed more by trial and error! A problem is that my hobby is on hold at the moment due to my recent house move and everything is currently still boxed up. I can't wait to get it all out and continue again in the next month or two!

    Here is a video I made of the railbus. Note that it was running completely under the automatic control of the ESP8266-01.



    Jim
     
  5. Joey Paul

    Joey Paul New Member

    7
    0
    1
    Hi Jim,

    Thanks for the reply and info! Great video, too! I can certainly wait until you can share a snippet of your code. No rush for me; I still need to get the hardware together. My coding is never elegant. I judge success by how it works. And you got a perfect result!!!

    (I still haven't fully unpacked from a move 25 years ago!)

    Take care, Joe.
     
  6. Joey Paul

    Joey Paul New Member

    7
    0
    1
    Hi Folks,

    I waiting for the Arduino motor shield and looking at the "<Minimalist Dcc Controller sample>" which is the first sketch that loads when opening the "DCCpp_Uno.ino." Is this sketch controlled buy your computer keyboard and the serial monitor?

    Thanks! Take care, Joe.
     
  7. John W Zerbe

    John W Zerbe TrainBoard Member

    74
    47
    5
    Hello Joey,
    Yes, absent anything else to talk to your new dcc++ controller, you can use the serial monitor in the arduino dev package to type in the commands that dcc++ acts on.
    example: the first one you want to send is "<s>". This tells dcc++ to send you what it knows about its status.

    There are a number of "dcc++ throttle" projects that do exactly what you describe that you want to do with the second arduino. ie your second arduino can connect to the first one via usb and do things like watch for button presses, potentiometer changes, etc and send text strings (dcc++ commands) to the serial interface in response.

    I did a little of this myself when I first build the DCC++ project. I then got a raspberry pi 3b, installed JMRI on it and connected it the arduino. I also have the arduino dev software on the pi as well.

    With the jmri software running I can now control trains from my phone which talks to jmri.
     
  8. Joey Paul

    Joey Paul New Member

    7
    0
    1
    Hi John,

    Thanks for the reply!

    So the base station can receive serial data from either the IDE or another Arduino. So that seems simple enough!

    I am still waiting for my boards from Banggood.

    Take care, Joe
     
  9. Robert Owen

    Robert Owen New Member

    1
    0
    1
    Hi Joe. Did you find code to implement PWM on the track? I am just starting with Arduino and trying to get an engine to go forwards and backwards so I can develop other features from there. The DCC packet structure I understand but am trying to find a sketch that places '0's and '1's onto the track. As I understand a '0' is a 116microsecond square wave and I need a sketch to command a motor shield to produce this.
     

Share This Page