Setting up Turnouts in JMRI

brendanf Jan 9, 2017

  1. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I think I may not have been clear on my intent... I am using DCCppESP32 as my base station, so the signal is already being sent out TO the rails. What I am trying to do is now read that signal back FROM the rails at another spot on the track. That's why I was wondering why two arduinos were needed, I just want a simple accessory decoder that will pick up turnout commands and apply them to the appropriate servos on the PCA9685. Hope that makes more sense?
     
  2. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    86
    6
    Here is a sketch and partial schematic to do what you want. It uses a 6N137 optoisolator to interface to the track. The 22 pF cap across the input of the opto does seem to be required for reliable operation. I have tested operation with 2 PCA9685's and 32 servos run by an Arduino Nano, and it should be easy to expand that to up 64 PCA9685's and 1024 servos, if you have a big enough +5 V supply. The PCA9685 takes care of the timing of the servo pulses, so the Arduino is not strained at all. Use a separate power supply for the servos to avoid electrical noise that could cause problems for the micro. Let me know if you have any questions.
     

    Attached Files:

  3. 9MM-Auto

    9MM-Auto TrainBoard Member

    10
    7
    10
    I know I'm a little late to the party on this thread but I'm looking at using the mega for the main DCC++ controller connected to an UNO R3 for servo operation as well. There was some previous discussion in this thread about possibly permanently changing/updating the base station code to work with this type of setup and I'm wondering if anyone knows of any changes that may have been done to the base station code since that discussion on this thread. The reason I ask is I don't want to make changes to the DCCpp code as the example given by Brendanf if other modifications have already been made. I am fairly new to the wonderful world of arduino and although I've been trying to learn as much about the coding as I can I'm not confident that I could recognize if it has already been modified.
     
  4. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    As far as I know, there have been ZERO changes to the Base Station code since this thread was started. You should be good to go.
     
  5. 9MM-Auto

    9MM-Auto TrainBoard Member

    10
    7
    10
    Thank You for the reply. I made the changes described and have uploaded to the boards. Thank you for the time you spent using your knowledge to make this work and then sharing it.
     
  6. FrenchSR

    FrenchSR New Member

    3
    0
    3
    My apologies also to re-igniting this thread but it appears that the threads involve a number of issues I have. My system initially is an Uno with a L293D (2-way motor & 16-way Server shield). I have happily modified the DCC++ base station sketch to use this shield to control locos both on the main and programming tracks but I'm unable to make the PCA9685 included drive any servos. My system requires 6 servos (controlling turnouts), 8 sensors and 5 signals (2 of which are fixed stop signals). This is a prelude to the main layout which would utilise 50+ turnouts, 80+ sensors and 20+ signals. The latter doesn't phase me providing I can understand the PCA9685 and the 16 I/O boards. I have tried the Adafruit servo test sketch which drives attached servos so I2C works but am unable to drive servos from DCC++ Base Station. Tried any number of address codes. Any help appreiated.
     
  7. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
    Hello Everyone
    I am currently in the process of building my/grand kids layout. It will have approximately 80 + turnouts. I have been able to get one pca 8685 controlling servos thru JMRI and will expand on this to control all of the turnouts. The layout is 25 feet x 20 feet in an E shape. I am using an Arduino Mega for the base station and another Mega instead of an Uno.

    My questions are.
    #1 How long can a shielded cat 5 cable be to transmit the I2C signals from one pca 9685 to another pca 9685 ? I have found in searches that 3 meters is max but would like to know actual length from someone that has done it and what type of cable that was used.

    #2 How long can a cat 3 phone cable that i am using from the pca 9685`s to the servo`s be? I have physically hooked 25 feet up and it worked but there again I would like to know the max from someone that has done it.This measurement will affect question #1`s max length measurement.

    #3 I would also like to put control panels at the 4 power districts that are are going to have the Dave Bodnar high power dcc boosters in them with push buttons to control the various turnouts in that area ,has anyone had success doing this yet? If so would you be kind enough to share your code work for adding push buttons to BrendanF`s code for controlling turnouts with JMRI so that the grand kids will have a physical button to push VS having to control them thru JMRI.

    I have done multiple searches for the push buttons subject and have not found anything of use so far, I don`t want the code written for me I just want to Know were I should start.

    Thanks for any help James
     
    Last edited: Jul 31, 2019
  8. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    Been awhile since I’ve been on here. Lol.

    I’ll try and answer your questions.

    #1. For the I2C data, it was never intended to be run long distances. It should be kept as short as possible. Every setup will behave differently but for me I have only tested it with non shielded wires about 2 feet and hand no issues. Your results may vary though.

    #2. The length of the servo wiring can be substantially longer then the I2C. I have several that are close to 10’ long and have no issues. Again your results may vary. I’m using the same cable and ends that the servos come with and a CAT3 Belsen cable should be fine as it is slightly larger gauge.

    #3. I have not added any push buttons but this is something you could setup easily with JMRI. If you use the push buttons as sensors and use logic within JMRI it can throw/close the switches for you.

    Hope this helps.
     
  9. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
    thanks for the reply brendan

    I have a 25 foot piece of cat 3 phone cable running a servo right now but the longest distance will be somewhere close to 45 feet away from were the pca`s and the base station are right now. So I guess I am going to have to do some testing and see how far I can get before losing signal/control or move my base station etc. closer to the center of the layout which is probably the best solution that way the longest wire would be around 28 feet from pca to the servo.
     
  10. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    Well the other option for such a very long run would be to ditch the CAT3 cable and use a heavier gauge wire for those long runs. It will prevent the voltage drop that would occur otherwise.
     
  11. SP_fan_1951

    SP_fan_1951 TrainBoard Member

    93
    86
    6
    I would suggest adding additional filter caps between the power and ground leads at the servo to reduce noise. Perhaps a 10 uF electrolytic capacitor and a .1 uF ceramic disc capacitor in parallel. The smaller ceramic cap is to compensate for the higher inductance inherent in electrolytic caps, reducing high frequency noise. Another issue you may run into is the inductance of the long run causing ringing of the positioning pulse, and increasing the rise and fall times. Try it, and if you run in to problems, you may need to add some sort of signal conditioning to the pulse signal line, such as a RS422 transmitter and receiver with a twisted pair interconnect.
     
  12. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
    Hello Everyone
    Thanks for the replies and suggestions!
    I have decided to move where my control panel so it will be located closer to the middle of the layout this will make the servo runs to the farthest servo around 30 feet that might be a better solution since I am in the building phase right now.
    Now to the issue I have now is I have 4 of the pca9685`s and can only get 3 of them to move servo`s
    I have ran an I2C scanner on them and have come back with the addresses of 0x40, 0x41, 0x42, 0x43.
    I have editted Brendans sketch to include.

    #define num_servo_boards 4
    uint8_t SERVOADDRS[num_servo_boards]={0x40, 0x41, 0x42, 0x43};

    what else do i need to edit to get them all working
    I have verified that the combinations of 0x40 ,0x41 will work
    0x40,0x42 will work
    0x40,0x43 will work
    0x40,0x41,0x42 will work
    0x40,0x41,0x43 will work
    put all 4 together and I cant get 0x43 to move servo`s 53-68
    0x40 moves servo 5-20
    0x41 moves servo 21-36
    0x42 moves servo 37-52
    0x43 no movement of servo 53-68

    When the layout is fully built I am going to have close to 100 servo`s so I need to understand what changes are needed to Brendan`s sketch so that I can make the changes as pca9685`s, switches and servo`s are added to the layout.

    Thanks for any help with this James
     
    Last edited: Aug 4, 2019
  13. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    Sorry for the delay in getting back to you here.. Life is a little crazy right now..

    Which version of that Turnout Controller are you using? I am pretty sure I know what is wrong.
     
  14. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
    i have ver 2.2 loaded
     
  15. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    Very sorry for the late reply, things have been hectic to say the least. The version you have doesn't have the bug I thought it might..

    Anyway I want you to try something for me, just so we can eliminate JMRI, open the Arduino IDE and run the Serial Monitor. I want you to try giving it the commands manually, since turnouts 53-68 aren't working try:

    <T 53 1> and <T 54 1> then try <T 53 0> and <T 54 0>

    Basically telling it to throw 53 and then 54 and then to open them afterwards.

    If it still doesn't work, I will have to do some more digging. If they do work, then the problem would have to do with JMRI although I am not sure why it would cause that problem.
     
  16. garry2577

    garry2577 TrainBoard Member

    17
    1
    3
    brendanf were



    brendanf
    have you uploaded the sketch for the jmri turnouts.
    i have your Turnout Controller 2.2 but can you send my modified Base Station code please.i really cant get my head round the changes to the base station sketch
     
  17. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
     
  18. jamescoleman1960

    jamescoleman1960 TrainBoard Member

    42
    15
    6
    Well I was going to upload the modified base station code for you but forget my comp crashed since I did it and I need to redo it. I will up-load when I have a chance to re-modify it .
     
  19. garry2577

    garry2577 TrainBoard Member

    17
    1
    3
    i have your Turnout Controller 2.2 but can you send my modified Base Station code please.i really cant get my head round the changes to the base station sketch
     
  20. brendanf

    brendanf TrainBoard Member

    62
    54
    8
    Sorry for the delay. Here you go.

    Extract the .zip and use the entire set of files.
     

    Attached Files:

Share This Page