DIY Model Railway Colour Light Signals Controlled by JMRI

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 มิ.ย. 2024
  • A step by step guide on how to setup the electronics for a 4 aspect colour light signal using an Ardunio and a PCA9685 servo driver board which we can then control using JRMI.
    Once set up in JRMI they're ready to be used in automation as we saw before with the semaphore signals.
    This would work for any number of aspects on your signals and can also include feathers and calling on lights.
    Using this method we can also reduce the brightness of the LEDs and introduce realistic fading.
    There are some limitations which I cover at the end.
    This doesn't cover the physical construction of the signal, only the electronics, but once you've got the electronics setup then I'm sure they could either be fitted to a check plastic signal or you could 3D print something bespoke.
    The main setup is the same as in the servo driver video which can be found here: • Servo Motor Control fo...
    If you want to chain multiple PCA9685s together to give loads more pins then check this video out: • Linking Multiple PCA96...
    Link to the sketch in GitHub: github.com/LittleWicketRailwa...
    Ebay and Amazon Affiliate Links
    (Full disclosure, as an Amazon Associate and Ebay partner I earn from qualifying purchases through these links and this helps to support the channel)
    Arduino Uno:
    amzn.to/2ODZoTO
    ebay.us/HYHkvP
    Servo Driver Board (PCA9685):
    amzn.to/2NoTKo3
    ebay.us/rVpaAJ
    LEDs:
    amzn.to/3rSViFz
    ebay.us/4EOXLX
    Variable Voltage Power Supply:
    amzn.to/3b4wtj9
    26AWG Servo Cable:
    amzn.to/3daEp55
    ebay.us/L1q3FE
    Crimping Tool:
    amzn.to/3tRJXHE
    ebay.us/XE2Dxl
    Jumper Wires:
    amzn.to/2N574Os
    ebay.us/Ujpvxn
    00:00 Introduction
    01:21 Step 1 - Connect LEDs to PCA9685
    03:50 Step 2 - Modify and Upload Arduino Sketch
    06:02 Step 3 - Create Signal in JMRI
    11:11 Other Considerations
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 64

  • @profhbtm
    @profhbtm 2 ปีที่แล้ว +1

    Another winner…addressing the very tricks I’m wanting to learn…Hugh thanks!

  • @marklittlejohn1457
    @marklittlejohn1457 ปีที่แล้ว +1

    Thankyou for the tips Rob and the video

  • @jamessutton9319
    @jamessutton9319 3 ปีที่แล้ว +1

    Learning a lot here. Keep up the great work and thanks.

  • @sophiehandy3285
    @sophiehandy3285 3 ปีที่แล้ว +1

    Very Informative, thank you Rob! 👍

  • @AlanReynoldsBucklandJunction
    @AlanReynoldsBucklandJunction 3 ปีที่แล้ว +1

    As a mature rail modeller who works with DC. This is far above my head. But hope my Grandson will understand and help me. Regards Alan at "Buckland Junction" :o)

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Thanks Alan. Sounds like a team project at Buckland Junction. Let me know how you get on.

  • @nick_thompson
    @nick_thompson 9 หลายเดือนก่อน

    much easier here is to just use grnd from the first set of pins on the PCA9685 as a common ground for all 3 leds, saves 2 wires from being needed and works perfectly well for this use case :)

  • @wrrail4428
    @wrrail4428 3 ปีที่แล้ว +1

    Thank you, your channel has made a big difference to my modelling.

  • @MalcolmCrabbe
    @MalcolmCrabbe 3 ปีที่แล้ว

    Great tutorial.

  • @oceancity1042
    @oceancity1042 3 ปีที่แล้ว +1

    One of the best channels - thank you
    Regards Robert

  • @ar_railwayvideos8805
    @ar_railwayvideos8805 3 ปีที่แล้ว

    Hi Rob, really enjoyed watching your series on servos using the servo driver board and this video - now doing something similar for my layout. Wondered also if the same can (easily) be done using perhaps a 74HC595 shift register mounted on a powered PCB without having to have have an Arduino always attached to the layout?

  • @GUSTAVOSILVA-dk6jo
    @GUSTAVOSILVA-dk6jo 3 ปีที่แล้ว +1

    Wow Rob, really cool stuff and far more understandable than many of the tutorials available on TH-cam about the same matters. Amazingly well done and your vocation is clearly on the instructor/teacher side.
    I have managed to get a pair of servos slow working on a module out of your tutorials and now my question is would it be possible to have these colour signals working alongside servos on the same PCA9685 board? Have you tried it? I haven't tried it yet, but eventually you did.
    Regards and keep up with the amazing work you are doing

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Thanks Gustavo, very much appreciated!
      I didn't actually try running both off the same board, but in theory you should be able to run servos and lights off the same PCA9685. Just remember that the servos need a frequency of 50Hz, but you might find that this causes your LEDs to strobe or flicker. A frequency above 100Hz should stop the flickering, but then you would need to have them on a separate board away from the servos.
      I did this video to prove to someone that it was possible to control LEDs using the same method. However, I think there is a better way of controlling LEDs. I've been introduced to addressable LEDs (google NeoPixels) and they effectively have their own little version of a PCA9685 for each LED. It's another project that's on the long list of projects.

    • @drnutsert
      @drnutsert 3 ปีที่แล้ว

      Hi Gustavo I’m still struggling with servo speeds can you explain or put the sketch on line for how to do this , many thanks Derek

  • @michaelmatsumura422
    @michaelmatsumura422 2 ปีที่แล้ว

    Let me begin by thanking you for your previous videos! I have followed your DCC++ video and the servo videos with no problems. This video has had me being stumped for the last two weeks or so. I'm a true newbie with 3 months or so of learning via TH-cam. I have had no luck getting this project to work and need all the help you can provide. Following this video you've been using a different Arduino and PCA9685 than the one used in the servo series. Is that correct or should I connect these LED's to the PCA9685 used for servos? Please HELP!

  • @lfsrailroadmodeling2329
    @lfsrailroadmodeling2329 3 ปีที่แล้ว +2

    Is there a bigger board we could run the leds on? Like would the sensor board for the mega be able to run the leds. Or os daisy chaining like the servo boards better?

  • @iannelson6323
    @iannelson6323 3 ปีที่แล้ว

    Another excellent video very well put together and presented.
    Everything works up to the point I need to add a mast. i.e. I can create the Heads and the lights come on and off when controlled from the signal head window.
    I am trying to add a 2 aspect distant signal mast - there is not one under BR2003-WE described as "individual aspects" and the other 2 aspect ones do not work. Please help!! Which one should I use? Can more types be download from somewhere?
    Thanks for your time.

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Hi Ian,
      I'll need to take a look at this as I don't know the answer off the top of my head. I don't think it's possible to download different types of masts.
      A really good place for information like this and problem solving is groups.io/g/jmriusers. The guys who develop JMRI are on there and most questions have been asked somewhere.
      I think the theory is that you create your signal heads and then these feed into the signal masts. Although I know it's possible to create signal masts without using signal heads. There is sometimes a bit of a clash between Simple Signal Logic (SSL) and Signal Mast Logic (SML). JMRI has largely been developed with US railroads in mind I think, so you might find that you have to be a bit clever when setting up masts around points for UK based railways.

  • @redwoodcityintheuknscalera7179
    @redwoodcityintheuknscalera7179 3 หลายเดือนก่อน +1

    if you have common anode led signals this will not work with them

  • @sidneychan475
    @sidneychan475 2 ปีที่แล้ว +1

    Hello Rob, good tutorial. Would you please show us how to use "MOSFET" and the wiring method in that case? Thank you very much!

    • @LittleWicketRailway
      @LittleWicketRailway  2 ปีที่แล้ว

      Hi Sidney 👋 MOSFETs briefly feature in this video - th-cam.com/video/CUWFqFmO1Ng/w-d-xo.html
      Hopefully that'll give you an idea on how they can be used with Arduino 👍

  • @johnfrankforther8162
    @johnfrankforther8162 2 ปีที่แล้ว

    Greal turtorials. Can you use the Arduino and JMRI to change the lights and the servo automatically at the same time?

  • @martincole8639
    @martincole8639 3 ปีที่แล้ว +1

    Thanks again Rob for these informative videos. I have a simple question to ask. I am thinking that to ease cable routing on my layout that I would have two pairs of PCA9685 boards. The first in the pair would be operating the servos for the points and the second for the associated lights. How do I set up each board in JMRI/CMRI? I may also want to use some of the I/O pins on the Sensor shield. I know I need address each board but would this be like; 1001....1101....1201....and 1301 and what happens to the addresses for the output pins on the shield? I'm nearly there but your help would be appreciated.
    Cheers Martin

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Hi Martin
      Each Ardunio is a node in CMRI, so if you're having two ardunios each with two PCA9685s then you'll need to setup each Ardunio as a node by changing the CMRI address line (_#define CMRI_ADDR 1 //CMRI node address in JMRI_
      The you'll need to setup two PCA9685s within each sketch (see video th-cam.com/video/v1f_EDHV390/w-d-xo.html). Make sure you solder the jumper closed on the second board.
      It's up to you which addresses in JMRI you assign to the servos and lights. For example, on node 1 you could use 1001-1016 for servos and 1017-1032 for lights, which correspond to bits 0-15 and 16-31 on node 1. On node 2 you could use 2001-2016 for servos and 2017-2032 for lights, corresponding to bits 0-15 and 16-31on node 2.
      Use the cmri.get_bit(i) code to find out if the servo is thrown/closed or the light is on/off in JMRI. So as an example, your first light is connected to the first position (marked 0) on the 2nd PCA9685 which you've setup as pwm2. You've created this light in JMRI with address 1017. To find out if the light is on or off in JMRI use the code
      _cmri.get_bit(16)_
      then store this in a table for the loop code to check. Within the loop you can then send the correct value to the light using the code below which is communicating with PCA9685 board 2 (pwm2) and connection 0.
      _pwm2 .writeMicroseconds( _*_0_*_ , VALUE TO SEND TO LIGHT);_
      You'll need to update the code loop for throwing/closing the servos or turning lights on/off and make sure it's referencing the correct bit in the table.
      Also, check out the series on using Ardunio, CMRI and JMRI together (th-cam.com/video/OkXG3mfY6PE/w-d-xo.html). I think this might be of interest. You can have servo, inputs and outputs all running off the same device. I'm in the process of making part three which also might be of interest. Rather than having one big CMRI node that does everything at one central location with tons of wiring, I'm effectively setting up a CMRI bus wire. CMRI nodes around the layout then connect to the CMRI bus. So if you had a long layout you could have multiple Ardunios each controlling a handful of sensors, servos and outputs each. Saves on wiring and speeds things up a bit since the processing power is shared out.

  • @seasea3273
    @seasea3273 2 ปีที่แล้ว

    How do you handle common positive signals? Most of the commercially available signals in the US have one positive and individual grounds. Thanks!

  • @ps4btccfanleague596
    @ps4btccfanleague596 3 ปีที่แล้ว +1

    This is awesome. However i have just finished your video on multiple servos (using on a lego layout) using a powered ardunio and board.
    However how would i combine servo control, sensor control and LED control onto one board?. I do have the sensor shield as well.

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Check out my most recent series on JMRI, CMRI and Arduinos. It shows you how you can have servos (or lights), outputs and sensors on the same Arduino with a sensor shield th-cam.com/video/OkXG3mfY6PE/w-d-xo.html

    • @emmcommentary1900
      @emmcommentary1900 3 ปีที่แล้ว

      Thanks mate. I lights i have are signal lights from trixbrix but will give it ago and see what happens. Thanks again.
      I have some great ideas to use on my lego layout. Want to try and get train crossing barriers working.
      By any chance did you do a lego series a few years back?

  • @rccrawlervenezuela
    @rccrawlervenezuela 2 ปีที่แล้ว +1

    Hi, Your videos are excellent, I have been able to advance in most of them, now watching this video, would it be possible to make this same signal, only with the Sensor Hub + Your Sketch CMRI?

    • @rccrawlervenezuela
      @rccrawlervenezuela 2 ปีที่แล้ว +1

      Done... working fine Sensor Hub + Your Sketch CMRI + this steps associate Light to Turnout Controller

    • @LittleWicketRailway
      @LittleWicketRailway  2 ปีที่แล้ว +1

      That didn't take long! 👍

    • @rccrawlervenezuela
      @rccrawlervenezuela 2 ปีที่แล้ว +1

      jajajaj It becomes easier when you understand better how to cross the signals between the input and output. , the power of the Arduino Mega + Sensor Hub + JMRI + CMRI is incredible, I will spend a very entertaining weekend preparing the signals and better understanding the work of all those components.
      Your videos were very helpful, very didactic and with good explanatory details. @@LittleWicketRailway

  • @brendanhannon1577
    @brendanhannon1577 3 ปีที่แล้ว +1

    Hi Robert, another great video, thank you. If it is of any help I was able to connect my leds directly to the PCA9685 by using female connectors and, therefore, did not need the breadboard which makes it simpler I think.

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      That does sound simpler, good idea!

    • @nugrohosetiabudi2783
      @nugrohosetiabudi2783 3 ปีที่แล้ว

      Hello Brendan.....I still do not know how to set up for more than 3 PCA9685......Do you know? the max is 3 PCA9685 for this, CMRI cmri(CMRI_ADDR , 24, 48, bus);

    • @nugrohosetiabudi2783
      @nugrohosetiabudi2783 3 ปีที่แล้ว +1

      @@LittleWicketRailway Hi Rob, another good video.....,any idea for more than 3 PCA9685? thanks

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      @@nugrohosetiabudi2783 I believe you can chain up to 62 boards together. You just need to address each board using the jumpers, add a line with the board address at the top of the script, set the frequency for each board and then change the number of servos variable so that the loops knows how many connections it needs to work through.

  • @stephengibson1106
    @stephengibson1106 3 ปีที่แล้ว +1

    Hi Rob
    I have managed to set up three servos for points using your excellent videos.
    I would like to change the speed of the servos and noted you had put a loop in this sketch at the end of the video.
    Unfortunately I am having trouble making out what it reads, could you possibly put the text file up so I can copy and paste it into my servo sketch please.
    I have just ordered a mega, sensor shield and sensors so will be following that tutorial and hopefully make that work too.
    Keep up the good work.
    Thanks

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว +2

      Hi Stephen,
      Long reply, but hope this helps. Example code at bottom.
      So the original code for changing the turnout position looked like this:
      Status[i] = (cmri.get_bit(i));
      if (Status[i] == 1){
      pwm1.writeMicroseconds(i, Throw[i]);
      }
      else {
      pwm1.writeMicroseconds(i, Close[i]);
      }
      It is constantly looping through and checking if JMRI has the turnout as thrown or closed. Each time the code is run it is sending a signal to the servo to move to either the thrown or closed position that you've defined. If JMRI changes then the servo will move as fast as it can from the old to the new position.
      To introduce a slow movement we want to force the servo to stop very briefly at positions between the thrown and closed positions. So if closed was 1000 and thrown was 1800 then we might want to the servo to start at 1000, then go to 1010, then 1020, 1030, etc. until it reached 1800. The process of stopping at the intermediate positions gives the illusion of a slower motion.
      So you need to put a loop of code in to force these little steps and to do this we'll replace this line:
      pwm1.writeMicroseconds(i, Throw[i]);
      with this line:
      for (int j = Close[i]; j = Close[i]; j=j-10) {
      pwm.writeMicroseconds(i, j);
      }
      So again, j starts at 1800 and the code checks to see if it's less than or equal to 1000 and keeps taking 10 off until it is. If the turnout is still moving too fast then you can introduce a delay after the pwm.writeMicrosendonds command, such as:
      delay(10);
      This will delay each step of the loop by 10 milliseconds.
      You need to be consistent with your thrown/closed values for this to work, i.e. your closed values must always be lower than your thrown values or vice versa. If you need them the other way round for a single servo then you'll either need to reverse the physical position of the servo or invert it in JMRI (easier option).
      The other important change you need to make is to make the code only change the position of the servo when a change is required. The old code is constantly sending the position to the servo even if no change has taken place. This is why you need to create the following table to hold the previous status of the turnout:
      int PreviousStatus[numServos];
      Then rather than send the position of the turnout each time, we want the code to check if a change has taken place using this code:
      if (Status[i] != PreviousStatus[i]){
      And at the end update the previous status to be the current status:
      PreviousStatus[i]=Status[i];
      So using a single PCA9685 with a single servo on position zero the full example code would look like this:
      #include
      #include
      #include
      #include
      #define CMRI_ADDR 1
      #define DE_PIN 2
      #define numServos 1 //The number of servos connected
      Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); //setup the board address 0
      Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
      CMRI cmri(CMRI_ADDR, 24, 48, bus);
      int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
      int PreviousStatus[numServos]; //THIS IS THE NEW TABLE TO HOLD THE PREVIOUS POSITION TO CHECK AGAINST
      int Throw[numServos]; //Create a table to hold the throw value for each servo
      int Close[numServos]; //Create a table to hold the close value for each servo
      void setup() {
      Serial.begin(9600);
      bus.begin(9600);
      pwm.begin();
      pwm.setPWMFreq(50); // This is the maximum PWM frequency
      //Position 0
      Throw[0] = 1800;
      Close[0] = 1000;
      }
      void loop(){
      cmri.process();
      for (int i = 0; i < numServos; i++) {
      Status[i] = (cmri.get_bit(i));
      if (Status[i] != PreviousStatus[i]){
      if (Status[i] == 1){
      for (int j = Close[i]; j = Close[i]; j=j-10) {
      pwm.writeMicroseconds(i, j);
      }
      }
      PreviousStatus[i]=Status[i];
      }
      }
      }

    • @stephengibson1106
      @stephengibson1106 3 ปีที่แล้ว +1

      @@LittleWicketRailway Thank you for this. I will give it ago later.
      Waiting for my sensor shield and merg block detectors to arrive and probably have loads of questions to ask lol.

    • @drnutsert
      @drnutsert 3 ปีที่แล้ว

      Hi Rob still trying! If I set it up with the code below using my nano and a test program in CMRI I can get it to work and it’s great but I’m trying to add the code to the CMRI combined sensors and servos code form your video it’s not working I know I’m doing something wrong I just don’t know what!

    • @tomhsclass2674
      @tomhsclass2674 3 ปีที่แล้ว

      @@drnutsert have you changed the baud rate to 19200?

  • @tonyrogerson3729
    @tonyrogerson3729 2 ปีที่แล้ว +2

    When I add the speed option to my servo control they stop working. This only affects the boards to which I add the extra code, the rest work fine. Anybody any ideas please?

    • @LittleWicketRailway
      @LittleWicketRailway  2 ปีที่แล้ว

      Hi Tony, maybe drop your code into a comment so we can take a look or drop me an email via the contract page on TH-cam 👍

    • @tonyrogerson3729
      @tonyrogerson3729 2 ปีที่แล้ว

      @@LittleWicketRailway
      Hi Rob. Thanks for getting back to me and offering to help.
      Firstly, I must tell you that I am a complete beginner with Arduino and sketches. I have dabbled in the past with BASIC, Pascal and COBOL, so know the general format I do not know the specifics of sketch code and have only got this far by watching your excellent tutorials.
      This the the code I am using to control the servos:
      void loop(){
      cmri.process();
      // PROCESS SERVOS
      // Assume servos start on bit 0 which corresponds to output address 1001
      for (int i = 0; i < 16; i++) {

      //BOARD 1
      Status[i] = (cmri.get_bit(i));
      if (Status[i] != PreviousStatus[i]){
      if (Status[i] == 1){
      for(int j = Close[i]; j= Close[i]; j=j-16){
      Board_1.writeMicroseconds(i,j);
      }
      }
      PreviousStatus[i] = Status[i];
      }

      //BOARD 2
      Status[i+16] = (cmri.get_bit(i+16));
      if (Status[i+16] != PreviousStatus[i+16]){
      if (Status[i+16] == 1){
      for(int j = Close[i+16]; j= Close[i+16]; j=j-16){
      Board_2.writeMicroseconds(i,j);
      }
      }
      PreviousStatus[i+16] = Status[i+16];
      }
      //BOARD 3
      Status[i+32] = (cmri.get_bit(i+32));
      if (Status[i+32] == 1){
      Board_3.writeMicroseconds(i, Throw[i+32]);
      }
      else {
      Board_3.writeMicroseconds(i, Close[i+32]);
      }


      //BOARD 4
      Status[i+48] = (cmri.get_bit(i+48));
      if (Status[i+48] == 1){
      Board_4.writeMicroseconds(i, Throw[i+48]);
      }
      else {
      Board_4.writeMicroseconds(i, Close[i+48]);
      }
      }
      Thanks again for offering to help.

  • @peterbudd1803
    @peterbudd1803 3 ปีที่แล้ว +1

    Hi Any reaon you can't use a Arduino Nano ?

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      No reason that I know of. Just to give you a heads up, I think there's better ways of doing coloured light signals. Someone specifically asked if the servo driver could also do LEDs which is why I made this video, but I'm looking into using an ESP32 instead. They have WiFi and rather than standard 3mm LEDs I'm looking at using addressable LEDs on a strip.

    • @peterbudd1803
      @peterbudd1803 3 ปีที่แล้ว

      @@LittleWicketRailway.Cool - I have a couple of ESP32's but not had a chance to do anything with them as yet. The Problem with train signals is the expense of commercial ones. There is a range by Berko which are more affordable but they work of 12DC.
      onlinemodelsltd.co.uk/product/3-aspect-ryg-standard-round-head/

  • @IoTT
    @IoTT 3 ปีที่แล้ว +1

    The same goes with much less effort on when using Neopixels instead as shown here: th-cam.com/video/9bk1LL12MSk/w-d-xo.html

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Wow! These are incredible. I made the video specifically because someone asked if you could drive LEDs from the PCA9685 alongside servos, but as you've said, this seems like a lot less effort for coloured light signals. Looks like I've got a weekend project coming up, thanks for the tip! 👍

  • @scalesmodellingmagic5883
    @scalesmodellingmagic5883 3 ปีที่แล้ว +1

    To complex for my skills

    • @LittleWicketRailway
      @LittleWicketRailway  3 ปีที่แล้ว

      Nooooo, If I can do it then I bet you can! It sounds complex, but plug a few wires in and copy the code, you'll be shining tiny lights at your trains in no time 😃

    • @scalesmodellingmagic5883
      @scalesmodellingmagic5883 3 ปีที่แล้ว

      @@LittleWicketRailway nah I don’t have that much experience with coding lol

    • @alexs5700
      @alexs5700 3 ปีที่แล้ว

      @@scalesmodellingmagic5883 it looks like the code has been written by Rob can be downloaded from his GitHub page and other info are shown in video, dont knock yourself give it a go