DCC++ communications and sensor data

Barry Gordon Apr 23, 2020

  1. Barry Gordon

    Barry Gordon TrainBoard Member

    Does any one know if the DCC++ system on the Arduino Mega sends out sensor status asynchronously as it changes, or does it have to be poled for by the device communicating with the DCC++. If it does not communicate sensor data asynchronously has any one done a sketch mod to do that if it is even possible.

    Barry Gordon
  2. tnt23

    tnt23 TrainBoard Member

    Hi Barry,

    I have been playing with DCC++ Command Station directly over Serial line, typing in commands and reading responses using simple Terminal Emulation programs like TeraTerm or Putty. From what I recall, DCC++ Command Station spits out any change in sensor right away, perhaps after a very short delay (fractions of a second).
    Of course, sensors have to be registered with the Command Station with <S> command.

    So it does not have to be polled to get the sensors data, top level software like JMRI just looks for those <Q> and <q> messages.

    Hope that helps.
  3. Barry Gordon

    Barry Gordon TrainBoard Member


    Thanks for the Reply!

    I am writing a little interface proxy for the raspberry Pi that will act as a front end to the DCC++. The proxy will accept TCP/IP commands, and based upon the command, forward it to the DCC++ or act on it within the proxy. This allows me to deal in a very flexible manner with the DCC++ through TCP/IP. The proxy will forward all unsolicited data received from the DCC++ to all connected TCP clients, but will only return a DCC++ reply to a client that issued the command.

    The proxy initializes the communications with the DCC++, and then initializes things like sensors and turnouts.

    I do all my coding these days in javascript, and use Nodejs on the RPi

    Your reply will save me a lot of time and effort
    FlightRisk likes this.
  4. FlightRisk

    FlightRisk TrainBoard Member

    I am one of the folks working on DCC++ and DCC++ EX. The main loop does three things while the DCC signal is generated by interrupt timers:

    Scan and process commands (which also creates the packets)
    Check the motor board status (current, short, etc.)
    Check the sensors

    So while there is a lot going on in those routines, there are literally only 3 lines of code in the repeating loop routine ;)

    It continually updates the sensor readings and will report <Q ID> when the sensor is activated by going from HIGH to LOW and <q ID> (small 'q') when the sensor goes back from LOW to HIGH. You can look at one or both of these depending on what you need to track (trigger, detector, etc.).
  5. Barry Gordon

    Barry Gordon TrainBoard Member


    Thank you for your reply. You are quite correct. the DCC++ does send sensor data asynchronously. Does it send anything else in that manner (asynchronous with no request)?

    Most of my problems had to do with my decision to run the sensors (IR Obstacle detectors) on 3.3 volts. I switched them to 5 volts and all is now working much more reliably.

Share This Page