Turnout feedback to JMRI

OzLodger May 1, 2020

  1. OzLodger

    OzLodger TrainBoard Member

    11
    4
    4
    Hi All,
    I've recently done a bit of tweaking to Gregg's excellent DCC++ code and have modified the Accessories handling routine for my own nefarious purposes. I've got it to the point where I can reliably send accessory/turnout commands via the I2C buss to a separately tasked Accessory Arduino instead of having to throw it into the track buss. All the physical changes to turnouts - in my case via servos - is handled by the slave Arduino rather than the DCC++ Base Station. I'm using JMRI to send the commands to the Base Station. Then the Base Station passes them to the slave.

    The issue I have is with feedback from the accessory. I haven't been able to find out a lot of detail about what JMRI is actually monitoring in that regard. Everything's fine if the turnout is thrown correctly. But - just looking at handling any potential glitches - I'm searching for ways to report back on the following sort of scenario:

    If, say, an apparently valid servo became unplugged, I can still unknowingly send a command to "Throw" it in JMRI. My code at the slave identifies that the servo is not attached and sends an error byte back through I2C to the DCC++ Base station. But JMRI still thinks the turnout's been "thrown". So far, I haven't been able to work out how to pass the info back to JMRI to update the on-screen display so it shows as still "closed".

    I know that, if entering a manual command via Serial to the Base Station, the Serial Monitor can report a "<X>" for other failed commands. But although I can do that with my routine, it doesn't seem to get detected by JMRI.

    I'd be grateful for any ideas on how to solve this. And does anyone have any detailed info on how "BSTURNOUT" and "BSOUTPUT" actually detect feedback?

    Regards,

    Geoff
     
  2. OzLodger

    OzLodger TrainBoard Member

    11
    4
    4
    Thanks to those who read my initial post. Over the weekend I did some more investigating and realized that the solution was easier than I first thought. The main issue was I just needed to move the point where my I2C code cuts in on Gregg's. Then, if it detected an error back from the I2C slave, pull a designated (spare) error pin LOW. Check the error pin and, if LOW, simply bypass saving to EEPROM and instead, load a serial command to reverse the original. JMRI - which had already updated its settings based on the initial command - picks up the reversal and re-sets its record for the missing turnout/servo to the prior state. The turnout feedback needs to be "BSTURNOUT" - which appears to just be JMRI reading the serial output sent by DCC++. I expect BSOUTPUT works the same. The "<X>"s that I had initially been sending didn't make sense to JMRI.

    I noticed in reading some old posts that Gregg had investigated using I2C back in the day and found problems with it. I'm using a MEGA and so far, so good, even though I'm only in Test with 1 servo attached. Might be a different story once I get operational!

    Any how, this probably all of not much interest to most of you. But at least to me it seems like I2C for accessories is feasible.

    Happy training all!

    G
     
    KC Smith likes this.
  3. Pieter

    Pieter TrainBoard Member

    152
    46
    10
  4. OzLodger

    OzLodger TrainBoard Member

    11
    4
    4
    Thanks Pieter, I'll check it out.
     

Share This Page